Transformations and Matrices
2D Transformations
2D Transformations Transformations are functions
Matrices are functions representations
What is transformations? 2 ways Matrices represent linear transformation
Changes in orientation , size , and shape are accomplished Object Transformation {2x2 Matrices} {2D Linear Transformation}
with geometrical transformations that alters the coordinate • Alter the coordinates descriptions an object What are they?
description of object. • Translation, rotation, scaling etc. changing something to something else via rules
Why the transformations is needed? • Coordinate system unchanged mathematics: mapping between values in a range set and
To manipulate the initially created object and to display the Coordinate transformation domain set (function/relation)
modified object without having to redraw it. • Produce a different coordinate system geometric: translate, rotate, scale, shear,…
Why are they important to graphics?
moving objects on screen / in space
mapping from model space to screen space
specifying parent/child relationships
4
Basic Transformation : Rotation
Basic Transformations : Translation (1/2) Translation (2/2)
Translation In matrix form
x tx
Definition : repositioning objects along a straight line path P' P T
y ty
from one position to another Translation is rigid-body Transformation that moves
Let P = x : original position, P = x : new position objects without deformation
y y
• every point on the object is translated by the same amount
We need translation distance (translation vector) For straight line
• applying translation distance to each line end points
tx for x direction
T= For polygon, curves
ty for y direction
Then, x' x tx
y' y ty
Basic Transformations : scaling (1/2)
Scaling
Definition : alters the size of an objects
we need scaling factors
SX 0 : for x value
S
0 Sy : for y value
In matrix form
sx 0 x
P S P
0 sy
y
Then x ' x sx y ' y sy
if sx sy : Uniform scaling
sx sy : differential scaling
scaling (2/2) Inverse 2D - Transformations Homogeneous Co-ordinates (1/3)
if 0 sx sy 1 : uniform compression
-1
Translaiton : T(dx,dy) T(-dx,-dy) Translation, scaling and rotation are expressed
• move objects to the coordinate origin (non-homogeneously) as:
if 1 sx sy : uniform Enlargement Rotation : R -1
(θ ) R(-θ ) translation: P = P + T
• move objects farther from the origin
Scale: P = S · P
Fixed point scaling : scaling based on a fixed point ( xf , yf )
• An object is scaled relative to the fixed point by scaling distance
Sclaing -1
: S (sx,sy) S ( 1sx , 1sy ) Rotate: P = R · P
from each vertex to fixed point Composition is difficult to express, since translation
x' xf (x xf)sx x sx xf(1 sx)
Mirror Ref : M x-1 M x
not expressed as a matrix multiplication
y' yf (y yf)sy y sy yf(1 sy) Homogeneous coordinates allow all three to be expr
essed homogeneously, using multiplication by 3 ´ 3
• when (xf,yf) (0,0) M y-1 M y matrices
W is 1 for affine transformations in graphics
18 19
Homogeneous Co-ordinates (2/3) Homogeneous Coordinates (3/3) Classification of Transformations
1. Rigid-body Transformation
P2d is a projection of Ph onto the w = 1
Preserves parallelism of lines
plane For Translation, Rotation, Scaling
Preserves angle and length
So an infinite number of points correspon x 1 0 t x x e.g. any sequence of R() and T(dx,dy)
d to : they constitute the whole line y 0 1 t y
Translation:
y 2. Affine Transformation
s 0 0 1 1
(tx, ty, tw) w Preserves parallelism of lines
P (x,y,w) h
Doesn’t preserve angle and length
x s x 0 0 x
w=1 Scaling: y 0 sy 0 y e.g. any sequence of R(), S(sx,sy) and T(dx,dy)
P2d(x,y,1) s 0 0 1 1
y Rotation: x cos - sin 0 x
y sin cos 0 y
x s 0
20
0 1 1
unit cube
22
45 deg rotaton Scale in X not in Y
Properties of rigid-body transformation Concatenation properties.
The following Matrix is Orthogonal if the upper left 2X2 matrix has the
following properties Matrix multiplication : associative
r11 r12 tx
r • ex) For three matrices A, B and C
1. A) Each row are unit vector.
21 r22 t y
sqrt(r11* r11 + r12* r12) = 1 A B C (A B) C A (B C)
0 0 1
B) Each column are unit vector. • Translation or Rotation : additive property commutative
sqrt(c11* c11 + c12* c12) = 1 • scaling : multiplicative property commutative
cos sin 0
sin However, Translation and Rotation : non commutative
cos 0
2. A) Rows will be perpendicular to each other • order of transformation matrix multiplication is important
0 0 1
(r11 , r12 ) . ( r21 , r22) = 0
A B B A
B) Columns will be perpendicular to each other
(c11 , c12 ) . (c21 ,c22) = 0
e.g. Rotation matrix is orthogonal
• Orthogonal Transformation Rigid-Body Transformation
• For any orthogonal matrix B B-1 = BT 23
Commutative of Transformation Matrices Composite Transformation (2/2)
Composite Transformation (1/2)
• In general matrix multiplication is not commutative
• For the following special cases commutativity holds i.e. M1.M2 = M2.M1
Translation Rotation
If two successive translation factor (tx1, ty1) and (tx2, ty2) are two successive rotation ,
M1 M2 applied to a coordinate point P P R( 2) {R( 1) P} {R( 2) R( 1)} P
Translate Translate • then R( 1) R( 2) R( 1 2)
Scale Scale P' T2(tX2,ty2) {T1(tx1,ty1) P} {T2(tX2,ty2) T1(tx1,ty1)} P
P' R( 1 2) P
Rotate Rotate • ex) 1 0 tx2 1 0 tx1 1 0 tx1 tx2 two successive rotations are also additive
0 1 ty2 0 1 ty1 0 1 ty1 ty2
Uniform Scale Rotate Scaling
0 0 1 0 0 1 0 0 1
i.e, sx2 0 0 sx1 0 0 sx1 sx2 0 0
• Some non-commutative T(tx2,ty2) T(tx1,ty1) T(tx1 tx2,ty1 ty2) 0 0 0 0
sy2 0 sy1 0 sy1 sy2
Compositions:
0 0 1
0 0 1
0 0 1
Non-uniform scale, Rotate Original
Two successive Translation are additive
Transitional S(SX2,SY2) S(SX1,SY1) S(SX1 SX2,SY1 SY2)
Translate, Scale Final
Rotate, Translate
26
successive scalings are multiplicative