3D Modeling Transformations Introduction to Computer Graphics Arizona State University

Dianne Hansford

February 8, 2005

1 Introduction

In our last course notes, we stepped-through 2D transformations. Now, 3D transformations should be easy! The 3D transformation matrix A is a 3 × 3 matrix:

A = [a_{1} a_{2} a_{3}] = [\begin{matrix}a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{matrix}] .

The linear map, which takes a vector v in the [e_{1}, e_{2}, e_{3}] system to a vector v̂ in the [a_{1}, a_{2}, a_{3}] system, has the form v̂ = Av. Therefore,

e_{1} → a_{1}  e_{2} → a_{2}  e_{3} → a_{3}.

One measure of the behavior of a linear map is the determinant of the matrix A, or |A|. In 3D the determinant measures the volume of the parallelepiped formed by the a_{i} vectors (positioned at the origin). Recall that you use co-factor expansion to compute the determinant of a 3 × 3 matrix.

One other notable difference between 2D and 3D transformations: rotations are not commutative in 3D. More on rotations below.

2 3D Linear Maps

2.1 Scaling

A = [\begin{matrix}s_{11} & 0 & 0 \\ 0 & s_{22} & 0 \\ 0 & 0 & s_{33} \end{matrix}] |A| = s_{11}s_{22}s_{33}

2.2 Reflection

A = [\begin{matrix}±1 & 0 & 0 \\ 0 & ±1 & 0 \\ 0 & 0 & ±1 \end{matrix}] such that |A| = −1

2.3 Shear

We can shear in one or more coordinate-axes. Let’s look at some examples. Shear parallel to the e_{1}, e_{2}-axes:

e_{1} → e_{1} e_{2} → e_{2} e_{3} → [\begin{matrix}a \\ b \\ 1 \end{matrix}] .

Therefore,

A = [\begin{matrix}1 & 0 & a \\ 0 & 1 & b \\ 0 & 0 & 1 \end{matrix}] .

An arbitrary vector v → [\begin{matrix}v_{1} + av_{3} \\ v_{2} + bv_{3} \\ v_{3} \end{matrix}].

Shear parallel to the e_{2}, e_{3}-axes:

A = [\begin{matrix}1 & 0 & 0 \\ ⋆ & 1 & 0 \\ ⋆ & 0 & 1 \end{matrix}] .

Shear parallel to the e_{1}, e_{3}-axes:

A = [\begin{matrix}1 & ⋆ & 0 \\ 0 & 1 & 0 \\ 0 & ⋆ & 1 \end{matrix}] .

The determinant of a shear: |A| = 1, thus the volume of a sheared object does not change.

Here is a special shear that you have encountered before, most likely unknowingly:

e_{1} → [\begin{matrix}1 \\ −b/a \\ −c/a \end{matrix}]  e_{2} → e_{2}  e_{3} → e_{3},

resulting in the following mapping

[\begin{matrix}1 & 0 & 0 \\ −b/a & 1 & 0 \\ −c/a & 0 & 1 \end{matrix}] [\begin{matrix}a \\ b \\ c \end{matrix}] = [\begin{matrix}a \\ 0 \\ 0 \end{matrix}] .

This is a Gauss Elimination step!

2.4 Projection

Projections “flatten” our geometry. In computer graphics, we are interested in parallel projections, which are either orthographic or oblique. The most common (linear map) projection is the following orthographic projection:

A = [\begin{matrix}1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 0 \end{matrix}] ,

which projects all vectors in to the e_{1}, e_{2}-plane.

We will discuss projections in more detail when we get to Viewing. Then we will introduce the perspective projection, which isn’t a linear map. (The foreshortening process doesn’t preserve linear combinations of vectors.)

2.5 Rotation

The rotation matrices will be set up so that the right-hand rule is preserved: Align your right thumb with the positive axis about which you will rotate. Your fingers will curl from one axis to another: A positive angle of rotation will rotate in this direction. Rotation about e_{3}:

A = [\begin{matrix}cos(α) & − sin(α) & 0 \\ sin(α) & cos(α) & 0 \\ 0 & 0 & 1 \end{matrix}] ,

rotates “from e_{1} to e_{2}”. (Recall this is our 2D transformation.)

Rotation about e_{2}:

A = [\begin{matrix}cos(α) & 0 & sin(α) \\ 0 & 1 & 0 \\ − sin(α) & 0 & cos(α) \end{matrix}] ,

rotates from e_{2} to e_{1}.

Rotation about e_{1}:

A = [\begin{matrix}1 & 0 & 0 \\ 0 & cos(α) & − sin(α) \\ 0 & sin(α) & cos(α) \end{matrix}] ,

rotates from e_{2} to e_{3}.

The column vectors of a rotation matrix are orthogonal and unit length, and thus orthonormal. A matrix with orthonormal column vectors is called orthogonal. These matrices have special a property that is quite handy for computer graphics:

R^{−1}(α) = R(−α) = R^{T} (α),

so to reverse a rotation is as simple as applying the transpose of the rotation!

In 3D, matrix products do not commute, and this includes rotations. (Recall that rotations commute in 2D.) Sketch the following example. Let

• R_{e3} be a 90^{∘} rotation about e_{3}, and

• R_{e1} be a 90^{∘} rotation about e_{1}.

Try applying these rotations to the vector e_{1}. You’ll see that

e_{2} = R_{e3}R_{e1}e_{1}  and  e_{3} = R_{e1}R_{e3}e_{1}.

This simple example illustrates the non-commutivity of matrix multiplication.

2.6 Properties

A linear map, v̂ = Av,

• Maps vectors → vectors

• Preserves linear combinations of vectors. Suppose we have

w = αu + βv

Apply the linear map:

v̂ = Av  û = Au  ŵ = Aw

And the relationship still holds:

ŵ = αû + βv̂

3 3D Affine Maps

An affine map in 3D takes the form

x̂ = A(x − o) + p = Ax + p.

As before, for a point x in the coordinate system defined by o, [e_{1}, e_{2}, e_{3}], an affine map gives the coordinates for the corresponding point x̂ in the coordinate system defined by p, [a_{1}, a_{2}, a_{3}].

Affine maps have the following nice properties.

• The ratio of three collinear points is invariant.

• Barycentric combinations are invariant.

• Parallel planes are mapped to parallel planes.

4 Homogeneous Coordinates

The homogeneous form of a 3D point x = [\begin{matrix}x_{1} \\ x_{2} \\ x_{3} \end{matrix}] is x̄ = [\begin{matrix}x_{1}x_{4} \\ x_{2}x_{4} \\ x_{3}x_{4} \\ x_{4} \end{matrix}]. Most of the

time, when you have a 3D point that you want to represent in homogeneous

coordinates, you will write it as x̄ = [\begin{matrix}x_{1} \\ x_{2} \\ x_{3} \\ 1 \end{matrix}], that is, x_{4} = 1.

Homogenous coordinates represent 4D points. The fourth coordinate is called the w-coordinate. When we form a 3D point from a homogeneous point, we divide each coordinate by the w-coordinate,

x ≈ x̄ = [\begin{matrix}x_{1}x_{4}/x_{4} \\ x_{2}x_{4}/x_{4} \\ x_{3}x_{4}/x_{4} \\ x_{4}/x_{4} \end{matrix}] = [\begin{matrix}x_{1} \\ x_{2} \\ x_{3} \\ 1 \end{matrix}] .

We use the ≈ sign and say that “x corresponds to x̄.” Commonly we think of the 3D point corresponding to the 4D point with w = 1. Although, all points on a line through the origin are considered to be equivalent. In other words, there are many homogeneous representations of the same (affine) 3D point. This idea is more easily understood (and sketched) by considering the homogeneous form of a 2D point, which is a 3D point. All points with z = 1 are affine points.

Homogeneous coordinates serve two purposes in computer graphics:

1. A notation that allows an affine map (A and p) to be consolidated into one matrix.

2. A representation for a perspective projection in matrix form.

In OpenGL, matrices are the cornerstone of the mathematics of the pipeline: e.g., the modelview and projection matrices. Both of these matrices are 4×4 in size, and they arranged such that

[\begin{matrix}a_{11} & a_{12} & a_{13} & p_{1} \\ a_{21} & a_{22} & a_{23} & p_{2} \\ a_{31} & a_{32} & a_{33} & p_{3} \\ 0 & 0 & 0 & 1 \end{matrix}]

or in short-hand notation:

[\begin{matrix}A & p \\ 0 0 0 & 1 \end{matrix}] .

Later, the zeros in the bottom row will be replaced with a perspective map definition.

Previously we defined an affine map as

x′ = Ax + p.

To put this transformation in the context of OpenGL’s matrix-oriented pipeline, let’s rewrite the affine map in matrix form with homogeneous coordinates:

x̄′ = [\begin{matrix}I & p \\ 0 0 0 & 1 \end{matrix}] [\begin{matrix}A & 0 \\ 0 0 0 & 1 \end{matrix}] x̄

= T̄Āx̄

= [\begin{matrix}A & p \\ 0 0 0 & 1 \end{matrix}] x̄.