The C++ Matrix3x3 Class

Overview

Affine transformations in n-dimensional space

An affine transformation is defined as a mapping of a point in an n-dimensional affine space to another point in the same space. Affine transformations include rotation, scale, mirror, and translation.

If P is an n-dimensional point in an affine space, then we say that X(P) is the affine transformation of the point. Affine transformations can also be applied to vectors. If v is such a vector, then we say that X(v) is the affine transformation of the vector.

An affine transformation can be represented as (M, t) where M is an n x n matrix, and t is an n-dimensional vector in the associated n-dimensional vector space. Assuming this representation, the transformation is applied to points as:

X(P) =MP + t

Similarly, it is applied to vectors as:

X(v) =Mv

By embedding our geometry in an (n+1)-dimensional projective space, we can represent the affine transformation as an (n+1)x(n+1) matrix in which M is the upper left nxn portion, the components of t comprise the first n elements of the last column, and the bottom row is (0, ..., 0, 1).

Affine transformations in 3-dimensional space

We restrict our attention to 3D points and vectors by fixing n=3. In terms of the application of an affine transformation as introduced above (i.e., X(P) =MP + t), instances of class Matrix3x3 are used to represent M, and instances of class AffVector are used to represent t.

As noted above, affine transformations on points in a 3D space can be represented using a 4x4 matrix operating on the projective space equivalents of those points. An instance of class Matrix4x4 can be created for this purpose. The normal mode of operation is to create the 3x3 matrix M first using one of the methods described here, then create the 4x4 matrix using a constructor which takes the 3x3 matrix and one of the following: (i) a fixed point, (ii) a point whose pre- and post-images are known, or (iii) an explicit translation vector, t. Among other things, such a 4x4 matrix may then be passed into a graphics API like OpenGL which assumes all transformations are represented as 4x4 matrices.

The methods and overloaded arithmetic operators specified here define common ways to construct 3x3 matrices encoding affine transformations and to apply them to 3D points and vectors. While nothing would prevent it, this class was not designed to provide facilities for representing 2D transformations on points embedded in a 3D projective space.

Constructors

As reviewed above, a 3x3 matrix by itself only describes the effect of an affine transformation on vectors. (Although the complete affine transformation for points is usually easily constructed from such a matrix. See the references for details.) Therefore the remaining constructors here are described in terms of specific types of transformations on vectors. The references provide pictures and other relevant explanatory material.

C++ Overloaded Operators

In the following, assume that instances of Matrix3x3 called M, N, S1, and S2 have been declared and initialized. Similarly, let us assume that P and Q have been defined as instances of class AffPoint and that u and v have been defined as instances of class AffVector.

Matrix3x3 Instance Methods

In the following, assume that an instance of Matrix3x3 called M has been declared and initialized.

Matrix3x3 Public Constants

The following constants are Matrix3x3 class variables that can be used in your programs.

Matrix3x3 Class Methods

Most of these class methods provide alternative ways to construct 3x3 matrices. If any of these methods cannot create the matrix due to some error in supplied parameters (e.g., a zero-length vector was provided), an identity matrix will be returned. Angles are assumed to be measured in radians.


Jim Miller