O'Reilly logo

Learning Cocoa by Apple Computer Inc

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Transformation Matrices

A transformation matrix maps points from one coordinate space into another coordinate space. Cocoa and Quartz use transformation matrices to perform standard graphical display operations such as scaling, rotation, and translation.

The matrix used to accomplish two-dimensional transformations is described by a 3 × 3 matrix. Figure 1.3 shows a sample 3 × 3 matrix. Note that u and v are always 0.0, and w is always 1.

A point transformed by a 3 × 3 matrix

Figure A-3. A point transformed by a 3 × 3 matrix

The contents of a 3 × 3 matrix transform a pointx,y into a point x’,y’ by means of the following equations:

A point transformed by a 3 × 3 matrix

For example, the matrix shown in Figure 1.4 performs no translation. It is referred to as the identity matrix.

The identity matrix

Figure A-4. The identity matrix

Using the formulas discussed earlier, you can see that this matrix would generate a new point x’,y’ that is the same as the old point x,y:

The identity matrix

To move an image by a specified displacement, you can perform a translation operation. This operation modifies the x and y coordinates of each point by a specified amount. The matrix shown in Figure 1.5 describes a translation ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required