©1986,2007 Jim E. Brooks http://www.palomino3d.org
This document was originally written in 1986, then rewritten in 1990. These descriptions of remain useful, despite that they contain relic references to an obsolete 8086 assembly implementation.
Originally written in 1986, rewritten in 1990. Describes rotating a matrix around one of its axises.
[see "local matrix rotation"]
counter-clockwise
+------------+
Basis for this is: | COS | SIN |
| -SIN | COS |
+------------+
Note that COS is placed so that if you were calculate new X,
X would be multiplied by COS, same for Y.
If you were to switch COS and SIN, calculations would be _wrong_.
For ex: if rotating by angle 0 (actually no rotation), matrix would be:
+-------------------------+ +-------+
| COS(0) = 1 SIN(0) = 0 | | 1 | 0 |
| -SIN(0) = 0 COS(0) = 1 | = | 0 | 1 |
+-------------------------+ +-------+
WRONG!
+-------------+
This is also _wrong_: | +COS | +SIN |
| +SIN | +COS |
+-------------+
+-------------+
Clockwise, correct: | COS | -SIN |
| SIN | COS |
+-------------+
+-----------------------------------------------------------+
| C-Clk (counter-clockwise) Matrix Rotation (July 27, 1990) |
+-----------------------------------------------------------+
[ Notes: ]
[ For understandability, the transcription was rewritten in a psuedo C notation ]
[ which differs from the original. Eg, the original was written with 0,2,4,.. ]
[ to denotice indexes into a 3x3 matrix of 16-bit values. ]
[ 'C' and 'S' mean cos(angle) and sin(angle). ]
[ 'M[]' means the 3x3 matrix. ]
+-----------+
X | 0 | 1 | 2 |
M[] = Y | 3 | 4 | 5 |
Z | 6 | 7 | 8 |
+-----------+
X Pitch
---------
M[3] = M[3]*C - M[6]*S // Y = Ycos - Zsin
M[4] = M[4]*C - M[7]*S
M[5] = M[5]*C - M[8]*S
M[6] = M[3]*S + M[6]*C // Z = Ysin + Zcos
M[7] = M[4]*S + M[7]*C
M[8] = M[5]*S + M[8]*C
Z Roll
---------
M[0] = M[0]*C - M[3]*S // X = Xcos - Ysin
M[1] = M[1]*C - M[4]*S
M[2] = M[2]*C - M[5]*S
M[3] = M[0]*S + M[3]*C // Y = Xsin + Ycos
M[4] = M[1]*S + M[4]*C
M[5] = M[2]*S + M[5]*C
Y Yaw
---------
M[0] = M[0]*C - M[6]*S // X = Xcos - Zsin
M[1] = M[1]*C - M[7]*S
M[2] = M[2]*C - M[8]*S
M[6] = M[0]*S + M[6]*C // Z = Xsin + Zcos
M[7] = M[1]*S + M[7]*C
M[8] = M[2]*S + M[8]*C
Clockwise is done by reversing S's sign C + S : -S + C
Last modified: Wed May 9 17:40:54 EDT 2007