Basic Principles of Three-Dimensional Graphics (Introduction to Computer Graphics Using Java 2D and 3D) Part 4

Projections

So far, transformations were used to position objects in a scene or to move them in animations. For the representation of a three-dimensional scene on a flat computer screen a projection to the two-dimensional plane is required. Such projections can also be described in terms of geometric transformations.

For the representation of a three-dimensional scene, the viewer’s position and the projection plane need to be defined. The viewer looks in the direction of the projection plane, which can be interpreted as a kind of window behind which the virtual world lies. The projection of an object onto this plane is obtained by connecting the points of the object with the centre of projection and computing the intersection points of these lines, called projectors, with the projection plane. This method is illustrated on the left-hand side of Fig. 5.8. It is called perspective projection.

When the centre of projection is moved farther and farther away from the projection plane and finally moved to infinity, the projectors become parallel lines. In this case, it is not necessary to specify a centre of projection, only the direction of the projection is needed. For such a parallel projection, the projectors are all parallel to this direction. Usually it is assumed that the direction of projection is perpendicular to the projection plane. A parallel projection is shown on the right-hand side of Fig. 5.8.


Perspective and parallel projection

Fig. 5.8 Perspective and parallel projection

Mapping an arbitrary plane to a plane parallel to the x/y-plane

Fig. 5.9 Mapping an arbitrary plane to a plane parallel to the x/y-plane

Before considering arbitrary projections, the special case of a parallel projection with a projection plane z = z0, a plane parallel to the x/y-plane, is described by an affine transformation in more detail. This parallel projection maps the point (x,y,z) to the point (x,y,z0). In homogeneous coordinates, this mapping can be written as a matrix multiplication in the form

tmpc009-254_thumb[2][2]_thumb

Based on this representation, now any parallel projection can be described in the form of matrix multiplication in homogeneous coordinates. If the projection plane is not parallel to the x/y-plane, another transformation has to be carried out before the matrix in (5.2) is applied. This transformation maps the projection plane to the x/y-plane. This can always be achieved by a rotation around the y-axis, followed by a rotation around the x-axis as illustrated in Fig. 5.9.

Therefore, it is sufficient for the understanding of parallel projections to examine only parallel projections to the x/y-plane. For other parallel projections, the above-described transformation is applied to the whole scene first and then a parallel projection to a plane parallel to the x/y-plane is carried out. It is even sufficient to consider only parallel projections to the x/y-plane since a suitable translation along the z-axis can map any plane parallel to the x/y-plane itself.

Fig. 5.10 Derivation of the matrix for the perspective projection

Derivation of the matrix for the perspective projection

Perspective projections can also be represented in the form of a matrix multiplication in homogeneous coordinates. As in the case of parallel projections, a specific perspective projection is considered first. It is assumed that the centre of projection lies in the origin of the coordinate system and that the projection plane is a plane parallel to the x/y-plane in the form z = z0. As can be seen from Fig. 5.10, one can apply one of the intercept theorems to derive the equations

tmpc009-256_thumb[2][2]_thumb

and therefore

tmpc009-257_thumb[2][2]_thumb

This means the perspective projection maps the point (x,y,z) to the point

tmpc009-258_thumb[2][2]_thumb

This mapping can be written in homogeneous coordinates in the following way:

tmpc009-259_thumb[2][2]_thumb

When the resulting point (x,y,z, z) is transformed back to Cartesian coordinates by dividing the first three components by the last one, the desired point in (5.3) is obtained.

The matrix for the perspective projection in (5.4) does not have the property of all previous matrices in homogeneous coordinates that the last row is (0,0, 0,1). Therefore, the resulting point is not obtained in normalised homogeneous coordinates with 1 as its fourth component.

In a similar way as for parallel projections, the specific choice of a perspective projection with the origin of the coordinate system as its centre of projection and a projection plane parallel to the x/y-plane is not restrictive at all. Any perspective projection can be reduced to this specific projection when suitable transformations are applied in advance. First the centre of projection of the considered perspective projection is translated into the origin of the coordinate system. Then the same transformations as in the case of the parallel projection as shown in Fig. 5.9 are applied in order to make the projection plane parallel to the x/y-plane.

Another special case of a perspective projection shall be considered here. Instead of having the centre of projection in the origin of the coordinate system, the centre is shifted along the z-axis by the translation (0,0, -z0)T so that the projection plane becomes the x/y-plane. Applying the same considerations based on the intercept theorem as in Fig. 5.10 to compute the perspective projection of the point (x,y,z) to the point (x’,y’, 0), one obtains

tmpc009-260_thumb[2][2]_thumb

This mapping can be written in matrix form in homogeneous coordinates in the following way:

tmpc009-261_thumb[2][2]_thumb

Again, the resulting point (x, y, 0,1 + -^) in homogeneous coordinates corresponds to the projected point in Cartesian coordinates in (5.5).

It was already demonstrated that, with a suitable transformation, any perspective projection can be reduced to a perspective projection with the centre of projection in the origin of the coordinate system and a projection plane parallel to the x/y-plane. This specific perspective projection can be reduced to the perspective projection in (5.6) by a translation by the vector (0, 0, —z0). For the understanding of the properties of perspective projections it is therefore sufficient to examine only the specific projection in (5.6). All other perspective projections can be interpreted as this specific projection together with an affine mapping which is applied to the virtual world before the projection. The matrix in (5.6) can be decomposed into a product of two matrices:

tmpc009-262_thumb[2][2]_thumb

The left matrix on the right-hand side of this equation corresponds exactly to the matrix in (5.2) with z0 = 0, encoding a parallel projection to the x/y-plane. It was shown before that any perspective projection Apersp can be reduced to the perspective projection Aperspz in (5.6) by applying a suitable transformation in advance.

tmpc009-263_thumb[2][2]_thumb

Based on the decomposition of the perspective projection Aperspz in (5.7) one obtains

tmpc009-264_thumb[2][2]_thumb

where

tmpc009-265_thumb[2][2]_thumb

This means that even any perspective projection can be considered as a suitable transformation T followed by a parallel projection to the x/y-plane. As explained before, also all parallel projections can be reduced to this special parallel projection. Therefore, projection can always be viewed as applying some transformation to the virtual world and then applying a parallel projection to the x/y-plane. For this reason it is sufficient to consider only the parallel projection to the x/y-plane whenever projections are mentioned.

The parallel projection to the x/y-plane simply assigns the value zero to the z-coordinate. In order to understand the effects of perspective projections a little better, the right matrix

tmpc009-266_thumb[2][2]_thumb

in the decomposition in (5.7) is examined in more detail. The x/y-plane, i.e., all points with z = 0, remains unchanged, since it is the projection plane. Considering a point of the form (0,0, W) with w e R, w = 0, it can be written in homogeneous coordinates as (0,0, 1,w). The matrix(5.8) maps this point to the point (0, 0,1, ^ + w) in homogeneous coordinates. In Cartesian coordinates this means    0

tmpc009-267_thumb[2][2]_thumb

Fig. 5.11 Vanishing point for perspective projection

Vanishing point for perspective projection

Letting the parameter w go to zero slowly, the point (0, 0, W) slides along the z-axis to infinity whereas its image (0, 0, w ) converges to the finite point (0,0,z0). This means that the hypothetical point at infinity on the z-axis is mapped to a concrete noninfinite point. Considering all lines through the point (0, 0, W), the images of these lines obtained by the matrix (5.8) meet in the point (0, 0,). Letting w go to zero, the lines through the point (0, 0, W) become lines parallel to the z-axis. The matrix maps these parallel lines meeting in the hypothetical point at infinity on the z-axis to lines through the point (0,0,z0). This point is called vanishing point.

These theoretical considerations prove the well-known effect that parallel lines leading away from the viewer do not look parallel any more in a perspective projection. They meet in the vanishing point. Figure 5.11 shows the typical example of a railway that seems to get narrower with increasing distance until it vanishes in a single point.

Horizontal and vertical lines remain parallel when this perspective projection is applied. The vanishing point is only of interest for lines that lead away from the viewer. If another projection plane is chosen for the perspective projection, then there might be two or even three vanishing points. The number of vanishing points is equal to the number of coordinate axes that the projection plane intersects. Figure 5.12 illustrates the effects for the projection of a cube when there are one, two or three vanishing points. The corresponding projections are called one-, two- and three-point perspective projections.

In this section, it has been demonstrated that an arbitrary projection of a scene can be viewed as a suitable geometric transformation of the scene followed by a parallel projection to the x/y-plane. Changing the viewer’s position or his direction of view corresponds to another transformation that is applied to the scene. Instead of transforming the viewer, the reverse transformation is simply applied to the scene. For modelling a moving viewer it is therefore sufficient to include the whole scene in its own transformation group in order to apply the reverse transformations of the viewer within this transformation group. For instance, when the viewer turns to the right, the whole scene is rotated to the left instead.

Fig. 5.12 One-, two- and three-point perspective projections

One-, two- and three-point perspective projections

Projections in Java 3D

By default, perspective projection is applied in Java 3D for showing scenes. If a parallel projection is preferred, this can be achieved by the following method to be called in the constructor of the corresponding Java 3D class:

tmpc009-270_thumb[2][2][2]

The class ViewParallelProjection.java uses parallel instead of perspective projection to show the static scene with the helicopter that was introduced in Sects. 5.3 and 5.2.2.

The method

tmpc009-271_thumb[2][2][2]

within the class SimpleUniverse positions the viewer such that he can see the range from —1 to 1 on the x- and the y-axis in the x/y-plane. One can also define another initial position of the viewer by defining a suitable transformation vt as an instance of the class Transform3D and applying the method

tmpc009-272_thumb[2][2][2]

If the viewer should carry out a fixed movement, this can either be implemented in Java 3D by applying the reverse movement or transformation to the whole scene or directly in the BranchGroup of the ViewPlatform. Interactive movements of the viewer, i.e., interactive navigation through the scene, controlled by the mouse can be realised with the OrbitBehavior that was introduced in Sect. 5.5. As an alternative, the keyboard can also be used to navigate interactively through the scene. This technique will be introduced in Sect. 9.10.

Next post:

Previous post: