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|
General Problem: |B| = |T| |A|
General Transformation of 2D points:
|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.
| 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
2) Scaling & Reflections: b=0, c=0
so far, what we would expect!
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
3) Off diagonal terms: Shearing
Example of Shearing & Reflections:
let b 0, c=0 (example: b =2)
x' = x
y' = bx + y
y' depends linearly on x
Similarly for b=0, c0
x' = rcos(f +q)
y = rsin(f)
y' = rsin (f +q)
cos(f +q) = cos(f)cos(q) - sin(f)sin(q)
sin(f +q) = 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
Where else are translations introduced?
B = A + Tr, where Tr = |tx ty|T
Note: we can not directly represent
translations as matrix multiplication, as we can rotations and scalings.
1) Rotations - when object not centered at the origin.
Can we represent translations in our general transformation
2) Scaling - when objects / lines not centered at
- 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.
Yes, by using homogeneous
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
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
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
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))=
48,600 multiplies and 32,400 adds
For method 2, we need:
1800*(9 multiplies, 6 adds) + 2* (27 multiplies, 18
adds) = 16,254 multiples and 10,836 adds.
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.
Translate the points by tx1, ty1, then by tx2,
| 1 0 (tx1+tx2) |
| 0 1 (tx1+tx2) |
| 0 0 1 |
Scaling: Similar to translations
rotate by q1, then by q2, stick the (q1+q2) in for
Rotation about an arbitrary point P in space
or calculate T1 for q1, then T2 for q2 & multiply
Gives same result.
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)
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
Translate P to the origin
Translate P back
T = T1(Px,Py)* T2(sx, sy)*T3(-Px, -Py)
| 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:
Screen Coordinates: The coordinate system used
to address the screen ( device
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 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
Window: ( x, y space) denoted by xmin, ymin,xmax,
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)
| Sx 0 -xmin*Sx+ umin |
| 0 Sy -ymin*Sy+ vmin |
| 0 0 1 |