際際滷

際際滷Share a Scribd company logo
2D TRANSFORMATIONS
2D Transformations
 What is transformations?
 The geometrical changes of an object from a current
state to modified state.
 Why the transformations is needed?
 To manipulate the initially created object and to display
the modified object without having to redraw it.
 2 ways
 Object Transformation
 Alter the coordinates descriptions an object
 Translation, rotation, scaling etc.
 Coordinate system unchanged
 Coordinate transformation
 Produce a different coordinate system
2D Transformations
Matrix Math
 Why do we use matrix?
 More convenient organization of data.
 More efficient processing
 Enable the combination of various concatenations
 Matrix addition and subtraction
a
b
c
d

a  c
b  d
=
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:
p'x = px + tx
p'y = py + ty
 or in matrix form:
P' = P + T
tx
ty
x
y
x
y
tx
ty
= +
(2, 2)
= 6
=4
?
Rotation
 A rotation repositions
all points in an object
along a circular path in
the plane centered at
the pivot point.
 First, well assume the
pivot is at the origin.

P
P
Rotation
 Review Trigonometry
=> cos  = x/r , sin = y/r
 x = r. cos , y = r.sin 


P(x,y)
x
y
r
x
y

P(x, y)
r
=> cos (+ ) = x/r
x = r. cos (+ )
x = r.coscos -r.sinsin
x = x.cos   y.sin 
=>sin (+ ) = y/r
y = r. sin (+ )
y = r.cossin + r.sincos
y = x.sin  + y.cos  Identity of Trigonometry
Rotation
 We can write the components:
p'x = px cos   py sin 
p'y = px sin  + py cos 
 or in matrix form:
P' = R  P
  can be clockwise (-ve) or
counterclockwise (+ve as our
example).
 Rotation matrix

P(x,y)

x
y
r
x
y

P(x, y)





 





cos
sin
sin
cos
R
 Example
 Find the transformed point, P, caused by rotating P= (5,
1) about the origin through an angle of 90.
Rotation

























 








cos
sin
sin
cos
cos
sin
sin
cos
y
x
y
x
y
x













90
cos
1
90
sin
5
90
sin
1
90
cos
5













0
1
1
5
1
1
0
5







5
1
Scaling
 Scaling changes the size of an
object and involves two scale
factors, Sx and Sy for the x- and
y- coordinates respectively.
 Scales are about the origin.
 We can write the components:
p'x = sx  px
p'y = sy  py
or in matrix form:
P' = S  P
Scale matrix as:







y
x
s
s
S
0
0
P
P
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.
P(2, 5)
P
 Example :
P(2, 5), Sx = 0.5, Sy = 0.5
Find P ?
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.
P(2, 5)
P
 Example :
P(2, 5), Sx = 0.5, Sy = 0.5
Find P ?
If the scale factors are larger than 1
 the points will be moved away from
the origin  the object will be larger.
P
 Example :
P(2, 5), Sx = 2, Sy = 2
Find P ?
Scaling
 If the scale factors are the same, Sx
= Sy  uniform scaling
 Only change in size (as previous
example)
P(1, 2)
P
If Sx  Sy  differential scaling.
Change in size and shape
Example : square  rectangle
P(1, 3), Sx = 2, Sy = 5 , P ?
What does scaling by 1 do?
What is that matrix called?
What does scaling by a negative value do?
Combining transformations
We have a general transformation of a point:
P' = M  P + A
When we scale or rotate, we set M, and A is the additive identity.
When we translate, we set A, and M is the multiplicative identity.
To combine multiple transformations, we must explicitly compute
each transformed point.
Itd be nicer if we could use the same matrix operation all the time.
But wed have to combine multiplication and addition into a
single operation.
Homogenous Coordinates
 Lets move our problem into 3D.
 Let point (x, y) in 2D be represented by point (x, y, 1) in the new
space.
 Scaling our new point by any value a puts us somewhere along a
particular line: (ax, ay, a).
 A point in 2D can be represented in many ways in the new space.
 (2, 4) ---------- (8, 16, 4) or (6, 12, 3) or (2, 4, 1) or etc.
y y
x
x
w
Homogenous Coordinates
 We can always map back to the original 2D point by dividing by
the last coordinate
 (15, 6, 3) --- (5, 2).
 (60, 40, 10) - ?.
 Why do we use 1 for the last coordinate?
 The fact that all the points along each line can be mapped back to
the same point in 2D gives this coordinate system its name 
homogeneous coordinates.
Matrix Representation
 Point in column-vector:
 Our point now has three coordinates. So our matrix is
needs to be 3x3.
 Translation
x
y
1


































1
1
0
0
1
0
0
1
1
y
x
t
t
y
x
y
x
P=T(tx,ty) . P
Rotation:
 Rotation
P=R(). P
 Scaling
Matrix Representation




















 













1
1
0
0
0
cos
sin
0
sin
cos
1
y
x
y
x






































1
1
0
0
0
0
0
0
1
y
x
s
s
y
x
y
x
P=S(sx, sy). P
2hjsakhvchcvj hSKchvsABJChjSVCHjhvcvdxz.pptx
Problem: Scaling

More Related Content

2hjsakhvchcvj hSKchvsABJChjSVCHjhvcvdxz.pptx

  • 2. 2D Transformations What is transformations? The geometrical changes of an object from a current state to modified state. Why the transformations is needed? To manipulate the initially created object and to display the modified object without having to redraw it.
  • 3. 2 ways Object Transformation Alter the coordinates descriptions an object Translation, rotation, scaling etc. Coordinate system unchanged Coordinate transformation Produce a different coordinate system 2D Transformations
  • 4. Matrix Math Why do we use matrix? More convenient organization of data. More efficient processing Enable the combination of various concatenations Matrix addition and subtraction a b c d a c b d =
  • 5. 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: p'x = px + tx p'y = py + ty or in matrix form: P' = P + T tx ty x y x y tx ty = + (2, 2) = 6 =4 ?
  • 6. Rotation A rotation repositions all points in an object along a circular path in the plane centered at the pivot point. First, well assume the pivot is at the origin. P P
  • 7. Rotation Review Trigonometry => cos = x/r , sin = y/r x = r. cos , y = r.sin P(x,y) x y r x y P(x, y) r => cos (+ ) = x/r x = r. cos (+ ) x = r.coscos -r.sinsin x = x.cos y.sin =>sin (+ ) = y/r y = r. sin (+ ) y = r.cossin + r.sincos y = x.sin + y.cos Identity of Trigonometry
  • 8. Rotation We can write the components: p'x = px cos py sin p'y = px sin + py cos or in matrix form: P' = R P can be clockwise (-ve) or counterclockwise (+ve as our example). Rotation matrix P(x,y) x y r x y P(x, y) cos sin sin cos R
  • 9. Example Find the transformed point, P, caused by rotating P= (5, 1) about the origin through an angle of 90. Rotation cos sin sin cos cos sin sin cos y x y x y x 90 cos 1 90 sin 5 90 sin 1 90 cos 5 0 1 1 5 1 1 0 5 5 1
  • 10. Scaling Scaling changes the size of an object and involves two scale factors, Sx and Sy for the x- and y- coordinates respectively. Scales are about the origin. We can write the components: p'x = sx px p'y = sy py or in matrix form: P' = S P Scale matrix as: y x s s S 0 0 P P
  • 11. 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. P(2, 5) P Example : P(2, 5), Sx = 0.5, Sy = 0.5 Find P ?
  • 12. 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. P(2, 5) P Example : P(2, 5), Sx = 0.5, Sy = 0.5 Find P ? If the scale factors are larger than 1 the points will be moved away from the origin the object will be larger. P Example : P(2, 5), Sx = 2, Sy = 2 Find P ?
  • 13. Scaling If the scale factors are the same, Sx = Sy uniform scaling Only change in size (as previous example) P(1, 2) P If Sx Sy differential scaling. Change in size and shape Example : square rectangle P(1, 3), Sx = 2, Sy = 5 , P ? What does scaling by 1 do? What is that matrix called? What does scaling by a negative value do?
  • 14. Combining transformations We have a general transformation of a point: P' = M P + A When we scale or rotate, we set M, and A is the additive identity. When we translate, we set A, and M is the multiplicative identity. To combine multiple transformations, we must explicitly compute each transformed point. Itd be nicer if we could use the same matrix operation all the time. But wed have to combine multiplication and addition into a single operation.
  • 15. Homogenous Coordinates Lets move our problem into 3D. Let point (x, y) in 2D be represented by point (x, y, 1) in the new space. Scaling our new point by any value a puts us somewhere along a particular line: (ax, ay, a). A point in 2D can be represented in many ways in the new space. (2, 4) ---------- (8, 16, 4) or (6, 12, 3) or (2, 4, 1) or etc. y y x x w
  • 16. Homogenous Coordinates We can always map back to the original 2D point by dividing by the last coordinate (15, 6, 3) --- (5, 2). (60, 40, 10) - ?. Why do we use 1 for the last coordinate? The fact that all the points along each line can be mapped back to the same point in 2D gives this coordinate system its name homogeneous coordinates.
  • 17. Matrix Representation Point in column-vector: Our point now has three coordinates. So our matrix is needs to be 3x3. Translation x y 1 1 1 0 0 1 0 0 1 1 y x t t y x y x P=T(tx,ty) . P
  • 19. Rotation P=R(). P Scaling Matrix Representation 1 1 0 0 0 cos sin 0 sin cos 1 y x y x 1 1 0 0 0 0 0 0 1 y x s s y x y x P=S(sx, sy). P