Spatial Transformation

After a model is created, it exists in its original reference frame until it is somehow spatially transformed. Indeed, there isn't much point to go to all the trouble of geometric modeling unless the model can be moved or rotated. This is the domain of spatial transformation.

The definition of a transformation is a function that maps points from one space to another. There are two basic uses of transformation in 3D graphics.

The first use is to move, rotate, scale, and shear objects in three dimensions. The applications programmer will use transformations in this way time and time again.

The second use of transformation is less frequently encountered by the applications programmer but is present in every application. This is the use of transformation to project the 3D world onto a 2D screen or other output device. Much more detail about view projection will be given in Chapters 11 and 13.

We now introduce some of the basic mathematical background necessary for understanding transformations.

Model Transformations

Model Transformations are simply those spatial transformations that apply to the geometric model independently of the view of that model. Two general classes of model transformation are as follows:

  • Rigid body transformations

  • Deformation transformations

Rigid Body Transformations

A rigid body transformation is one in which the points are moved or rotated without changing the distances between them. Vectors, points, and scalars can undergo rigid body transformation. In three-dimensional space, there are six possible values that we can play with—three for translation (x, y, z) and three more for rotation (pitch, roll, and yaw). The six transformations are often referred to as having six degrees of freedom. Note that in the case of a Cartesian coordinate, we have three degrees of freedom (x, y, and rotation).

Sticking with the Cartesian coordinate system for a moment, we can see any point P(x, y) specified in two dimensions can be moved to a new location in the same coordinate system P(x+dx, y+dy) by simply adding dx units to x and dy units to y. This operation defines a translation in two dimensions and can be expressed in column vector form as

As a further example, we consider scaling in 2D. Just as we added dx and dy to x and y, we can multiply x and y by scaling factors, sx and sy. Alternatively in matrix form, this is shown as

Finally, it is possible to rotate points about the origin. In this case, we have

You will notice that two of the three operations described previously are multiplications and that translation is the odd ball because it requires addition. It would be better if all three of these operations could be expressed in terms of multiplication and hence use a common set of methods for performing them. This is achieved through the use of a homogenous coordinate system.

Homogeneous coordinates are essential elements of projective geometry and permit the translation of points using matrix multiplication. By adding a non-zero third coordinate (the so-called W coordinate) to each of our 2D points, we can express each point in two dimensions as a line in three dimensions. Therefore, our point P=(x, y) is now represented by P = (x, y, W). Further, if we divide by W (often referred to as homogenizing the point), we get a point on a plane equal to (x/W, y/W, 1). The addition of the W coordinate now mandates that a 3x3 matrix be used when translating our homogenous point a distance dx and dy. So, our translation operation, , in homogeneous coordinates is expressed as

So far, however, we have described no advantage to the use of homogeneous coordinates. The advantage comes from something that was alluded to previously. Homogeneous coordinates allow for the composition (also known as concatenation or compounding) of matrices. The advantage of composition is that a single transform can be used to make a series of spatial transformations, thereby often gaining a substantial improvement in efficiency.

The idea can be expanded to coordinate systems of any dimension. In our case, we are most interested in applying homogeneous coordinates in three dimensions. This time we will add W as the fourth coordinate of a point in 3D space, thereby representing a point as (x, y, z, W). Again, remember that W cannot equal 0 and is typically equal to 1 for convenience.

In short, by working with homogeneous coordinates, we can make efficient computations for any number of rotational, scaling, and translation operations through multiplication. The result of these operations will always be a matrix of the form:

The preceding form is omnipresent in 3D graphs. Note that there are various submatrices that can be extracted. One of these is the upper-left 3x3 matrix denoted as R. R provides information on the aggregate scaling and translation. Likewise, the 1x3 column vector of ts provides the aggregate translation.

So far, we have only dealt with points in 3D, however, because lines and polygons are defined by their endpoints and vertices respectively, it is trivial to apply the transformations to these points as well.

Note

In Java 3D, it isn't really necessary to work directly with the 4x4 matrix because there are a number of methods for rotation, scaling, and translation. Nevertheless, the 4x4 matrix is such a staple of 3D graphics in general that you are encouraged to become familiar with the form. Java 3D's utility package includes a large number of methods for accessing matrices and performing mathematical operations on them (see Chapter 11) .


Deformation Transformations

The two primary forms of structure deformations are scaling and shearing. Scaling refers to proportionally reducing or increasing the distances between points. This can be thought of as contracting or expanding the space linearly.

The second deforming transformation is shearing. With a shearing transformation, the points are displaced on some axis by an amount proportional to that point's distance from the origin along another direction. For example, a shear in the Y direction will transform the values of X and Z according to the point's position in Y. Those with a larger Y projection will move the most in the X and Z directions.

Transforming in Local Coordinates

Another approach to the problem of transformation was also illustrated in Chapter 2 where we considered transformation in terms of a change in coordinate systems. This is often the approach used in practice and as you will see, a frequently used approach in Java 3D.

The basic idea is to think in terms of local coordinate systems within the global coordinate system. A good example of local coordinate systems is our solar system. One coordinate system can be defined for the Sun and yet another can be defined for each planet that orbits the Sun. The Earth is rotating in its coordinate system and is rotating around the Sun in the Sun's coordinate system. Of course, calculating the Earth's rotation about its axis within the Sun's coordinate system would be possible and far more challenging than computing the Earth's rotation about its own axis in its coordinate system and moving the entire coordinate system around the sun. More examples of the use of local coordinate systems are given in the next chapter.

Quarternions

There has been a lot of interest recently in using quarternions for computing rotations in space. Quarternions are a mathematical construct involving fourth dimensional vectors, complex numbers, and a special algebra. There is really nothing new about quarternions because they were discovered in the mid-1800s. The desirability of using Euler angles versus quarternions has been debated ever since.

The advantage of quarternions stems from the fact that for some rotations, executing the Euler angles in series can lead to the loss of one degree of freedom. The occurrence of this is termed gimbal lock and happens when two of the angles begin to describe the same rotation. Quarternions allow for rotations about an arbitrary axis and therefore aren't susceptible to the order of rotations problem encountered with some Euler angle sequences. Quarternions can be used to advantage in these cases. It should be noted that gimbal lock rarely poses any real problem for most applications but it does occasionally, and the developer should be aware of the opportunity to use quarternions.

A second reason why a programmer would want to specify rotation in quarternions is that the interpolation between two points on a curve can be smoother. This is where the real argument for using quarternions can be made. Rotational animations can be considerable smoother when quarternions are used to compute the transformations.

In practice, however, we haven't found the use of quarternions to yield a significant improvement in our visualizations. Our recommendation is for developers to attempt their visualizations first with the more traditional Euler rotations to see if the Euler angles are sufficient to the task before considering the more challenging quarternion approach. Of course, modelers with a solid understanding of quarternions should use whichever approach they feel the problem calls for. Java 3D's vecmath package fully supports quarternions.

Projection Transformations

As we have stated frequently in this chapter, the great irony of 3D modeling is that after we go to all the trouble to specify an object in terms of a 3D coordinate system, we are forced to render it to a 2D screen. This unfortunate fact of life adds another level of complexity to the transformations that we must use in order to render a 3D scene. The name for this process is view projection.

Two fundamental forms of projection exist: perspective and parallel. These are described next. Refer to Chapter 13 and Listing 13.1 for a detailed examination of these and other viewing concepts. We give a brief description here.

Perspective Projection

A perspective projection is the type that is most common in drawing and that matches how we view the environment in real life. The technique makes objects that are farther away smaller and makes lines that go into the distance converge (that is, a road running into the horizon). Perspective is the default for realism and is the choice to make in the vast majority of applications.

Perspective projections are created by placing the user's eye at the point of convergence of rays reflected from the objects in the virtual world. As each ray travels to the eye, it passes through the view plane. The set of these points are stored for later rendering.

The distance from the eye to the projection plane can be varied to produce different focal distances.

Parallel Projection

The idea behind parallel projection is that the depth dimension of the 3D space is collapsed such that all lines that are parallel in the 3D space map onto a single point on the projection plane. Parallel projection is often used when the visualization requires that the objects maintain their size dimensions on the output rendering; for example, when an architect draws construction plans. Another commonly used term for parallel projection is orthographic projection; however, this term refers only to projections at right angles (90 degree) to the projection plane. A parallel projection taken at any other angle is termed oblique.

See Figure 13.2 and 13.3 for examples of perspective and parallel projections.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset