Sie sind auf Seite 1von 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


(Image removed due to copyright considerations.)

emmav
(Courtesy of Emily Vincent. Used with permission.)

psoto
(Courtesy of Paul Soto. 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 NEAR

World space
common to all objects
z o

y x
EYE

Eye space / Camera space


derived from view frustum
x z
NDC

Screen space
indexed according to hardware attributes
((Courtesy

of Seth Teller. Used with permission.)


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
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 Reflection 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
Translation Identity Rotation Scaling Isotropic Scaling Reflection Shear

MIT EECS 6.837, Durand and Cutler

Affine Transformations
preserves parallel lines
Affine Similitudes Linear Rigid / Euclidean
Translation Identity Rotation Scaling Isotropic Scaling Reflection Shear

MIT EECS 6.837, Durand and Cutler

Projective Transformations
preserves lines
Projective Affine Similitudes Linear Rigid / Euclidean
Translation Identity Rotation Scaling Isotropic Scaling Reflection Shear

MIT EECS 6.837, Durand and Cutler

Perspective

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' a d b e c x + f y

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

p' =

Mp
MIT EECS 6.837, Durand and Cutler

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)


y

Translate(c,0,0)

Why bother with the extra dimension?


Because now translations can be encoded in the matrix!

p' x

x' y' z' 0 1

1 0 0 0

0 1 0 0

0 0 1 0

tx ty tz 1

x y z 1

MIT EECS 6.837, Durand and Cutler

Scale (sx, sy, sz)


y

Scale(s,s,s)
p' p q' q x

Isotropic (uniform) scaling: sx = sy = sz

x' y' z' 1

sx 0 = 0 0

0 sy 0 0

0 0 sz 0

0 0 0 1

x y z 1

MIT EECS 6.837, Durand and Cutler

Rotation
y

ZRotate()
p'

About z axis

p x

x' y' z' 1

cos -sin sin cos 0 0 0 0

0 0 1 0

0 0 0 1

x y z 1

MIT EECS 6.837, Durand and Cutler

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

About y axis:

MIT EECS 6.837, Durand and Cutler

Rotation
About (kx, ky, kz), a unit vector on an arbitrary axis (Rodrigues Formula)
z

Rotate(k, ) k
x

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

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

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

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


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

MIT EECS 6.837, Durand and Cutler

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

2 0 6 0 2 2 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


b

MIT EECS 6.837, Durand and Cutler

Change of Orthonormal Basis


Given:
coordinate frames xyz and uvn point p = (x,y,z)
v y x p u v u y x

Find:
p = (u,v,n)

y v p n z
MIT EECS 6.837, Durand and Cutler

u x

Change of Orthonormal Basis


v y.u y v y.v u x.v x x.u z n x u y

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 + 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

(x . n) n ] + (y . n) n ] + (z . n) n ]

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) + 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) ] u + z (z . v) ] v + z (z . n) ] n

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) + In matrix form: u v n ux uy uz = vx vy vz nx ny nz x y z
where: ux = x . u uy = y . u etc.

z (z . u) z (z . v) z (z . n)

MIT EECS 6.837, Durand and Cutler

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

M-1 = MT

MIT EECS 6.837, Durand and Cutler

Next Time:

Adding Transformations to the Ray Caster (Assignment 2)

MIT EECS 6.837, Durand and Cutler

Das könnte Ihnen auch gefallen