Академический Документы
Профессиональный Документы
Культура Документы
2D Transformations
What is transformations?
The geometrical changes of an object from a current state to modified state.
2D Transformations
2 ways
Object Transformation
Alter the coordinates descriptions an object Translation, rotation, scaling etc. Coordinate system unchanged
Coordinate transformation
Produce a different coordinate system
Matrix Math
Why do we use matrix?
More convenient organization of data. More efficient processing Enable the combination of various concatenations
Matrix Math
How about it? a s c d
b e
Matrix Multiplication
Dot product
a c b d
e g
Matrix Math
What about this?
1 2
1 3 2 1
2 = 1
2 3
1 3
tak boleh!!
Type of matrix
a b Row-vector
a b Column-vector
Matrix Math
Is there a difference between possible representations?
a b e ae bf y ! c d f ce df
?e ?e
a b f Ay ! ?ae cf c d a c f Ay ! ?ae bf b d
be df A ce df A
Matrix Math
Well use the column-vector representation for a point. Which implies that we use pre-multiplication of the transformation it appears before the point to be transformed in the equation.
A B x Ax By C D y y ! Cx Dy
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
?
ty=4
(2, 2)
tx= 6
x x tx y = y + ty
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
U
Rotation
Review Trigonometry
=> cos J = x/r , sin J= y/r x = r. cos J, y = r.sin J => cos (J+ U) = x/r x = r. cos (J+ U) x = r.cosJcosU -r.sinJsinU x = x.cos U y.sin U =>sin (J+ U) = y/r y = r. sin (J+ U) y = r.cosJsinU + r.sinJcosU y = x.sin U + y.cos U
P(x, y)
r
y
U
P(x,y)
r J
x
Identity of Trigonometry
Rotation
We can write the components: p'x = px cos U py sin U p'y = px sin U + py cos U or in matrix form: P' = R P U can be clockwise (-ve) or (counterclockwise (+ve as our example). Rotation matrix
P(x, y)
y
U
P(x,y)
cosU R! sin U
sin U cos U
r J
x
Rotation
Example
Find the transformed point, P, caused by rotating P= (5, 1) about the origin through an angle of 90r.
cos U sin U
sin U x y cos U y
x cos U x sin U
y sin U y cos U
Scaling changes the size of an object and involves two scale factors, Sx and Sy for the xand 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:
S sx 0 0 sy
Scaling
P
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 Find P ?
Scaling
P(2, 5)
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 Find P ? If the scale factors are larger than 1 the points will be moved away from the origin the object will be larger. Example : P(2, 5), Sx = 2, Sy = 2 Find P ?
Scaling
P
P(2, 5)
Scaling
If the scale factors are the same, Sx = Sy uniform scaling Only change in size (as previous example) If Sx { Sy differential scaling. Change in size and shape Example : square rectangle P(1, 3), Sx = 2, Sy = 5 , P ?
P
P(1, 2)
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
y y w x x 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.
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: x y 1 Our point now has three coordinates. So our matrix is needs to be 3x3. Translation
xd 1 0 t x x yd! 0 1 t y y y 1 0 0 1 1
Matrix Representation
Rotation
x y 1
Scaling
cos U sin U 0
sin U cos U 0
0 x 0 y y 1 1
x y 1
s x 0 0
0 sy 0
0 x 0 y y 1 1
Composite Transformation
We can represent any sequence of transformations as a single matrix.
No special cases when transforming a point matrix vector. Composite transformations matrix matrix.
Composite transformations:
Rotate about an arbitrary point translate, rotate, translate Scale about an arbitrary point translate, scale, translate Change coordinate systems translate, rotate, scale
Composition Properties
Is matrix multiplication associative?
(A.B).C = A.(B.C)
a b e c d y g f i y h k j ae bg ! l ce dg af bh i y cf dh k j l aej bgj afl bhl cej dgj cfl dhl
?
j a b ei fk ej fl ! c d y gi hk gj hl l aei afk bgi bhk aej afl bgj bhl ! cei cfk dgi dhk cej cfl dgj dhl
Composition Properties
Is matrix multiplication commutative?
A.B=B.A
?
a b e c d y g
e g
f ae bg ! ce dg h
af bh cf dh
eb fd gb hd
f a b ea fc y c d ! ga hc h
Order of operations
So, it does matter. Lets look at an example:
1. 2. Translate Rotate 1. 2. Rotate Translate
. .
cosU -sinU -tx cosU+ ty sinU sinU cosU -tx sinU - ty cosU 0 0 1
cosU -sinU -tx cosU+ ty sinU + tx sinU cosU -tx sinU - ty cosU + ty 0 0 1
x y 1
0.5 -0.866 -1.0.5 + 2.0.866 + 1 0.866 0.5 -1.0.866- 2.0.5 + 2 0 0 1 0.5 - 0.866 2.232 0.866 0.5 0.134 0 0 1
2 5 1 -1.098 4.366 1
2 5 1
P = (-1, 4)
2. Rotate P = 90 degree P(3, -1) -- > kos 90 -sin 90 3 = 0 -1 3 = 1 sin 90 kos 90 -1 1 0 -1 3 3. Translate back ke pivot point (tx = 2 , ty = 2) titik (1, 3 ) titik akhir (3, 5)
Answer
1 0 0 1 0 0 0 1 0 0 1 0 tx ty 1 tx ty 1
. .
Sx 0 0 Sy 0 0
0 0 1
1 0 0
0 1 0
Sx 0 -tx Sx 0 Sy -ty Sy 0 0 1
x =6, y = 8, Sx = 2, Sy = 3, tx =2, ty = 2
2 0 0
0 3 0
-2( 2) + 2 -2(3) + 2 1
6 8 1
10 20 1
latihan
Dapatkan titik akhir bagi P(5, 8) jika titik tersebut diputarkan sebanyak 90 darjah, kemudian ditranslate sebanyak (-6, 9) dan akhirnya diskala dengan faktor skala (2, 0.5).
S
Sx 0 0 Sy 0 0 0 0 1
T
1 0 0 0 1 0 tx ty 1
R
cosU -sinU 0 sinU cosU 0 0 0 1
. .
Sx 0 0 Sy 0 0 SxcosU Sy sinU 0
0 0 1
Sx(-sinU) Sx tx Sy cosU Sy ty 0 1
Other transformations
Reflection: x-axis y-axis
1 0 0 0 1 0 0 0 1
1 0 0 0 1 0 0 0 1
Other transformations
Reflection: origin line x=y
1 0 0 0 1 0 0 0 1
0 1 0 1 0 0 0 0 1
Other transformations
Shear: x-direction
0 0 1
1 shx 0 1 0 0
1 sh y 0
0 0 1 0 0 1
y-direction