# Palomino - Archaic Documents

©1986,2006 Jim E. Brooks http://www.palomino3d.org http://www.jimbrooks.org/sim

These are my documents that originated in 1986 and were rewritten in 1990.
Their descriptions of 3D computer graphics principles remains useful,
although they contain relic references to an obsolete 8086 implementation.

## Matrix Rotation (1986,1990)

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: Tue Aug 15 22:25:02 EDT 2006