• No results found

Perspective Projection Using 4×4 Matrices

Chapter 9 More on Matrices

9.3 Orthogonal Matrices

9.4.6 Perspective Projection Using 4×4 Matrices

Because the conversion from 4D to 3D space implies a division, we can encode a perspective pro- jection in a 4×4 matrix. The basic idea is to come up with an equation for p' with a common denominator for x, y, and z and then set up a 4×4 matrix which will set w equal to this denominator. We will assume that the original points have w = 1.

First we manipulate the equation for p' to have a common denominator:

To divide by this denominator, we put the denominator into w, so the 4D point will be of the form:

So we need a 4×4 matrix that takes an “ordinary” homogenous vector of the form [x, y, z, 1] and transforms it into the form given above. The matrix that does this is shown below:

Thus, we have derived a 4×4 projection matrix. There are several important points to be made here:

n Multiplication by this matrix doesn’t actually perform the perspective transform; it just com- putes the proper denominator into w. Remember that the perspective division actually occurs when we convert from 4D to 3D by dividing by w.

n There are many variations. For example, we can place the plane of projection at z = 0 and the center of projection at [0, 0, –d]. This results in a slightly different equation.

n This seems overly complicated. It seems like it would be simpler to divide by z, rather than bothering with matrices. So why is homogenous space interesting? First, 4×4 matrices pro- vide a way to express projection as a transformation that can be concatenated with other trans- formations. Second, projection onto non-axially aligned planes is possible. Basically, we

Chapter 9: More on Matrices

145

Equation 9.12: Projecting a point onto the planez = d Equation 9.13: Projecting onto the plane z = d using a 4×4 matrix

don’t need homogenous coordinates to perform any operations, but 4×4 matrices provide a compact way to represent and manipulate projection transformations.

n The projection matrix in a real graphics geometry pipeline is not going to be exactly like the one we derived here. There are many important details that must be considered. For example, our matrix basically discards z, which many graphics systems use for z-buffering. See Chapter 15 for a description of how the graphics geometry pipeline would be implemented.

9.5 Exercises

1. Compute the determinant of the following matrix:

2. Compute the determinant, adjoint, and inverse of the following matrix:

3. Is the following matrix orthogonal?

4. Invert the matrix from the previous exercise. 5. Invert the 4×4 matrix:

6. Construct a 4×4 matrix to translate by [4,2,3].

7. Construct a 4×4 matrix to rotate 20° about the x-axis and then translate by [4,2,3]. 8. Construct a 4×4 matrix to translate by [4,2,3] and then rotate 20° about the x-axis.

9. Construct a 4×4 matrix to perform a perspective projection onto the plane x=5. (Assume the origin is the center of projection.)

10. Use the matrix from the previous exercise to compute the 3D coordinates of the projection of the point (107, –243, 89) onto the plane x=5.

C h a p t e r 1 0

Orientation and Angular

Orientation and Angular

Displacement in 3D

Displacement in 3D

In this chapter, we will tackle the difficult problem of describing the orientation of an object in 3D. We will also discuss the closely related concept of angular displacement. There are several differ- ent ways we can express orientation and angular displacement in 3D. We will discuss the three most important methods — matrices, Euler angles, and quaternions. For each method, we will define precisely how the representation method works and discuss the peculiarities, advantages, and disadvantages of the method.

Different techniques are needed in different circumstances, and each technique has its advan- tages and disadvantages. It is important to know not only how each method works, but also which technique is most appropriate for a particular situation and how to convert between representations.

In this chapter, we will make extensive use of the terms object space and inertial space, which were discussed in Section 3.2.

147

This chapter discusses orientation in 3D. It is divided into six sections.

n Section 10.1 discusses the subtle differences between terms like “orientation,” “direction,” and “angular displacement.”

n Section 10.2 describes how to express orientation using a matrix.

n Section 10.3 describes how to express angular displacement using Euler angles.

n Section 10.4 describes how to express angular displacement using a quaternion.

n Section 10.5 compares and contrasts the three methods.

10.1 What is Orientation?

Before we can begin to discuss how to describe orientation in 3D, let us first define exactly what it is that we are attempting to describe. In this section, we will discuss how orientation is related to other similar terms:

n Direction

n Angular displacement

n Rotation

Intuitively, we know that the “orientation” of an object basically tells us what direction the object is facing. However, “direction” is not exactly the same as orientation. A vector has “direction,” but not “orientation.” The difference is that when a vector points in a certain direction, you can “twist” the vector along its length (see Figure 10.1), and there is no real change to the vector (or its direc- tion) since a vector has no thickness or dimension other than its length.

However, if you have an object facing a certain direction and you twist that object in the same way that we twisted the vector (see Figure 10.2), you will change the orientation of the object.

Technically, this is demonstrated by the fact that we can parameterize a direction in 3D using just two numbers (i.e., polar coordinates), whereas an orientation requires a minimum of three numbers.