Beruflich Dokumente
Kultur Dokumente
2D-Transformations
Contents
Why transformations
Transformations
• Translation
• Scaling
• Rotation
Homogeneous coordinates
Matrix multiplications
Combining transformations
Transformation
• What is transformations?
• To manipulate the initially created object and to display the modified object
without having to redraw it.
Translation
y
6
0
1 2 3 4 5 6 7 8 9 10 x
Y 6 5
6
5
4
dx = 2 3 3
3
dy = 3
2
1
0
1 2 3 4 5 6 7 8 9 10
X
x x' dx
v , v' , t
Component-wise addition of vectors y y ' dy
v’ = v + t where
x’ = x + dx
y’ = y + dy
Scaling
y
6
3 6 9
3 3
2
1 2 3
1 1
0
1 2 3 4 5 6 7 8 9 10 x
sx 3
sy 2
2 3
6 9
1 1 2 2
v’ = Sv where x x'
v , v'
y y '
and x' s x x
sx 0
S
0 sy
y' s y y
Rotation
2
1 6
x
0
1 2 3 4 5 6 7 8 9 10
Rotation
Consider rotation about the origin by q degrees
• radius stays the same, angle increases by q
x’ = r cos (φ + )
y’ = r sin (φ+ )
Rotate by q
6
about the origin.
x x'
v , v'
y y '
v’ = Rθ v where cos
R
sin
sin cos
xh yh
•We can then any point (x, y)yas(hx, hy, h)
x write
h
•We can conveniently choose hh = 1 so that
(x, y) becomes (x, y, 1)
Homogeneous Coordinates
Ph (x,y,w)
x 1
• What is
y ? P2d (x/w,y/w,1)
w X
a b c x a * x b * y c * z
d e
f y d * x e * y f * z
g h i z g * x h * y i * z
Homogeneous Translation
1 0 dx x 1* x 0 * y dx *1 x dx
0 1 dy y 0 * x 1* y dy *1 y dy
0 0 1 1 0 * x 0 * y 1*1 1
Homogenous Coordinates
1 0 dx x x dx
Translation: 0 1 dy y y dy : v' T (dx, dy )v
0 0 1 1 1
sx 0 0 x sx x
0 sy 0 y sy y : v' S (sx, sy )v
Scaling:
0 0 1 1 1
Homogenous Coordinates (cont…)
Rotation:
Composite translations:
P T t2 x , t2 y T t1x , t1 y P T t2 x , t2 y T t1x , t1 y P
1 0 t2 x 1 0 t1x 1 0 t1x t2 x
0 1 t 0 1 t 0 1 t t
2y 1y 1y 2y
T t2 x , t2 y T t1x , t1 y T t1x t2 x , t1 y t2 y
Two successive Translations are Additive
Composite Transformations
R 2 R 1 R 1 2
P R 1 2 P
Two successive Rotations are Additive
Composite Scaling:
S2 x 0 0 S1x 0 0 S1x S2 x 0 0
0 S2 y 0 0 S1 y 0 0 S1 y S2 y 0
0 0 1 0 0 1 0 0 1
S S2 x , S2 y S S1x , S1 y S S1x S2 x , S1 y S2 y
Concatenation Properties
A . B . C = ( A . B ) .C = A . ( B . C )
A.B=B.A
Composite Transformations
y
Order of Transformations
x
Object is first rotated by 90º and then
translated in the x direction
y
x
Object is first translated in the x direction
and then rotated by 90º
Composite Transformations
House (H ) T (dx,dy ) H
1 2
4
3
Pivot -Point Rotation
Pivot-Point Rotation
T x f , y f S s x , s y T x f , y f S x f , y f , s x , s y
1 0 xf s x 0 0 1 0 x f s x 0 x f (1 s x )
0 1 yf 0 sy 0 0 1 y f 0 sy y f (1 s y )
0 0 1 0 0 1 0 0 1 0 0 1
2D Reflection
y y=x
• With respect to the line y = x
x 0 1 0 x
y
1 0 0 y
1 0 0 1 1
x
The shear transformation in the x-direction with shearing factor shx is the
following:
The shear transformation in the y-direction with shearing factor shy is the
following:
y y
3
1 2
1
1 x 1 x
Initial object shy = 2
2D Shearing
• x-direction relative to other reference line
y
x x shx ( y yref )
1
y y
1 x
yref = -1
Matrix form y
shx = ½, yref = -1
2D Shearing
• y-direction relative to other reference line y
x x
y y shy ( x xref )
1
xref = -1 1 x
Matrix form
y
x 1 0 0 x 2
y shx 1 shy xref y
1 0 1 1
0 1
xref = -1 1 x
shy = ½, xref = -1
Transformations between 2D Coordinate Systems
y0
x0
x
y
1)
1 0 x0
T ( x0 , y0 ) 0 1 y0 y0
2) 0 0 1
x0
x
Concatenating:
cos sin 0 y
R( ) sin cos 0
0 1
0
x
M xy , xy R( ) T ( x0 , y0 )
Equations
Translation:
xnew = xold + dx ynew = yold + dy
Scaling:
xnew = Sx × xold ynew = Sy × yold
Rotation:
xnew = xold × cosθ – yold × sinθ
ynew = xold × sinθ + yold × cosθ
Exercises 1
(2, 3)
3
(1, 2) (3, 2)
2
1
(2, 1)
0 x
1 2 3 4 5 6 7 8 9 10
Exercises 2
4
(2, 3)
3
(1, 2) (3, 2)
1
(2, 1)
x
0 1 2 3 4 5 6 7 8 9 10
Exercises 3
4
(7, 3)
3
(6, 2) (8, 2)
1
(7, 1)
x
0 1 2 3 4 5 6 7 8 9 10
2D Homogeneous Coordinate Transformations
1 0 7 1 8
0 1 9 3 12
0 0 1 1 1
5 0 0 2 10
0 10 0 3 30
0 0 1 1 1
2D Homogeneous Coordinate Transformations
3/2 1 / 2 2 32
1/ 2 3 / 2 4 1 2 3
Problem-2
• Magnify the triangle with vertices A(0,0),B(1,1) and C(5,2) to twice its
size while keeping C(5,2) fixed
• Soln
1 0 5 2 0 0 1 0 5 2 0 5
0 1 2 0 2 0 0 1 2 0 2 2
0 0 1 0 0 1 0 0 1 0 0 1
Problem-2(contd…)
•Represent point P with coord(x,y) by the
column vector xy we have,
1
2 0 5 0 5
0 2 2
0
2
•S2,2.A= 0 0 1 1
1
2 0 5 1 3
0 2 2
1 0
•S2,2.B=
0 0 1 1 1
2 0 5 5 5
•S2,2.C= 0 2 2
2 2
0 0 1 1
1
Problem-3
• Consider the line with endpoints (10, 10) and (30, 25).
Translate it by tx = -20, ty = -10 and then rotate it by θ = 90º.
y
(30, 25)
(10, 10)
x
Right-to-left
0 1 0 1 0 20 x
1 0 0 0 1 10 y
0 0 1 0 0 1 1
y
0 1 10 x
(30, 25)
1 0 20 y
0 0 1
1 (10, 10)
x
Solution (continue)
x 0 1 10 x y
y
1 0 20 y (30, 25)
1 0 0 1
1 (-15, 10)
(10, 10)
x
Point (10, 10) (0, -10)
x 0 1 10 10 0
y
1 0 20 10
10
1 0 0 1 1
1
Point (30, 25)
x 0 1 10 30 15
y
1 0 20 25
10
1 0 0 1
1 1
Problem-4,5,6,7
4. Given rectangular coordinates are (2, 1), (5,1), (5, 3) and (2, 3). Scale the given
rectangular by twice of its size with the reference point (2, 1). Check the displacement of
the rectangle. If it is displaced then give the reason, if it is not displaced give the reason.
5. Given triangles three vertexes are not on the origin. You are asked to rotate the triangle
about 60o in anti clock wise direction with respect to any one of the vertex of the triangle.
What type of rotation it is? Derive the formula for the rotation to be performed by you.
6. The Triangular coordinates are (2, 1), (6, 1) and (4, 4). Apply the following transformation
individually and find out the transformed coordinates for the transformations.
a)Translate the given triangle towards x axis 3 units and towards y axis 2 units.
b)Perform scaling to reduce the triangle to its half of its size.
c)Rotate the triangle about 45 degree in anti clock wise direction with respect to origin.
7. Given Rectangular coordinates are (3, 2), (7, 2), (7, 4) and (3, 4). Perform the following
transformation individually.
a)Perform translation towards x axis 3 units and towards y axis 4 units.
b)Perform scaling to make the given rectangle twice of its given size.
c)Rotate the given triangle about 60 degree towards anti clock wise direction with
respect to origin.
Problem-8
8. Construct a triangle ABC whose coordinates are A(4,1), B(5,2) and C(4,3)
(i). Reflect the given triangle about X axis
(ii). Reflect the given triangle about Y axis
(iii). Reflect the given triangle about Y=X axis
In each case find the Coordinates of reflected triangle
The End