Transformations: MIT EECS 6.837, Durand and Cutler

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 42

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

emmav alexg psoto

koi scyudits
MIT EECS 6.837, Durand and Cutler
Notes on Assignments
• Make sure you turn in a linux or windows
executable (so we can test your program)
• Don't use athena dialup
• Collaboration Policy
– Share ideas, not code
• Ask questions during office hours, or email
6.837-staff@graphics.csail.mit.edu
• 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
• World space
– common to all objects
• Eye space / Camera space
– derived from view frustum
• Screen space
– indexed according
to hardware attributes

MIT EECS 6.837, Durand and Cutler


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

Identity
Translation
Rotation

MIT EECS 6.837, Durand and Cutler


Similitudes / Similarity Transforms

• Preserves angles

Similitudes
Rigid / Euclidean

Identity
Translation Isotropic Scaling
Rotation

MIT EECS 6.837, Durand and Cutler


Linear Transformations

Similitudes
Linear
Rigid / Euclidean
Scaling
Identity
Translation Isotropic Scaling Reflection
Rotation
Shear

MIT EECS 6.837, Durand and Cutler


Linear Transformations
• L(p + q) = L(p) + L(q)
• L(ap) = a L(p)

Similitudes
Linear
Rigid / Euclidean
Scaling
Identity
Translation Isotropic Scaling Reflection
Rotation
Shear

MIT EECS 6.837, Durand and Cutler


Affine Transformations
• preserves
parallel lines
Affine

Similitudes
Linear
Rigid / Euclidean
Scaling
Identity
Translation Isotropic Scaling Reflection
Rotation
Shear

MIT EECS 6.837, Durand and Cutler


Projective Transformations
• preserves lines
Projective
Affine

Similitudes
Linear
Rigid / Euclidean
Scaling
Identity
Translation Isotropic Scaling Reflection
Rotation
Shear

Perspective
MIT EECS 6.837, Durand and Cutler
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' a b x c
= +
y' d e y f

p' = 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
x' a b c d x
y' e f g h y
=
z' i j k l z
w' m n o p w

p' = Mp
MIT EECS 6.837, Durand and Cutler
Homogeneous Coordinates
• Most of the time w = 1, and we can ignore it

x' a b c d x
y' e f g h y
=
z' i j k l z
1 0 0 0 1 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? p p'
Because now translations
x
can be encoded in the matrix! c

x' 1 0 0 tx x
y' 0 1 0 ty y
=
z' 0 0 1 tz z
10 0 0 0 1 1

MIT EECS 6.837, Durand and Cutler


Scale (sx, sy, sz) Scale(s,s,s)
y p'

• Isotropic (uniform)
p
scaling: sx = sy = sz q'
q
x

x' sx 0 0 0 x
y' 0 sy 0 0 y
=
z' 0 0 sz 0 z
1 0 0 0 1 1

MIT EECS 6.837, Durand and Cutler


Rotation ZRotate(θ)
y
p'
• About z axis
θ p

x
z

x' cos θ -sin θ 0 0 x


y' sin θ cos θ 0 0 y
=
z' 0 0 1 0 z
1 0 0 0 1 1

MIT EECS 6.837, Durand and Cutler


Rotation
x' 1 0 0 0 x
• About y' 0 cos θ -sin θ 0 y
x axis: =
z' 0 sin θ cos θ 0 z
1 0 0 0 1 1

x' cos θ 0 sin θ 0 x


• About y' 0 1 0 0 y
=
y axis: z' -sin θ 1 cos θ 0 z
1 0 0 0 1 1
MIT EECS 6.837, Durand and Cutler
Rotation y
Rotate(k, θ)

• About (kx, ky, kz), a unit θ


vector on an arbitrary axis k
(Rodrigues Formula) x
z

x' kxkx(1-c)+c kzkx(1-c)-kzs kxkz(1-c)+kys 0 x


y' kykx(1-c)+kzs kzkx(1-c)+c kykz(1-c)-kxs 0 y
=
z' kzkx(1-c)-kys kzkx(1-c)-kxs kzkz(1-c)+c 0 z
1 0 0 0 1 1

where c = cos θ & s = sin θ


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 combined?
Scale then Translate
(5,3)
Scale(2,2) (2,2) Translate(3,1)
(1,1) (3,1)
(0,0) (0,0)

Use matrix multiplication: p' = T ( S p ) = TS p


1 0 3 2 0 0 2 0 3
TS = 0 1 1 0 2 0 = 0 2 1
0 0 1 0 0 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
(5,3)
Scale(2,2) (2,2) Translate(3,1)
(1,1) (3,1)
(0,0) (0,0)

Translate then Scale: p' = S ( T p ) = ST p


(8,4)
Translate(3,1) (4,2) Scale(2,2)
(1,1) (6,2)
(3,1)
(0,0)

MIT EECS 6.837, Durand and Cutler


Non-commutative Composition
Scale then Translate: p' = T ( S p ) = TS p
1 0 3 2 0 0 2 0 3
TS = 0 1 1 0 2 0 = 0 2 1
0 0 1 0 0 1 0 0 1

Translate then Scale: p' = S ( T p ) = ST p


2 0 0 1 0 3 2 0 6
ST = 0 2 0 0 1 1 = 0 2 2
0 0 1 0 0 1 0 0 1

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


Review of Dot Product

MIT EECS 6.837, Durand and Cutler


Change of Orthonormal Basis
• Given: y
v x p
coordinate frames u
v
u
xyz and uvn y
point p = (x,y,z) x

y
• Find: v
p u
p = (u,v,n)
n x
z

MIT EECS 6.837, Durand and Cutler


Change of Orthonormal Basis
y y
v y.u v
y.v
u u
x.v
x n x

x.u
z

x = (x . u) u + (x . v) v + (x . n) n
y = (y . u) u + (y . v) v + (y . n) n
z = (z . u) u + (z . v) v + (z . n) n

MIT EECS 6.837, Durand and Cutler


Change of Orthonormal Basis
x = (x . u) u + (x . v) v + (x . n) n
y = (y . u) u + (y . v) v + (y . n) n
z = (z . u) u + (z . v) v + (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 + (x . n) n ] +
y [ (y . u) u + (y . v) v + (y . n) n ] +
z [ (z . u) u + (z . v) v + (z . n) n ]

MIT EECS 6.837, Durand and Cutler


Change of Orthonormal Basis

p = x [ (x . u) u + (x . v) v + (x . n) n ] +
y [ (y . u) u + (y . v) v + (y . n) n ] +
z [ (z . u) u + (z . v) v + (z . n) n ]

Rewrite:
p = [ x (x . u) + y (y . u) + z (z . u) ] u +
[ x (x . v) + y (y . v) + z (z . v) ] v +
[ x (x . n) + y (y . n) + z (z . n) ] n

MIT EECS 6.837, Durand and Cutler


Change of Orthonormal Basis
p = [ x (x . u) + y (y . u) + z (z . u) ] u +
[ x (x . v) + y (y . v) + z (z . v) ] v +
[ x (x . n) + y (y . n) + 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) + z (z . u)
v = x (x . v) + y (y . v) + z (z . v)
n = x (x . n) + y (y . n) + z (z . n)

MIT EECS 6.837, Durand and Cutler


Change of Orthonormal Basis

u = x (x . u) + y (y . u) + z (z . u)
v = x (x . v) + y (y . v) + z (z . v)
n = x (x . n) + y (y . n) + z (z . n)

In matrix form:
where:
u ux uy uz x ux = x . u
v = vx vy vz y uy = y . u
n nx ny nz z etc.

MIT EECS 6.837, Durand and Cutler


Change of Orthonormal Basis
u ux uy uz x x
v = vx vy vz y = M y
n nx ny nz z z

What's M-1, the inverse?

x xu x v xn u u x = x . u = u . x = xu
y = yu y v yn v
z zu zv zn n
M = M
-1 T

MIT EECS 6.837, Durand and Cutler


Next Time:

Adding Transformations
to the Ray Caster
(Assignment 2)

MIT EECS 6.837, Durand and Cutler

You might also like