CG 2d Trans
CG 2d Trans
CG 2d Trans
Transformations
• Rigid Body Transformations - transformations that do
not change the object.
• Translate
– If you translate a rectangle, it is still a rectangle
• Scale
– If you scale a rectangle, it is still a rectangle
• Rotate
– If you rotate a rectangle, it is still a rectangle
Translation
• A translation moves all points
in an object along the same
straight-line path to new
positions.
• The path is represented by a ?
vector, called the translation or
shift vector.
• We can write the components: ty=4
x' = x + tx
y' = y + ty (2, 2) tx= 6
• or in matrix form:
P' = P + T
x’ y’ = x y + tx ty
Example:
Q. Translate the polygon with coordinate A(2,5) , B(7,10)
and C(10,2) by 3 units in x direction and 4 units in y
direction.
=>sin ( + ) = y’/r x’ x
y’ = r. sin ( + )
Identity of Trigonometry
•y’ = r.cos sin + r.sin cos
•y’ = x.sin + y.cos
Rotation
• We can write the components:
x' = x cos – y sin
y' = x sin + y cos
P’(x’, y’)
• or in matrix form:
P' = R • P
• can be clockwise (-ve) or
counterclockwise (+ve as our
example). y’
P(x,y)
• Rotation matrix
r y
cos sin
R
sin cos x
x’
• Default direction of rotation is
anticlockwise direction.
x’ y’ = x y cos ө sinө
-Sinө cosө
example
• A point (4,3) is rotated counterclockwise by
an angle of 45° . Find the rotation matrix
and resultant point.
Scaling
• Scaling changes the size of an
object and involves two scale
factors, Sx and Sy for the x-
and y- coordinates P’
respectively.
• Scales are about the origin.
• We can write the components:
x’ = sx • px
P
Y’ = sy • py
or in matrix form:
P' = S • P
Scale matrix as:
sx 0
S
0 sy
Scaling
• If the scale factors are in between 0
and 1 the points will be moved
closer to the origin the object
will be smaller.
• Example :
•P(2, 5), Sx = 0.5, Sy = 0.5
P(2, 5)
•Find P’ ?
P’
Scaling
• If the scale factors are in between 0
and 1 the points will be moved
P’
closer to the origin the object
will be smaller.
• Example :
•P(2, 5), Sx = 0.5, Sy = 0.5
P(2, 5)
•Find P’ ?
•If the scale factors are larger than 1
the points will be moved away P’
P' = P M1 + M2
Where
X= Xw / W , Y=Yw / W
( x , y , 1)
Homogeneous coordinate for translation are:
1 0 0
X’ Y’ 1 = X Y 1
0 1 0
tx ty 1
= X+tx Y+ty 1
Homogeneous coordinate for rotation are:
Cos Θ sin Θ 0
R =
-Sin Θ cos Θ 0
0 0 1
Cos Θ sin Θ 0
X’ Y’ 1 = X Y 1 -Sin Θ cos Θ 0
0 0 1
Sx 0 0
S =
0 sy 0
0 0 1
Sx 0 0
X’ Y’ 1 = X Y 1 0 sy 0
0 0 1
= x s x y sy 1
Q. Give 3 x 3 Homogeneous coordinate transformation
tx = ty = 2 sx =sy = 0.5
Q. find transformation of triangle A(1,0) B(0 , 1) C(1,1) by
• Composite transformations:
– Rotate about an arbitrary point – translate, rotate,
translate
– Scale about an arbitrary point – translate, scale,
translate
– Change coordinate systems – translate, rotate, scale
Order of operations
So, it does matter. Let’s look at an example:
1. Translate 1. Rotate
2. Rotate 2. Translate
Composite Transformation Matrix
General Pivot- Point Rotation
Operation :-
1. Translate (pivot point is moved to origin)
2. Rotate about origin
T(pivot) • R( ) • T(–pivot)
Composite Transformation Matrix
1 0 0 cos sin 0 1 0 0
0 1 0 . -sin cos 0 . 0 1 0
-tx -ty 1 0 0 1 tx ty 1
cos sin 0 1 0 0
-sin cos 0 . 0 1 0
-tx cos + ty sin -tx sin - ty cos 1 tx ty 1
cos sin 0
-sin cos 0
-tx cos + ty sin +tx -tx sin - ty cos +ty 1
Q. Perform counter clockwise 45° rotation of
x-axis 1 0 0
0 1 0
0 0 1
Other transformations
Reflection: about y axis
y-axis
1 0 0
0 1 0
0 0 1
Other transformations
Reflection: about origin
1 0 0
0 1 0
0 0 1
Other transformations
Reflection: about y=x
0 1 0
1 0 0
0 0 1
Other transformations
Reflection: about y= -x
0 1 0
1 0 0
0 0 1
Other transformations
Shear : Transformation that slant the shape of an object .
X shear: preserve the y coordinate but change x value which
1 0 0
shx 1 0
0 0 1
Other transformations
y shear: preserve the x coordinate but change y value
which causes horizontal line to transform in to lines
which slope up or down
1 shy 0
0 1 0
0 0 1
Inverse Transformation
Determinant of a 2 x 2 matrix is ;
det t11 t12 = t11 t22 - t12 t21
t21 t22
• Inverse of homogeneous coordinate transformation matrix
can be given as ,
a d 0 -1 1 e -d 0
b e 0 = ------- -b a 0
c f 1 ae-bd bf-ce cd-af ae-bd