Foundations of Computer Graphics (Fall 2012) CS 184, Lecture 3: Transformations 1

advertisement
Foundations of Computer Graphics
(Fall 2012)
CS 184, Lecture 3: Transformations 1
http://inst.eecs.berkeley.edu/~cs184
To Do
 Submit HW 0b
 Start looking at HW 1 (simple, but need to think)
 Axis-angle rotation and gluLookAt most useful
 Probably only need final results, but try understanding
derivations.
 Problems in text help understanding material. Usually, we
have review sessions per unit, but this one before midterm
Course Outline
 3D Graphics Pipeline
Modeling
Animation
Rendering
Course Outline
 3D Graphics Pipeline
Modeling
Animation
Unit 1: Transformations
Resizing and placing objects in the
world. Creating perspective images.
Weeks 1 and 2
Ass 1 due Sep 12 (DEMO)
Rendering
Motivation
 Many different coordinate systems in graphics
 World, model, body, arms, …
 To relate them, we must transform between them
 Also, for modeling objects. I have a teapot, but
 Want to place it at correct location in the world
 Want to view it from different angles (HW 1)
 Want to scale it to make it bigger or smaller
 Demo of HW 1
Goals
 This unit is about the math for these transformations
 Represent transformations using matrices and matrixvector multiplications.
 Demos throughout lecture: HW 1 and Applet
 Transformations Game Applet
 Brown University Exploratories of Software
 http://www.cs.brown.edu/exploratories/home.html
 Credit: Andries Van Dam and Jean Laleuf
General Idea
 Object in model coordinates
 Transform into world coordinates
 Represent points on object as vectors
 Multiply by matrices
 Demos with applet
Outline
 2D transformations: rotation, scale, shear
 Composing transforms
 3D rotations
 Translation: Homogeneous Coordinates (next time)
 Transforming Normals (next time)
(Nonuniform) Scale
æ s
x
Scale(sx ,sy ) = ç
çè 0
æ s
x
ç
ç 0
ç
çè 0
0
sy
0
0 ö
÷
sy ÷ø
0 öæ x
֍
0 ֍ y
֍ z
sz ÷ø è
æ s -1 0
x
-1
ç
S =
ç 0 sy-1
è
ö æ sx x
ç
÷
=
s
y
ç
y
÷
÷ø ç
çè sz z
transformation_game.jar
ö
÷
÷
÷
÷ø
ö
÷
÷
ø
Shear
æ 1 a ö
Shear = ç
÷
è 0 1 ø
æ
ö
1
-a
-1
S =ç
÷
è 0 1 ø
Rotations
2D simple, 3D complicated. [Derivation? Examples?]
2D?
é x ' ù é cos q
ê
ú=ê
êë y ' úû êë sin q
 Linear
- sin q ù é x
úê
cos q úû êë y
R(X+Y)=R(X)+R(Y)
 Commutative
transformation_game.jar
ù
ú
úû
Outline
 2D transformations: rotation, scale, shear
 Composing transforms
 3D rotations
 Translation: Homogeneous Coordinates
 Transforming Normals
Composing Transforms
 Often want to combine transforms
 E.g. first scale by 2, then rotate by 45 degrees
 Advantage of matrix formulation: All still a matrix
 Not commutative!! Order matters
E.g. Composing rotations, scales
x3 = Rx2
x2 = Sx1
x3 = R(Sx1) = (RS)x1
x3 ¹ SRx1
transformation_game.jar
Inverting Composite Transforms
 Say I want to invert a combination of 3 transforms
 Option 1: Find composite matrix, invert
 Option 2: Invert each transform and swap order
 Obvious from properties of matrices
= M1M2M3
M
M
-1
-1
-1
3
-1
2
-1
1
=M M M
-1
3
-1
2
-1
1
M M = M (M (M M1)M2 )M3
transformation_game.jar
Outline
 2D transformations: rotation, scale, shear
 Composing transforms
 3D rotations
 Translation: Homogeneous Coordinates
 Transforming Normals
Rotations
Review of 2D case
é x ' ù é cos q
ê
ú=ê
y
'
êë
úû êë sin q
 Orthogonal?,
ù
- sin q é x ù
úê
ú
cos q úû êë y úû
R R=I
T
Rotations in 3D
 Rotations about coordinate axes simple
æ cosq
ç
Rz = ç sinq
çè 0
æ cosq
ç
Ry = ç
0
çè - sinq
0
0
1
ö
÷
÷
÷ø
0 sinq
1
0
0 cosq
ö
÷
÷
÷ø
- sinq
cosq
0
 Always linear, orthogonal
 Rows/cols orthonormal
æ 1
0
ç
Rx = ç 0 cosq
çè 0 sinq
0
- sinq
cos q
R R=I
T
R(X+Y)=R(X)+R(Y)
ö
÷
÷
÷ø
Geometric Interpretation 3D Rotations
 Rows of matrix are 3 unit vectors of new coord frame
 Can construct rotation matrix from 3 orthonormal vectors
æ x y
zu ö
u
u
ç
÷
Ruvw = ç xv y v zv ÷ u = xu X + y uY + zu Z
ç
÷
çè xw y w zw ÷ø
æ x
ç u
Rp = ç xv
ç
çè xw
yu
yv
yw
æ u·p ö
zu ö æ xp ö
÷
֍
ç
÷
zv ÷ ç y p ÷ = ? ç v · p ÷
÷
֍
ç w·p ÷
zw ÷ø ç zp ÷
è
ø
è
ø
Geometric Interpretation 3D Rotations
æ x
ç u
Rp = ç xv
ç
çè xw
yu
yv
yw
zu ö æ xp ö æ u · p
÷ ç
֍
zv ÷ ç y p ÷ = ç v · p
÷ ç
֍
zw ÷ø ç zp ÷ è w · p
è
ø
ö
÷
÷
÷
ø
 Rows of matrix are 3 unit vectors of new coord frame
 Can construct rotation matrix from 3 orthonormal vectors
 Effectively, projections of point into new coord frame
 New coord frame uvw taken to cartesian components xyz
 Inverse or transpose takes xyz cartesian to uvw
Non-Commutativity
 Not Commutative (unlike in 2D)!!
 Rotate by x, then y is not same as y then x
 Order of applying rotations does matter
 Follows from matrix multiplication not commutative
 R1 * R2 is not the same as R2 * R1
 Demo: HW1, order of right or up will matter
Arbitrary rotation formula
 Rotate by an angle θ about arbitrary axis a
 Homework 1: must rotate eye, up direction
 Somewhat mathematical derivation but useful formula
 Problem setup: Rotate vector b by θ about a
 Helpful to relate b to X, a to Z, verify does right thing
 For HW1, you probably just need final formula
Axis-Angle formula
 Step 1: b has components parallel to a, perpendicular
 Parallel component unchanged (rotating about an axis
leaves that axis unchanged after rotation, e.g. rot about z)
 Step 2: Define c orthogonal to both a and b
 Analogous to defining Y axis
 Use cross products and matrix formula for that
 Step 3: With respect to the perpendicular comp of b




Cos θ of it remains unchanged
Sin θ of it projects onto vector c
Verify this is correct for rotating X about Z
Verify this is correct for θ as 0, 90 degrees
Axis-Angle: Putting it together
(b \ a)ROT = (I3´3 cosq - aaT cosq )b + (A* sinq )b
(b ® a)ROT = (aa )b
T
R(a,q ) = I3´3 cosq + aa (1- cosq ) + A sinq
T
*
Unchanged Component Perpendicular
(cosine)
along a
(rotated comp)
(hence unchanged)
Axis-Angle: Putting it together
(b \ a)ROT = (I3´3 cosq - aaT cosq )b + (A* sinq )b
(b ® a)ROT = (aa )b
T
R(a,q ) = I3´3 cosq + aa (1- cosq ) + A sinq
T
æ 1 0 0
ç
R(a,q ) = cosq ç 0 1 0
è 0 0 1
æ x2
ö
ç
÷
÷ + (1- cosq ) ç xy
ç
ø
è xz
*
xy
y2
yz
æ 0
xz ö
÷
ç
yz ÷ + sinq ç z
÷
çè -y
z2 ø
-z
0
x
y ö
÷
-x ÷
0 ÷ø
(x y z) are cartesian components of a
Download