Representations and Transformations Objectives

Transcription

Representations and Transformations Objectives
Representations
and
Transformations
Objectives
• Derive homogeneous coordinate
transformation matrices
• Introduce standard transformations
- Rotations
- Translation
- Scaling
- Shear
2
1
Scalars, Points, Vectors
•Three basic elements from geometry:
Scalars, Points, Vectors
•Scalars can be defined as members of a set
which can be combined by the operations of
addition and multiplication and obey the
fundamental axioms:
associativity, commutivity, inversion
•Examples include the real and complex numbers
under the rules we are all familiar with
•Scalars alone have no geometric properties
3
Scalars, Points, Vectors
• A vector is a quantity with two attributes
direction & magnitude and its own rules as we
saw last lecture
• The set defines a vector space
•But, vectors lack position
Same length and magnitude ->
•Vectors are insufficient to specify geometry
We need points
4
2
Points and Vectors
• Points, we know, are locations in space
• Certain operations translate between
points and vectors
- Point-point subtraction yields a vector
- Leads to equivalent to point-vector addition
v=P-Q
P=v+Q
5
Vector Spaces
• Consider a basis v1, v2,…., vn
• A vector is written v=1v1+ 2v2 +….+nvn
• The list of scalars {1, 2, …. n} then is the
representation of v with respect to the given
basis
• And we write the representation as a row or
column array of scalars
 
1
a=[1
2 ….
 
2
T
n] =  . 
 
 n
 
6
3
Affine Spaces
• Vector spaces do not represent points
• Instead, we work in an affine space and
add a special point, the origin, to the basis
vectors, this is called a frame
v2
P0
v1
v3
7
Affine Spaces
• An affine space is both point and vector
space
• It allows operations from vectors, points and
scalars:
- Vector-vector addition
- Scalar-vector multiplication
- Point-vector addition
- All scalar-scalar operations
• Define our space with a coordinate “Frame”
8
4
Affine Spaces
•A frame is determined by (P0, v1, v2, v3, ...)
•Within this frame:
Every vector can be written as
v=1v1+ 2v2 +….+nvn
And every point can be written as
P = P0 + 1v1+ 2v2 +….+nvn
9
Homogeneous Coordinates
Consider the point and the vector
P = P0 + 1v1+ 2v2 +….+nvn
v=1v1+ 2v2 +….+nvn
They appear to have the similar representations
v=[1 2 3]
p=[1 2 3]
v
which confuse the point with the vector
p
But, a vector has no position
v
can be placed anywhere
fixed
10
5
Homogeneous Coordinates
• An affine space distinguishes point and
vector with
( 1 )( P ) = P
( 0 )( P ) = 0 (zero vector)
11
Homogeneous Coordinates
With these rules, we can keep track of the
difference:
v=1v1+ 2v2 +3v3 = [1 2 3 0 ] [v1 v2 v3 P0] T
P = P0 + 1v1+ 2v2 +3v3= [1 2 3 1 ] [v1 v2 v3 P0] T
Thus we obtain a four-dimensional
representation for both:
v = [1 2 3 0 ] T
p = [   1 ] T
1
2
3
12
6
Homogeneous Coordinates
• Homogeneous coordinates are key to all
computer graphics systems
• Hardware pipeline all work with 4 dimensional
representations
• All standard transformations (rotation,
translation, scaling) can be implemented by
matrix multiplications with 4 x 4 matrices
13
Homogeneous Coordinates
•Most generally, the form of homogeneous
coordinates is
p=[x y z w] T
•We can return to a simple three dimensional
point by
x'x/w
y'y/w
z'z/w
•But if w=0, the representation is that of a vector
14
7
Transformations
• A transformation maps points to other
points and/or vectors to other vectors
v=T(u)
Q=T(P)
15
Affine Transformations
• Line preserving
• Characteristic of many physically
important transformations
- Rigid body transformations: rotation, translation
- Non-rigid: Scaling, shear
• Importance in graphics is that we need
only transform vertices (points) of line
segments and polygons, then system
draws between the transformed points
16
8
Translation
• Move (translate, displace) a point to a
new location
P’
d
P
• Displacement determined by a vector d
- Three degrees of freedom
- P’=P+d
17
Moving objects
When we move a point on an object to a new
location, to preserve the object, we must move
all other points on the object in the same way
object
translation: every point displaced
by the same vector, d
18
9
Translation Using
Representations
Using the homogeneous coordinate
representation in some frame
p=[ x y z 1]T
p’=[x’ y’ z’ 1]T
d=[dx dy dz 0]T
Hence p’ = p + d or
x’=x+dx
note that this expression is in
y’=y+dy
four dimensions and expresses
that point = vector + point
z’=z+dz
19
Translation Matrix
We can also express translation using a
4 x 4 matrix T in homogeneous coordinates
p’=Tp where
1
0
T = T(dx, dy, dz) = 
0

0
0 0 dx 
1 0 dy 

0 1 dz 

0 0 1
This form is better for implementation because all affine
transformations can be expressed this way and
multiple transformations can be concatenated together
20
10
Rotation (2D)
• Consider rotation about the origin by  degrees
- radius stays the same, angle increases by 
What is this rotation
about the z axis?
21
Rotation (2D)
• Consider rotation about the origin by  degrees
- radius stays the same, angle increases by 
x = r cos (
y = r sin (
x’=x cos  –y sin 
y’ = x sin  + y cos 
x = r cos 
y = r sin 
22
11
Rotation about the z axis
• Rotation about z axis in three dimensions leaves
all points with the same z
- Equivalent to rotation in two dimensions in
planes of constant z
x’=x cos  –y sin 
y’ = x sin  + y cos 
z’ =z
- or in matrix notation (with p as a column)
p’=Rz()p
23
Rotation Matrix
Homogeneous Coordinates:
cos   sin 

cos 
R = Rz() =  sin 
 0
0

0
 0
0 0
0 0
1 0

0 1
24
12
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
0
0
0
1
0 cos  - sin  0


R = Rx() = 0 sin  cos  0


0
0
1
0
 cos 

R = Ry() =  0
- sin 

 0
0 sin  0
1
0
0

0 cos  0

0
0
1
25
Scaling
Expand or contract along each axis (fixed point of origin)
x’=sxx
y’=syy
z’=szz
p’=Sp
S = S(sx, sy, sz) =
 sx
0

0

0
0
sy
0
0
0
0
sz
0
0
0

0

1
26
13
Reflection
corresponds to negative scale factors
sx = -1 sy = 1
original
sx = -1 sy = -1
sx = 1 sy = -1
27
Shear
•Helpful to add one more basic transformation
•Equivalent to pulling faces in opposite directions
28
14
Shear Matrix
Consider simple shear along x axis
x’ = x + y shy
y’ = y
z’ = z
1 shy
0 1
H() = 
0 0

0 0
0 0
0 0
1 0

0 1
29
Inverses
• Although we could compute inverse matrices by
general formulas, we can also use simple
geometric observations, for example:
- Translation: T-1(dx, dy, dz) = T(-dx, -dy, -dz)
- Rotation: R -1() = R(-)
• Holds for any rotation matrix
• Note that since cos(-) = cos() and sin(-)= -sin()
R -1() = R T()
- Scaling: S-1(sx, sy, sz) = S(1/sx, 1/sy, 1/sz)
30
15
Composite
•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 composite transformation to
its vertices to
Scale
Orient
Locate
31
Composite Transformations
• Scaling about a fixed point
- Simply applying the scale transformation
also moves the object being scaled.
Q'
Q
P
P'
32
16
Composite Transformations
• Scaling about origin does not move object
• Origin is a fixed point for the scale transformation
• We use composite transformations to create scale
transformations with different fixed points
Q'
Q
P'
P
33
Composite Transformations
• Fixed point scale transformation
• Move fixed point (px,py,pz) to origin
• Scale by desired amount
• Move fixed point back to original position
M = T(px, py, pz) S(sx, sy, sz) T(-px, -py, -pz)
34
17
Composite Transformations
• Rotating about a fixed point
- basic rotation alone will rotate about origin
but we want:
35
Composite Transformations
• Rotating about a fixed point
• Move fixed point (px,py,pz) to origin
• Rotate by desired amount
• Move fixed point back to original position
M = T(px, py, pz) Rx() T(-px, -py, -pz)
36
18
Composite Transformations
37
Composite transformations
A series of transformations on an
object can be applied as a series of
matrix multiplications
: position in the global coordinate
: position in the local coordinate
38
19
Interpolation
• In order to “move things”, we need both
translation and rotation
• Interpolating the translation is easy, but
what about rotations?
39
Interpolation of orientation
• How about interpolating each entry of the
rotation matrix?
• The interpolated matrix might no longer be
orthonormal, leading to nonsense for the
in-between rotations
40
20
Interpolation of orientation
Example: interpolate linearly from a positive 90
degree rotation about y axis to a negative 90
degree rotation about y
Linearly interpolate each
component and halfway
between, you get this...
41
Motivation
• Finding the most natural and compact
way to present rotation and orientations
• Orientation interpolation which result in a
natural motion
• A closed mathematical form that deals
with rotation and orientations (expansion
for the complex numbers)
42
21
Representing Rotation
• Rotation matrix
• Euler angle
• Axis angle
• Quaternion
• Exponential map
43
Joints and rotations
Rotational DOFs are widely used in character animation
3 translational DOFs
48 rotational DOFs
Each joint can have up to 3 DOFs
1 DOF: knee
2 DOF: wrist
3 DOF: arm
44
22
Euler Angle
Representation
• Angles used to rotate about cardinal
axes
• Orientations are specified by a set of 3
ordered parameters that represent 3
ordered rotations about axes, ie. first
about x, then y, then z
• Many possible orderings, don’t have to
use all 3 axes, but can’t do the same axis
back to back
45
Euler Angles
• A general rotation is a combination of three
elementary rotations: around the x-axis (x-roll) ,
around the y-axis (y-pitch) and around the z-axis (zyaw).
46
23
Euler Angles and
Rotation Matrices
0
0
1

 0 cos 1 sin 1
x  roll (1 )  
0  sin 1 cos 1

0
0
0
 cos  3 sin  3

  sin  3 cos  3
z  yaw( 3 )  
0
0

0
0

0

0
0

1 
 cos  2

 0
y - pitch( 2 )  
sin  2

 0
0  sin  2
1
0
0
0
cos  2
0
0

0
0

1 
0 0

0 0
1 0

0 1 
c2 c3


 s1s2 c3  c1s3
R(1 , 2 , 3 )  
c s c s s
 1 2 3 1 3

0

c2 s3
 s2
s1 s2 s3  c1c3
c1s2 s3  s1c3
s1c2
c1c2
0
0
0

0
0

1 
47
Gimbal Lock
• A 90 degree rotation about the y axis essentially
makes the first axis of rotation align with the third.
• Incremental changes in x,z produce the same
results – you’ve lost a degree of freedom
48
24
Gimbal Lock
• Phenomenon of two
rotational axis of an object
pointing in the same
direction.
• Result: Lose a degree of
freedom (DOF)
49
Gimbal Lock
A Gimbal is a hardware implementation of
Euler angles used for mounting
gyroscopes or expensive globes
Gimbal lock is a basic problem with
representing 3D rotation using Euler
angles or fixed angles
50
25
Euler angles interpolation
y
π
z
y
π
y
x
x
z
x
x-roll
π
z
y
y-pitch
π
x
π
R(0,0,0),…,R(t,0,0),…,R(,0,0)
t[0,1]
y
z-yaw
π
z
x
z
R(0,0,0),…,R(0,t, t),…,R(0,, )
51
Euler Angles Interpolation
Unnatural movement !
52
26
Representing Rotation
• Rotation matrix
• Euler angle
• Axis angle
• Quaternion
• Exponential map
53
Axis angle
• Represent orientation as a vector and a
scalar
-
vector is the axis to rotate about
scalar is the angle to rotate by
54
27
Angle and Axis
• Any orientation can be represented by a 4-tuple
- angle, vector(x,y,z) where the angle is the amount to rotate
by and the vector is the axis to rotate about
• Can interpolate the angle and axis separately
• No gimbal lock problems!
• But, can’t efficiently compose rotations…must
convert to matrices first!
55
Representing Rotation
• Rotation matrix
• Euler angle
• Axis angle
• Quaternion
• Exponential map
56
28
Quaternions
•Extension of imaginary numbers
•Requires one real and three imaginary
components i, j, k
q=q0+q1i+q2j+q3k


57
Quaternions
•Extension of imaginary numbers
•Requires one real and three imaginary
components i, j, k
q = (w, x, y, z)

= cos +
2
 sin 
2


x, y, z ] of axis
58
29
Quaternion interpolation
•Quaternions can express rotations on unit sphere
smoothly and efficiently.
1-angle rotation can be
represented by a unit circle
2-angle rotation can be
represented by a unit sphere
• Interpolation means moving on n-D sphere
• Now imagine a 4-D sphere for 3-angle rotation
Quaternion interpolation
• Moving between two points on the 4D unit
sphere
- a unit quaternion at each step - another point on
the 4D unit sphere
- move along the great circle between the two
points on the 4D unit sphere as an arc
60
30
Quaternion interpolation
Spherical linear interpolation (SLERP)

Process:
-Rotation matrix  quaternion
-Carry out slerp/operations with quaternions
-Quaternion  rotation matrix
61
Matrix form
62
31
Summary
Quaternions – points on a 4D unit hypersphere
+ better interpolation
+ almost unique
- less intuitive
63
Quaternion Math
Unit quaternion
Multiplication
64
32
Quaternion Rotation
If
then
is a unit quaternion and
results in
rotating about
by
proof: see Quaternions by Shoemaker
65
Choose a representation
• Choose the best representation for the
task
- input: Euler angles
- joint limits: Euler angles, quaternion (harder)
- interpolation: quaternion or exponential map
- compositing: quaternions or orientation matrix
- rendering: orientation matrix ( quaternion can be
represented as matrix as well)
66
33