5. 2D & 3D Transformations

Brock University
COSC 3P98 Computer Graphics
Instructor: Brian Ross



2d transform composition

 M1

 M2

 translate

translate

scale

scale

rotate

rotate

scale (sx = sy)

rotate


Combined form for 2d Transforms

    |  r11  r12  tx  |
M = |  r21  r22  ty  |
    |   0    0    1  |


Coordinate systems: Local and Global


2d transforms: OpenGL implementation


2d transforms: OpenGL


OpenGL: Order of transformation operations

glScaled(1.0, 1.0, 3.0);
glRotatef(45.0, 0.0, 1.0, 0.0);
glTranslatef(3.0, 2.0, 0.0);
draw_my_triangle();


2D Transformation inversions

T(dx, dy) * T(-dx, -dy) = 1

R( A) * R(- A) = 1

S(sx, sy) * S( 1/sx, 1/sy) = 1

To invert a sequence of transforms P' = M * P = (Tr1 * Tr2 * ... * TrK) * P

M^(-1) * P = (Tr1 * Tr2 * ... * TrK)^(-1) * P = TrK^(-1) * ... * Tr2^(-1) * Tr1^(-1) * P


OpenGL: Saving and restoring contexts


OpenGL Matrix Modes


Properties of affine transformation matrix M


2D transforms: Shear transformations ("shearing")

 

       | 1  a  0 |            | 1  0  0 |
SHx =  | 0  1  0 |     SHy =  | b  1  0 |
       | 0  0  1 |            | 0  0  1 |

x' = x + ay             x' = x
y' = y                  y' = bx + y


3D Transforms


3D transforms

               | 1 0 0 dx |
T(dx,dy,dz) =  | 0 1 0 dy |
               | 0 0 1 dz |
               | 0 0 0 1  |
               | sx  0  0  0 |
S(sx,sy,sz) =  |  0 sy  0  0 |
               |  0  0 sz  0 |
               |  0  0  0  1 |
        | 1      0        0   0 |
Rx(A) = | 0  cos A   -sin A   0 |
        | 0  sin A    cos A   0 |
        | 0      0        0   1 |
 
        | cos A   0   sin A   0 |
Ry(A) = |     0   1       0   0 |
        | -sin A  0   cos A   0 |
        |     0   0       0   1 |

        | cos A  -sin A   0   0 |
Rz(A) = | sin A   cos A   0   0 |
        |     0       0   1   0 |
        |     0       0   0   1 |

3d transforms

z' = z cos A - x sin A

x' = z sin A + x cos A (as before)

--> but when you put these in matrix form, the X and Z are in reversed order, hence the sign change


3D transforms

    | r11  r12  r13  tx |
M = | r21  r22  r23  ty |
    | r31  r32  r33  tz |
    |   0    0    0   1 |
    | r11  r12  r13 |
R = | r21  r22  r23 |
    | r31  r32  r33 |
    
                    |  r11  -r21  r13 |
R^(-1) = (1/Det R)* | -r12  r22  -r32 |
                    |  r31  -r23  r33 |


3D transform properties


Non-affine transform: Fish-eye (angle halver)


Non-affine transforms: inversion in a unit circle


References



Back to COSC 3P98 index

COSC 3P98 Computer Graphics
Brock University
Dept of Computer Science
Copyright © 2001 Brian J. Ross (Except noted figures).
http://www.cosc.brocku.ca/Offerings/3P98/course/lectures/2d_3d_xforms/
Last updated: October 16, 2001