Upload
others
View
10
Download
0
Embed Size (px)
Citation preview
1
1
CS 536 Computer Graphics
Transformations Week 9, Lecture 18
David Breen, William Regli and Maxim Peysakhov Department of Computer Science
Drexel University
3
2D Transformations
4
2D Affine Transformations
All represented as matrix operations on vectors! Parallel lines preserved, angles/lengths not
• Scale • Rotate • Translate • Reflect • Shear
Pics/Math courtesy of Dave Mount @ UMD-CP 5
2D Affine Transformations
• Example 1: rotation and non uniform scale on unit cube
• Example 2: shear first in x, then in y Note: – Preserves parallels – Does not preserve
lengths and angles 1994 Foley/VanDam/Finer/Huges/Phillips ICG
6
2D Transforms: Translation
• Rigid motion of points to new locations
• Defined with column vectors: as
1994 Foley/VanDam/Finer/Huges/Phillips ICG
7
• Stretching of points along axes: In matrix form: or just:
2D Transforms: Scale
1994 Foley/VanDam/Finer/Huges/Phillips ICG
2
8
• Rotation of points about the origin
Positive Angle: CCW Negative Angle: CW
Matrix form: or just:
2D Transforms: Rotation
1994 Foley/VanDam/Finer/Huges/Phillips ICG
9
2D Transforms: Rotation • Substitute the
1st two equations into the 2nd two to get the general equation
1994 Foley/VanDam/Finer/Huges/Phillips ICG
rcos(θ + φ) rcos(φ)
€
x'= x cos(θ) − y sin(θ)y'= x sin(θ) + y cos(θ)
10
Homogeneous Coordinates
• Observe: translation is treated differently from scaling and rotation
• Homogeneous coordinates: allows all transformations to be treated as matrix multiplications
Example: A 2D point (x,y) is the line (x,y,w), where w is any real #, in 3D homogenous coordinates. To get the point, homogenize by dividing by w (i.e. w=1)
1994 Foley/VanDam/Finer/Huges/Phillips ICG
11
Recall our Affine Transformations
Pics/Math courtesy of Dave Mount @ UMD-CP
12
Matrix Representation of 2D Affine Transformations
• Translation:
• Scale:
• Rotation:
• Shear: Reflection: Fy=
13
Composition of 2D Transforms • Rotate about a point P1
– Translate P1 to origin – Rotate – Translate back to P1
1994 Foley/VanDam/Finer/Huges/Phillips ICG
P’ = T ✴ P T
3
14
Composition of 2D Transforms • Scale object around point P1
– P1 to origin – Scale – Translate back to P1
– Compose into T
1994 Foley/VanDam/Finer/Huges/Phillips ICG
P’ = T ✴ P 15
Composition of 2D Transforms • Scale + rotate object
around point P1 and move to P2 – P1 to origin – Scale – Rotate – Translate to P2
1994 Foley/VanDam/Finer/Huges/Phillips ICG
P’ = T ✴ P
16
• Be sure to multiple transformations in proper order!
Composition of 2D Transforms
P’ = T ✴ P
P’ = ((T✴ (R✴ (S ✴ T)))✴ P)
P’ = (T✴(R✴(S✴ (T✴ P))))
18
The Window-to-Viewport Transformation
• Problem: Screen windows cannot display the whole world (window management)
• How to transform and clip: Objects to Windows to Screen
Pics/Math courtesy of Dave Mount @ UMD-CP
19
Window-to-Viewport Transformation
• Given a window and a viewport, what is the transformation from WCS to VPCS?
Three steps: • Translate • Scale • Translate
1994 Foley/VanDam/Finer/Huges/Phillips ICG
20
Transforming World Coordinates to Viewports
• 3 steps 1. Translate 2. Scale 3. Translate
Overall Transformation:
1994 Foley/VanDam/Finer/Huges/Phillips ICG
€
P'= MwvP
4
24
3D Transformations
25
Representation of 3D Transformations
• Z axis represents depth • Right Handed System
– When looking “down” at the origin, positive rotation is CCW
• Left Handed System – When looking “down”, positive
rotation is in CW – More natural interpretation for
displays, big z means “far” (into screen)
1994 Foley/VanDam/Finer/Huges/Phillips ICG
26
3D Homogenous Coordinates
• Homogenous coordinates for 2D space requires 3D vectors & matrices
• Homogenous coordinates for 3D space requires 4D vectors & matrices
• [x,y,z,w] 27
3D Transformations: Scale
• Scale – Parameters for each
axis direction
28
3D Transformations: Translate
• Translation
29
3D Transformations: Rotation
• One rotation for each world coordinate axis
5
30
Rotation Around an Arbitrary Axis
• Rotate a point P around axis n (x,y,z) by angle θ
• c = cos(θ) • s = sin(θ) • t = (1 - c)
Graphics Gems I, p. 466 & 498 €
R =
tx 2 + c txy + sz txz − sy 0txy − sz ty 2 + c tyz + sx 0txz + sy tyz − sx tz2 + c 00 0 0 1
#
$
% % % %
&
'
( ( ( (
• Also can be expressed as the Rodrigues Formula
31 €
Prot = P cos(ϑ ) + (n× P)sin(ϑ ) + n(n ⋅ P)(1− cos(ϑ ))
Rotation Around an Arbitrary Axis
Improved Rotations
• Euler Angles have problems – How to interpolate keyframes? – Angles aren’t independent – Interpolation can create Gimble Lock, i.e.
loss of a degree of freedom when axes align
• Solution: Quaternions!
32 33
34 35
€
p = (0, x )
6
36 37
38
slerp – Spherical linear interpolation Need to take equals steps on the sphere
A & B are quaternions
What about interpolating multiple keyframes?
• Shoemake suggests using Bezier curves on the sphere
• Offers a variation of the De Casteljau algorithm using slerp and quaternion control points
• See K. Shoemake, “Animating rotation with quaternion curves”, Proc. SIGGRAPH ’85
39
40
3D Transformations: Reflect
• Reflection:
about x-y plane
about y-z plane Fx =
−1 0 0 00 1 0 00 0 1 00 0 0 1
"
#
$$$$
%
&
''''
Reflection
corresponds to negative scale factors
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
original sx = -1 sy = 1
sx = -1 sy = -1 sx = 1 sy = -1
7
43
3D Transformations: Shear
• Shear: (function of y)
Hx =
1 shx 0 00 1 0 00 0 1 00 0 0 1
!
"
####
$
%
&&&&
x ' = x +shx ⋅ y
45
3D Transformations: Shear
€
X 'Y 'Z '1
"
#
$ $ $ $
%
&
' ' ' '
=
1 Shxy Shx
z 0Shy
x 1 Shyz 0
Shzx Shz
y 1 00 0 0 1
"
#
$ $ $ $
%
&
' ' ' '
∗
XYZ1
"
#
$ $ $ $
%
&
' ' ' '
X ' = X + ShxyY + Shx
zZ
Y ' = ShyxX +Y + Shy
zZ
Z ' = ShzxX + Shz
yY + Z
46
Example: Composition of 3D Transformations
• Goal: Transform P1P2 and P1P3
1994 Foley/VanDam/Finer/Huges/Phillips ICG
47
Example (Cont.)
• Process 1. Translate P1 to (0,0,0) 2. Rotate about y 3. Rotate about x 4. Rotate about z
(1)
(2-3)
(4)
1994 Foley/VanDam/Finer/Huges/Phillips ICG
48
Final Result • What we’ve really
done is transform the local coordinate system Rx, Ry, Rz to align with the origin x,y,z
1994 Foley/VanDam/Finer/Huges/Phillips ICG
49
Example 2: Composition of 3D Transformations
• Airplane defined in x,y,z • Problem: want to point it
in Dir of Flight (DOF) centered at point P
• Note: DOF is a vector • Process:
– Rotate plane – Move to P
1994 Foley/VanDam/Finer/Huges/Phillips ICG
8
50
Example 2 (cont.)
• Zp axis to be DOF • Xp axis to be a horizontal
vector perpendicular to DOF – y x DOF
• Yp, vector perpendicular to both Zp and Xp (i.e.Zp x Xp)
1994 Foley/VanDam/Finer/Huges/Phillips ICG
51
Transformations to Change Coordinate Systems
• Issue: the world has many different relative frames of reference
• How do we transform among them? • Example: CAD Assemblies & Animation Models
52
Transformations to Change Coordinate Systems
• 4 coordinate systems 1 point P
)45()8.1,7.6(
)5.0,5.0()3,2()2,4(
43
32
21
RTMSTM
TM
•=
•=
=
←
←
←
1994 Foley/VanDam/Finer/Huges/Phillips ICG
53
Coordinate System Example (1)
• Translate the House to the origin
€
M1←2 = T(x1,y1)
M2←1 = M1←2( )−1
= T(−x1,−y1)
1994 Foley/VanDam/Finer/Huges/Phillips ICG
The matrix Mij that maps points from coordinate system j to i is the inverse of the matrix Mji that maps points from coordinate system j to coordinate system i.
P1
54
Coordinate System Example (2) • Transformation
Composition:
€
M5←1 = M5←4 •M4←3 •M3←2 •M2←1
1994 Foley/VanDam/Finer/Huges/Phillips ICG
55
World Coordinates and Local Coordinates
• To move the tricycle, we need to know how all of its parts relate to the WCS
• Example: front wheel rotates on the ground wrt the front wheel’s z axis: Coordinates of P in wheel coordinate system:
1994 Foley/VanDam/Finer/Huges/Phillips ICG €
P(wo) = T(αr,0,0) ⋅ Rz(α) ⋅ P(wh )
€
P'(wh )= Rz (α) ⋅ P(wh )
9
Properties of Transformation Matrices
• Note that matrix multiplication is not commutative
• i.e. in general M1M2 ≠ M2M1
• T – reflection around y axis • T’ – rotation in the plane