lecture 9: transformationsteaching.csse.uwa.edu.au/units/cits3003/lectures/...Β Β· β’a 2d example:...
TRANSCRIPT
CITS3003 Graphics & Animation
Lecture 9: Transformations
E. Angel and D. Shreiner: Interactive Computer Graphics 6E Β© Addison-Wesley 2012
Objectives
β’ Introduce standard transformationsβ Rotation
β Translation
β Scaling
β Shear
β’ Derive homogeneous coordinate transformation matrices
β’ Learn to build arbitrary transformation matrices from simple transformations
2
Rotation (2D)
β’ Consider a rotation about the origin by q degrees
β radius stays the same, angle increases by q
π₯β² = π₯ cos π β π¦ sin ππ¦β² = π₯ sin π + π¦ cos π
π₯ = π cosππ¦ = π sinπ
π₯β² = π cos(π + π)π¦β² = π sin(π + π)
(Old point p before rotation)
(New point π©β² after rotation)
3
Rotation about the z axis
β’ Rotation in two dimensions is equivalent to rotation about the π§ axis in three dimensions.
β’ Rotation about the π§ axis in 3D leaves the π§ components of all the points unchanged:
π π§ π =
cos π βsin π 0 0sin π cos π 0 000
00
10
01
In homogeneous coordinates
π©β² = ππ(π)π©
4
Rotation about the z axis (cont.)β’ Consider the example
π₯ = π cosππ¦ = π sinπ
π§ = 0we have
π₯β²π¦β²
π§β²1
= π π§(π)
π cosππ sin π
01
=
cos π βsin π 0 0sin π cos π 0 000
00
10
01
π cosππ sinπ
01
=
π cos π cosπ β π sin π sin ππ sin π cosπ + π cos π sinπ
01
5
Rotation about the z axis (cont.)β’ Applying the rule:
cos(π + π) = cos π cosπ β sin π sinπsin π + π = sin π cosπ + cos π sinπ
we get
π₯β²π¦β²
π§β²1
= π π§(π)
π cosππ sinπ
01
=
π cos(π + π)π sin(π + π)
01
β’ Thus,In general, π₯β² = π₯ cos π β π¦ sin π π¦β² = π₯ sin π + π¦ cos π π§β² = π§
π₯β² = π cos(π + π) π¦β² = π sin(π + π) π§β² = 0
6
Rotation about x and y axes
β’ Same argument as for rotation about z axisβ For rotation about x axis, x is unchanged
β For rotation about y axis, y is unchanged
R = Rx(q) =
R = Ry(q) =
1000
0 cos sin0
0 sin- cos0
0001
1000
0 cos0 sin-
0010
0 sin0 cos
Note the negative
sign here7
Scaling
π = π(π π₯, π π¦, π π§) =
1000
000
000
000
z
y
x
s
s
s
π₯β² = π π₯π₯π¦β² = π π¦π¦π§β² = π π§z
π©β² = ππ©
β’ Expand or contract along each axis (fixed point of origin)
8
Reflection
corresponds to negative scale factors
originalsx = -1
sy = 1
sx = -1
sy = -1
sx = 1
sy = -1
9
Inverses
β’ Although we could compute inverse matrices by general formulas, we can use simple geometric observations
β Translation: πβ1(ππ₯ , ππ¦, ππ§) = π(βππ₯ , βππ¦, βππ§)
β Rotation: πβ1(π) = πΉ(βπ)
β’ Holds for any rotation matrix
β’ Note that since cos(βπ) = cos(π) and sin(βπ) =β sin(π)
πβ1(π) = πT(π)
β Scaling: πβ1(π π₯, π π¦, π π§) = π(1/π π₯, 1/π π¦, 1/π π§)
10
Concatenation
β’ We can form arbitrary affine transformation matrices by multiplying together rotation, translation, and scaling matrices
β’ Because the same transformation is applied to many vertices, the cost of forming a matrix π = ππππ is not significant compared to the cost of computing ππ©for many vertices π©
β’ The difficult part is how to form a desired transformation from the specifications in the application
11
Order of Transformations
β’ Note that matrix on the right is the first applied
β’ Mathematically, the following are equivalent
π©β² = ππππ© = π(π(ππ©))
β’ Note many references use row vectors to represent points. For such references:
π©β²T = π©TπTπTπT
12
General Rotation About the Origin
q
x
z
y
v
A rotation angle of q about an arbitrary axis
can be decomposed into the concatenation
of rotations about the π₯, π¦, and π§ axes
πΉ(π) = πΉπ§(ππ§) πΉπ¦(ππ¦) πΉπ₯(ππ₯)
ππ₯ , ππ¦, and ππ§ are called the Euler angles
Note that rotations do not commute
We can use rotations in another order but
with different angles
13
Rotation About a Fixed Point other than the Origin
1. Move the origin to the fixed point
2. Rotate
3. Move the origin back to fixed point back
=> M = T(pf) R(q) T(-pf)
After Step 1 After Step 2 After Step 3
14
Rotation About a Fixed Point other than the Origin (cont.)
β’ A 2D example:Objective: want to rotate a square 45 degrees about its own centre, π©.
This is the same as rotating about the π§-axis (pointing out of the page) in 3D.
x0
y
Before rotation Output wanted after rotation
y
0 x
π©
15
Rotation About a Fixed Point other than the Origin (cont.)
β’ Our aim is to construct a matrix π so that when the four vertices of the square are pre-multiplied by we get the desired output.
β’ Step 1: apply a translation so that the origin is at π©.
x0
y
x0
y
π = π(βπ©)
π©
16
Rotation About a Fixed Point other than the Origin (cont.)
β’ Step 2: apply a 45 degree rotation about the π§-axis at the origin.
x0
y
π = πz π½ π(βπ©)
x0
y
17
Rotation About a Fixed Point other than the Origin (cont.)
β’ Step 3: move the origin back to where it was before.
x0
y
π = π π© πz π½ π(βπ©)
y
0 x
18
Instancing
β’ In modeling, we often start with a simple object centered at the origin, oriented with the axis, and at a standard size
β’ We apply an instance transformation to its vertices to β Scale
β Orient
β Locate
19
Shear
β’ It is helpful to add one more basic transformation, the shearing transformation, to the collection of transformation we have learnt
β’ Shearing is equivalent to pulling faces in opposite directions
20
Shear Matrix
Consider a simple shear along the x axis
π₯β² = π₯ + π¦ cot π π¦β² = π¦ π§β² = π§
q
1000
0100
0010
00cot 1
=> H(q) =
21
Further Reading
βInteractive Computer Graphics β A Top-Down Approach with Shader-Based OpenGLβ by Edward Angel and Dave Shreiner, 6th Ed, 2012
β’ Sec 3.7 Affine Transformations (all subsections)
β’ Sec 3.8 Translation, Rotation, and Scaling
β’ Sec 3.9 Transformations in Homogeneous Coordinates
β’ Sec 3.10 Concatenation of Transformations
22