# 2D TRANSFORMATIONS AND MATRICES

• Note: these notes are going to follow the notation in Foley and Van Dam. If you look at other sources, you will probably find the transposes of the matrices described in these notes.
• Representation of Points:
•
2 x 1 matrix: |x|
|y|
• General Problem: |B| = |T| |A|
• |T| represents a generic operator to be applied to the points in A
• T is the geometric transformation matrix.
• A & T are know, want to find B, the transformed points.
• General Transformation of 2D points:
•         | a c | |x|    |x'|
| b d | |y| =  |y'|

x' = ax + cy
y' = bx +dy
• Special cases of 2D Transformations:
•
1) T= identity matrix, a=d=1, b=c=0

x'=x, y'=y
so far, what we would expect!
2) Scaling & Reflections: b=0, c=0
x' = ax, y' = dy
• scaling by a in x, d in y
• Scale matrix: let Sx =a, Sy=d
•         | Sx 0 |
| 0  Sy|
• What if sx and/ or sy < 0 ?
• get reflections through an axis or plane
• Only diagonal terms involved in scaling and reflections
• Scaling Example
3) Off diagonal terms: Shearing
• a=d=1
• let b ­ 0, c=0 (example: b =2)
• x' = x
y' = bx + y
y' depends linearly on x
• Similarly for b=0, c­0
Example of Shearing & Reflections:

4) ROTATION

• x= rcos(f)

• x' = rcos(f +q)
• y = rsin(f)

• y' = rsin (f +q)
• Remember,
• cos(f +q) = cos(f)cos(q) - sin(f)sin(q)
sin(f +q) = cos(f)sin(q) + sin(f)cos(q)
x'=r(cos(f)cos(q)-sin(f)sin(q))
y'=r(cos(f)sin(q)+sin(f)cos(q))
• x' = xcos(q) - ysin(q)
• y' = xsin(q) + ycos(q)
• In matrix form, this is :
•         | cos(q)  -sin(q)|
| sin(q)  cos(q) |
• Positive Rotations: counter clockwise about the origin
• For rotations, det|T| = 1 and |T|T = |T|-1
• Example:

5) Translations
• B = A + Tr, where Tr = |tx ty|T
• Note: we can not directly represent translations as matrix multiplication, as we can rotations and scalings.
•

• Where else are translations introduced?
• 1) Rotations - when object not centered at the origin.
2) Scaling - when objects / lines not centered at the origin.
- line from (2,1) to (4,1) scaled by 2 in x & y.
- If line intersects the origin, no translation.
- Scaling is about the origin.

• Can we represent translations in our general transformation matrix?

• Yes, by using homogeneous coordinates

# HOMOGENEOUS COORDINATES

• We have x' = ax + cy + tx
• y' = bx + cy + ty
• Use a 3 x 3 matrix:
•                 |x'|    | a c tx| |x|
|y'| =  | b d ty|*|y|
|z'|    | 0 0 1 | |1|
• Each point is now represented by a triple: (x, y, W)
• x/W, y/W are called the Cartesian coordinates of the homogeneous points.
• Two hom. coord. (x, y, w1) & (x,y, w2) represent the same point IFF they are multiples of one another: (1,2,3) & (3,6,9).
• There is no unique homogeneous representation of a point.
• All triples of the form (tx, ty, tW) form a line in x,y,W space.
• Cartesian coordinates are just the plane w=1 in this space.
• W=0, are the points at infinity.

# COMPOSITION OF TRANSFORMATIONS

• If we want to apply a series of transformations T1, T2, T3 to a set of points, We can do it 2 ways:

•
1) We can calculate p'=T1*p, p'' = T2*p', p'''=T3*p''

2) Calculate T= T1*T2*T3, then p'''= T*p.

• Lets say we have 1800 points (the number in the torso I use),
•

Remember, T1*T2 takes 27 multiplies, 18 adds
T1*p takes 9 multiplies, 6 adds

For method 1, we need :
1800 * (3 * ( 9 multiplies, 6 adds))=

For method 2, we need:
1800*(9 multiplies, 6 adds) + 2* (27 multiplies, 18

• Method 2, saves large number of adds and multiplies.
• Approximately 1/3 as many operations.
• Therefore, we concatenate or compose the matrices into one final transformation matrix that we apply to the points.
• Translations:
•  Translate the points by tx1, ty1, then by tx2, ty2:

| 1 0 (tx1+tx2) |
| 0 1 (tx1+tx2) |
| 0 0 1         |
• Scaling: Similar to translations
• Rotations:
• rotate by q1, then by q2, stick the (q1+q2) in for q,
or calculate T1 for q1, then T2 for q2 & multiply them.
Gives same result.

• Rotation about an arbitrary point P in space
• As we mentioned before, rotations are about the origin.
• So to rotate about a point P in space, translate so that P coincides with the origin, then rotate, then translate back:
• Translate by (-Px, -Py)
• Rotate
• Translate by (Px, Py)
•

• T = T1(Px,Py)* T2(q)*T3(-Px, -Py)
•   = | 1  0  Px |   | cos(q)  -sin( q) 0 |   | 1  0  -Px |
| 0  1  Py | * | sin(q)   cos( q) 0 | * | 0  1  -Py |
| 0  0  1  |   | 0        0       1 |   | 0  0   1  |

| cosq      -sinq   Px*(1-cosq)+Py*sinq |
= | sinq       cosq   Py*(1-cosq)-Px*sinq |
| 0           0        1                |
• Scaling about an arbitrary point in Space

• Again,

• Translate P to the origin
• Scale
• Translate P back
• T = T1(Px,Py)* T2(sx, sy)*T3(-Px, -Py)
• T =
•     | sx  0   Px*(1-sx) |
| 0   sy  Py*(1-sy) |
| 0   0   1         |

Commutivity of Transformations
• If we scale , then translate to the origin, then translate back, is that equivalent to translate to origin, scale, translate back?
• When is the order of matrix multiplications unimportant?
• When does T1*T2 = T2*T1?
• Cases where T1*T2 = T2*T1:
•         T1      T2

translation     translation
scale           scale
rotation        rotation
scale(uniform)  rotation
Examples:

# COORDINATE SYSTEMS

Screen Coordinates: The coordinate system used to address the screen ( device
coordinates)

World Coordinates: A user-defined application specific coordinate system

having its own units of measure, axis,origin, etc.

Window: The rectangular region of the world that is visible.

Viewport: The rectangular region of the screen space that is used to display the

window.

# WINDOW TO VIEWPORT TRANSFORMATION

• Want to find the transformation matrix that maps the window in world coordinates to the viewport in screen coordinates.
• Viewport: (u, v space) denoted by umin, vmin ,umax, vmax
• Window: ( x, y space) denoted by xmin, ymin,xmax, ymax
• The transformation:
• 1) Translate the window to the origin
2) Scale it to the size of the viewport
3) Translate it to the viewport location

MWV =  T(umin, vmin)*S(Sx, Sy)*T(-xmin, -ymin)

Sx = (umax -umin)/(xmax-xmin)
Sy = (vmax -vmin)/(ymax-ymin)

MWV =

| S 0       -xmin*Sx+ umin |
| 0   Sy      -ymin*Sy+ vmin |
| 0   0              1       |