# GAMBAS BOOK 3.19.1

### Site Tools

k23:k23.4:k23.4.2:k23.4.2.10.1:start

## 23.2.4.10.1 Perspective display of images

This chapter is based on proposals and projects by Tobias Boege and Ingo Beckert for the perspective display of images with depth effect. In both projects, the image matrices are changed depending on a rotation angle φ so that a perspective display is achieved.

Figure 23.2.4.10.1.1: Horizontal compression (φ=60°)

If you want to distort an image, or compress or stretch parts of the image to varying degrees - depending on whether they are further to the left or right or at the top or bottom of the image - this is no easy task. It is easier if we assume that a plane E exists in the space R3 and that E is to be mapped onto another plane E'. The space R3 is the Cartesian coordinate system and the plane E, in which the image lies, is the plane spanned by the y and z axes. The plane E is to be rotated in a circle along a straight line, similar to a door around a hinge. It is also assumed that the lower left corner of the image lies in the coordinate origin O(0,0,0) and that the image expands in the positive z and y directions.

The following mapping equation E' applies: [ x → x + cos(φ), y → y-sin(φ), z → z ]. The plane E is the y,z plane and therefore x = 0. We obtain a plane rotated by the angle φ with arc(φ)∈R and 0⇐arc(φ)⇐ Pi/2. The restriction for φ is understandable because the image has no back side that could be viewed. Now the image is lying transversely in space and you have to translate the coordinates of the new plane E' into an image object as if you were looking at it from the viewpoint of the original plane E.

To do this, you leave the space R3, which was only viewed at the beginning for the sake of clarity. You can see immediately that the z-coordinate can be neglected and we return to R2. The image is therefore available in x,y coordinates.

For the mapping equation of a compression only in the x-direction (horizontal), E' now applies: [ x → x-cos(φ), y → y ].

Figure 23.2.4.10.1.2: Horizontal compression (φ=60°)

So far, the image with the angle φ has only been compressed horizontally. The vertical compression, which contributes significantly to the illusion of perspective, is still missing. The perspective causes the right-hand parts of the image to be sent further 'spacewards' and must appear smaller in order to achieve an effect of depth.

It is now necessary to determine from where the viewer is looking at the image, i.e. how much the image should be compressed vertically from above and below. The centre of the image is selected and the image is compressed to the same extent from above and below for “perspective compression”.

For vertical compression, you can define a factor ψ that specifies how much the image should be compressed in the y-direction across the entire width of the image. With the factor ψ = 2-arc(φ)/Pi and ψ in [0,1], an image height H' = (1-ψ)-H remains after the rotation by φ.

Figure 23.2.4.10.1.3: Horizontal and vertical compression with ψ=1 and φ=60°

Figure 23.2.4.10.1.4: Horizontal and vertical compression with ψ=0.666 and φ=60°

Projects

The Gambas book authors Tobias Boege and Ingo Beckert have implemented their theoretical approaches in two projects, whose source code archives can be found in the download area for your own explorations.

The first project by Tobias Boege directly follows the explanations in the paragraph above, while the second project by Ingo Beckert works with an adjustable depth effect:

Figure 23.2.4.10.1.5: Perspective animation (Ingo Beckert)