Notes on homogeneous coordinates and matrix transformations

Homogeneous coordinates

We can deal with both points in a scene and directions (which are essentially points at infinity) by adding an extra coordinate, which we call the homogeneous coordinate.

For example, in two dimensions, we would write [x,y,w] to represent (x/w, y/w).

In the example to the right, we have both points and directions. The point at (1,0) is represented by [1,0,1], whereas the direction vector (1,0) (shown in red) is represented by [1,0,0].

By convention we place all points on the w=1 plane (shown in gray), although scaling arbitrarily to [cx,cy,cw] still describes the same point (x/w, y/w), as shown by the upward slanting arrows in the figure.

The same principle applies when we move to three dimensions: We use the homogeneous vector [x,y,z,w] to describe (x/w, y/w, z/w).

• A point at location (x,y,z) is described as [x,y,z,1]

• A vector in direction (x,y,z) is described as [x,y,z,0]

 

 


 

Coordinate transformations

The default coordinate system in three dimensions has coordinate axes [1,0,0,0], [0,1,0,0] and [0,0,1,0], respectively (the x, y and z global direction vectors).

Its origin is [0,0,0,1] (the point (0,0,0)), as shown in the figure to the right in black.

We can describe a transformed coordinate system by redefining each of the x, y and z axes, and by translating the origin to point t, as shown in the figure to the right in blue.

Note that this is a very general representation. For example, the new x, y and z directions do not need to be perpendicular to each other. Nor do they need to be unit length. For

 

 


 

Transformation matrices

All of the information of a coordinate transformation can be placed in a 4×4 matrix, as shown in the figure to the right.

The x, y and z axes form the first three respective columns of the matrix.

The origin t forms the right-most column of the matrix.

In this class we will follow the convention of storing the 16 matrix values in column-major order:

     [ x0, x1, x2, x3,   y0, y1, y2, y3,   z0, z1, z2, z3,   t0, t1, t2, t3 ]

 

 


 

Transforming a point

We can use a 4×4 matrix to transform a vector.

By convention, we represent the input as a column vector, and place it to the right of the matrix.

Also, by convention, if we omit the fourth (homogeneous) coordinate of the input, as in the example to the right, we assume a value of 1.0 for its homogeneous coordinate, unless otherwise specified.

The result of the transformation is another column vector, which we obtain by taking the inner product of each successive row of the matrix with the input vector.

In this case, the matrix is rotating the point (1,0,0) about the z axis.

 

 


 

The identity transformation

The identity matrix is the "do nothing" transformation. It will transform any point or direction to itself. You generally want to call the identity() method on a matrix object to initialize that matrix.
 

 


 

The translate transformation

To translate a point, we use only the right-most column of the matrix. The rest of the matrix is the same as the identity matrix.

1 0 0 Tx
0 1 0 Ty
0 0 1 Tz
0 0 0 1

Note that translation affects only points, not directions. Because the homogeneous coordinate of a direction is zero, its value cannot be affected by the right-most column of the matrix.

 

 


 

Rotate about the x axis

Rotation about the x axis only affects the y and z axes.

1 0 0 0
0 cosθ -sinθ 0
0 sinθ cosθ 0
0 0 0 1

"Positive" rotation is counterclockwise when looking from the positive x direction.

 

 


 

Rotate about the y axis

Rotation about the y axis only affects the z and x axes.

cosθ 0 sinθ 0
0 1 0 0
-sinθ 0 cosθ 0
0 0 0 1

"Positive" rotation is counterclockwise when looking from the positive y direction.

 

 


 

Rotate about the z axis

Rotation about the z axis only affects the x and y axes.

cosθ -sinθ 0 0
sinθ cosθ 0 0
0 0 1 0
0 0 0 1

"Positive" rotation is counterclockwise when looking from the positive z direction.

 

 


 

The scale transformation

Like rotation, a scale transformation (which makes shapes bigger or smaller) uses only the top-left 3×3 portion of the 4#215;4 matrix.

Sx 0 0 0
0 Sy 0 0
0 0 Sz 0
0 0 0 1

In the case illustrated on the right, we are performing a uniform scale, by using the same values for the three locations along the diagonal of the matrix.

If we were to use differing values at these three locations, then we would perform a non-uniform scale, which would result in the shape becoming squashed or stretched.

 

 


 

The perspective transformation

For completeness, we include the perspective transformation, although this is rarely used, except for setting up camera views. Note that the perspective transformation uses only the bottom row of the matrix.

1 0 0 0
0 1 0 0
0 0 1 0
Px Py Pz 1

Because perspective can change the homogeneous coordinate of an [x,y,z,w] vector, it is able to throw points out to infinity (that is, transform a point into a direction vector), as well as bring points at infinity into the scene (that is, transform a direction vector into a point).

   

 


 

Homework

For now, just study the structure of these matrices, and make sure you understand them.

I am going to give homework on Thursday that will be due after the Spring break.