Transformations
MIT EECS 6.837, Durand and Cutler
Outline • • • • • •
Assignment 0 Recap Intro to Transformations Classes of Transformations Representing Transformations Combining Transformations Change of Orthonormal Basis
MIT EECS 6.837, Durand and Cutler
Cool Results from Assignment 0 (Image removed due to copyright considerations.)
emmav
psoto (Courtesy of Paul Soto. Used with permission.)
(Courtesy of Emily Vincent. Used with permission.)
(Image removed due to copyright considerations.)
scyudits MIT EECS 6.837, Durand and Cutler
(Courtesy of Sophia Yuditskaya. Used with permission.)
Notes on Assignments • Make sure you turn in a linux or windows executable (so we can test your program) • Collaboration Policy – Share ideas, not code
• Tell us how much time you spent on each assignment
MIT EECS 6.837, Durand and Cutler
Quick Review of Last Week • Ray representation • Generating rays from eyepoint / camera – orthographic camera – perspective camera
• Find intersection point & surface normal • Primitives: – spheres, planes, polygons, triangles, boxes
MIT EECS 6.837, Durand and Cutler
Outline • • • • • •
Assignment 0 Recap Intro to Transformations Classes of Transformations Representing Transformations Combining Transformations Change of Orthonormal Basis
MIT EECS 6.837, Durand and Cutler
What is a Transformation? • Maps points (x, y) in one coordinate system to points (x', y') in another coordinate system x' = ax + by + c y' = dx + ey + f • For example, IFS:
MIT EECS 6.837, Durand and Cutler
Common Coordinate Systems • Object space – local to each object
FAR
y
• World space
NEAR
– common to all objects
x
o
z
EYE
• Eye space / Camera space
y
– derived from view frustum
x z
• Screen space – indexed according to hardware attributes ((Courtesy
of Seth Teller. Used with permission.) MIT EECS 6.837, Durand and Cutler
x
z
NDC
y
o
Simple Transformations
• Can be combined • Are these operations invertible? Yes, except scale = 0 MIT EECS 6.837, Durand and Cutler
Transformations are used: • • • • •
Position objects in a scene (modeling) Change the shape of objects Create multiple copies of objects Projection for virtual cameras Animations
MIT EECS 6.837, Durand and Cutler
Outline • Assignment 0 Recap • Intro to Transformations • Classes of Transformations • • • • •
Rigid Body / Euclidean Transforms Similitudes / Similarity Transforms Linear Affine Projective
• Representing Transformations • Combining Transformations • Change of Orthonormal Basis MIT EECS 6.837, Durand and Cutler
Rigid-Body / Euclidean Transforms • Preserves distances • Preserves angles
Rigid / Euclidean Translation
Identity Rotation
MIT EECS 6.837, Durand and Cutler
Similitudes / Similarity Transforms • Preserves angles
Similitudes Rigid / Euclidean Translation
Identity Rotation
Isotropic Scaling
MIT EECS 6.837, Durand and Cutler
Linear Transformations
Similitudes Linear Rigid / Euclidean Translation
Identity Rotation
Scaling Isotropic Scaling
MIT EECS 6.837, Durand and Cutler
Reflection Shear
Linear Transformations • L(p + q) = L(p) + L(q) • L(ap) = a L(p) Similitudes Linear Rigid / Euclidean Translation
Identity Rotation
Scaling Isotropic Scaling
MIT EECS 6.837, Durand and Cutler
Reflection Shear
Affine Transformations • preserves parallel lines Affine Similitudes Linear Rigid / Euclidean Translation
Identity Rotation
Scaling Isotropic Scaling
MIT EECS 6.837, Durand and Cutler
Reflection Shear
Projective Transformations • preserves lines Projective Affine Similitudes Linear Rigid / Euclidean Translation
Identity Rotation
Scaling Isotropic Scaling
Perspective
MIT EECS 6.837, Durand and Cutler
Reflection Shear
Perspective Projection
MIT EECS 6.837, Durand and Cutler
Outline • • • • • •
Assignment 0 Recap Intro to Transformations Classes of Transformations Representing Transformations Combining Transformations Change of Orthonormal Basis
MIT EECS 6.837, Durand and Cutler
How are Transforms Represented? x' = ax + by + c y' = dx + ey + f x' = y'
p' =
a d
b e
c x + f y
Mp + t
MIT EECS 6.837, Durand and Cutler
Homogeneous Coordinates • Add an extra dimension • in 2D, we use 3 x 3 matrices • In 3D, we use 4 x 4 matrices
• Each point has an extra value, w d h l p
a b x' e f y' = i j z' m n w'
c g k o
p' =
Mp MIT EECS 6.837, Durand and Cutler
x y z w
Homogeneous Coordinates • Most of the time w = 1, and we can ignore it x' y' z' 1
=
a e i 0
b f j 0
c g k 0
d h l 1
x y z 1
• If we multiply a homogeneous coordinate by an affine matrix, w is unchanged MIT EECS 6.837, Durand and Cutler
Homogeneous Visualization • Divide by w to normalize (homogenize) • W = 0? Point at infinity (direction)
(0, 0, 1) = (0, 0, 2) = … w = 1 (7, 1, 1) = (14, 2, 2) = … (4, 5, 1) = (8, 10, 2) = …
w=2
MIT EECS 6.837, Durand and Cutler
Translate (tx, ty, tz)
Translate(c,0,0) y
• Why bother with the extra dimension? Because now translations can be encoded in the matrix!
x' y' z' 10
=
1 0 0 0
p'
p
0 1 0 0
0 0 1 0
c
tx ty tz 1
MIT EECS 6.837, Durand and Cutler
x y z 1
x
Scale (sx, sy, sz)
Scale(s,s,s) p'
y
• Isotropic (uniform) scaling: sx = sy = sz
p q' q x
x' y' z' 1
sx 0 = 0 0
0 sy 0 0
0 0 sz 0
0 0 0 1
MIT EECS 6.837, Durand and Cutler
x y z 1
Rotation
ZRotate(θ) y p'
• About z axis
θ
p x
z
x' y' z' 1
=
cos θ -sin θ sin θ cos θ 0 0 0 0
0 0 1 0
MIT EECS 6.837, Durand and Cutler
0 0 0 1
x y z 1
Rotation • About x axis:
x' y' z' 1
• About y axis:
x' y' z' 1
=
0 0 1 0 cos θ -sin θ 0 sin θ cos θ 0 0 0
0 0 0 1
x y z 1
=
cos θ 0 -sin θ 0
0 1 1 0
0 0 0 1
x y z 1
MIT EECS 6.837, Durand and Cutler
sin θ 0 cos θ 0
Rotation
y
• About (kx, ky, kz), a unit vector on an arbitrary axis (Rodrigues Formula)
Rotate(k, θ) θ k
z
kxkx(1-c)+c kzkx(1-c)-kzs kxkz(1-c)+kys x' kykx(1-c)+kzs kzkx(1-c)+c kykz(1-c)-kxs y' = kzkx(1-c)-kys kzkx(1-c)-kxs kzkz(1-c)+c z' 0 0 0 1 where c = cos θ & s = sin θ MIT EECS 6.837, Durand and Cutler
x
0 0 0 1
x y z 1
Outline • • • • • •
Assignment 0 Recap Intro to Transformations Classes of Transformations Representing Transformations Combining Transformations Change of Orthonormal Basis
MIT EECS 6.837, Durand and Cutler
How are transforms combined? Scale then Translate (1,1)
(2,2)
Scale(2,2)
Translate(3,1)
(5,3) (3,1)
(0,0)
(0,0)
Use matrix multiplication: p' = T ( S p ) = TS p TS =
1 0 3 0 1 1 0 0 1
2 0 0 0 2 0 0 0 1
=
2 0 3 0 2 1 0 0 1
Caution: matrix multiplication is NOT commutative! MIT EECS 6.837, Durand and Cutler
Non-commutative Composition Scale then Translate: p' = T ( S p ) = TS p (1,1)
(2,2)
Scale(2,2)
Translate(3,1)
(5,3) (3,1)
(0,0)
(0,0)
Translate then Scale: p' = S ( T p ) = ST p (8,4) (1,1)
Translate(3,1)
(4,2) (3,1)
Scale(2,2)
(0,0)
MIT EECS 6.837, Durand and Cutler
(6,2)
Non-commutative Composition Scale then Translate: p' = T ( S p ) = TS p TS =
1 0 3 0 1 1 0 0 1
2 0 0 0 2 0 0 0 1
=
2 0 3 0 2 1 0 0 1
Translate then Scale: p' = S ( T p ) = ST p ST =
2 0 0 0 2 0 0 0 1
1 0 3 0 1 1 0 0 1
MIT EECS 6.837, Durand and Cutler
=
2 0 6 0 2 2 0 0 1
Outline • • • • • •
Assignment 0 Recap Intro to Transformations Classes of Transformations Representing Transformations Combining Transformations Change of Orthonormal Basis
MIT EECS 6.837, Durand and Cutler
Review of Dot Product b
a
MIT EECS 6.837, Durand and Cutler
Change of Orthonormal Basis • Given:
y
coordinate frames xyz and uvn point p = (x,y,z)
• Find:
v
x p u
v u y x
y v p
p = (u,v,n) n z MIT EECS 6.837, Durand and Cutler
u x
Change of Orthonormal Basis v y.u
y
y v y.v
u
u x.v x
x
n
x.u z
x y z
= (x . u) u + (x . v) v + = (y . u) u + (y . v) v + = (z . u) u + (z . v) v + MIT EECS 6.837, Durand and Cutler
(x . n) n (y . n) n (z . n) n
Change of Orthonormal Basis x y z
= (x . u) u + (x . v) v + = (y . u) u + (y . v) v + = (z . u) u + (z . v) v +
(x . n) n (y . n) n (z . n) n
Substitute into equation for p: p = (x,y,z) = x x + y y + z z p = x [ (x . u) u + (x . v) v + y [ (y . u) u + (y . v) v + z [ (z . u) u + (z . v) v + MIT EECS 6.837, Durand and Cutler
(x . n) n ] + (y . n) n ] + (z . n) n ]
Change of Orthonormal Basis p = x [ (x . u) u + (x . v) v + y [ (y . u) u + (y . v) v + z [ (z . u) u + (z . v) v +
(x . n) n ] + (y . n) n ] + (z . n) n ]
Rewrite: p = [ x (x . u) + y (y . u) + [ x (x . v) + y (y . v) + [ x (x . n) + y (y . n) + MIT EECS 6.837, Durand and Cutler
z (z . u) ] u + z (z . v) ] v + z (z . n) ] n
Change of Orthonormal Basis p = [ x (x . u) + y (y . u) + [ x (x . v) + y (y . v) + [ x (x . n) + y (y . n) +
z (z . u) ] u + z (z . v) ] v + z (z . n) ] n
p = (u,v,n) = u u + v v + n n Expressed in uvn basis: u = x (x . u) + y (y . u) + v = x (x . v) + y (y . v) + n = x (x . n) + y (y . n) + MIT EECS 6.837, Durand and Cutler
z (z . u) z (z . v) z (z . n)
Change of Orthonormal Basis u = x (x . u) + y (y . u) + v = x (x . v) + y (y . v) + n = x (x . n) + y (y . n) +
z (z . u) z (z . v) z (z . n)
In matrix form: u v n
ux uy uz = vx vy vz nx ny nz
x y z
MIT EECS 6.837, Durand and Cutler
where: ux = x . u uy = y . u etc.
Change of Orthonormal Basis u v n
ux uy uz = vx vy vz nx ny nz
x y z
=
M
x y z
What's M-1, the inverse? xu xv xn x y = yu yv yn zu zv zn z
u v n
ux = x . u = u . x = xu
MIT EECS 6.837, Durand and Cutler
M-1 = MT
Next Time:
Adding Transformations to the Ray Caster (Assignment 2)
MIT EECS 6.837, Durand and Cutler