Title: Transformations
1Transformations Homogeneous Coordinates
6.837 Introduction to Computer Graphics Fredo
Durand, MIT EECS
2Administrivia
- Linear algebra review tomorrow Wednesday at 730
in 32-D507 - You should be well started with assignment 1
(due next week)
3Eugene has setup a remote Athena
- Hi all, I've recently set up an Athena Linux
machine for remote logins (so you folks can work
at home). Before I continue though, let me just
say that this is not an officially supported
solution (which is why I'm sending it to
6837-discuss rather than 6837-students, because
6837-students is reserved for official
announcements). This means Use the machine
at your own risk. If you're working on it, and
it happens to crash two hours before the
assignment, it's not an excuse for lateness.
The official course staff answer to any setup
questions will be we encourage you to work in a
cluster, since we don't have the resources to
offer technical support on personal machines.
With that stated, the machine is (drumroll)
eraser.csail.mit.edu I've only enabled login
access to all people that currently have turnin
directories. And here are basic usage
instructions LINUX If you have a Linux
machine at home, you should be able to ssh -X
into the machine and run applications remotely.
I've tried this on several Linux machines, and it
only worked on some of them, and that's all I can
say about that. WINDOWS MIT has XWin32
available from their software distrubtion page
(http//web.mit.edu/software/). You can use this
to connect to eraser remotely and run
applications. Note that you need to disable
"Advanced Window Caching" in the configuration
(otherwise, OpenGL windows will pop up blank).
MAC In theory, OS X allows you to run X
applications remotely, but I've never tried it.
See the following http//www.apple.com/downloads/
macosx/apple/x11formacosx.html Good luck.
Eugene
4Assignment 0
- Fixed size array
- Kind of dirty, but OK for asst0
- But make sure they are big enough!!!!
- Now you should use vectors (variable-size array)
- putting glBegin(GL_TRIANGLES)/glEnd() inside of
the loop instead of outside is not optimal
slower drawing...
5Pinhole Camera
6Synthetic Camera
7Modeling Problem
- Write an OpenGL procedure that draws a 2D
rectangle with one corner at (lox, loy) and
another at (hix, hiy).
8Solution
drawBox(lox, loy, hix, hiy) glBegin(GL_QUADS)
glVertex2f(lox, loy) glVertex2f(hix,
loy) glVertex2f(hix, hiy) glVertex2f(lox,
hiy) glEnd()
9Another Solution
- Assume drawUnitBox() procedure draws a unit box
- This is a solution you should use in almost all
graphics application speed, modularity,
flexibility,
drawBox(lox, loy, hix, hiy) glTranslate(lox,
loy) glScale(hix-lox, hiy-loy) drawUnitBox()
10Another Example
- Write an OpenGL procedure that draws an ellipse
assuming drawUnitCircle() draws a unit-circle
centered at the origin.
drawEllipse(cx, cy, rx, ry) glTranslate(cx,
cy) glScale(rx, ry) drawUnitCircle()
11Geometry Pipeline Modeling
12Geometry Pipeline Viewing
13OpenGL Example Modeling
// Current matrix affects objects
positions glMatrixMode( GL_MODELVIEW ) //
Initialize to the identity glLoadIdentity()
// Position the camera at 0,0,5,
looking at // 0,0,0, with 0,1,0 as the up
direction. gluLookAt(0.0, 0.0, 5.0,
0.0, 0.0, 0.0, 0.0, 1.0, 0.0) //
Rotate by -20 degrees about 0,1,0 glRotated(-20.
0, 0.0, 1.0, 0.0) // Draw a
teapot. glutSolidTeapot(1.0)
14OpenGL Example Viewing
// Set up a perspective view, // with square
aspect ratio glMatrixMode(GL_PROJECTION) glLoadId
entity() // perspective camera // field of
view, aspect ratio, gluPerspective(50.0, 1.0,
1.0, 100.0)
15Questions?
16Outline
- Intro to Transformations
- Classes of Transformations
- Representing Transformations
- Combining Transformations
- Fun Iterated Function Systems
- Hardcore transforming normals
17What is a Transformation?
- A function that maps points x to points x'
- Applications animation, deformation, viewing,
projection, real-time shadows,
From Sederberg and Parry, Siggraph 1986
18Simple Transformations
- Can be combined
- Are these operations invertible?
Yes, except scale 0
19Outline
- Intro to Transformations
- Classes of Transformations
- Representing Transformations
- Combining Transformations
- Transformations in Modeling
20Rigid-Body / Euclidean Transforms
- Preserves distances
- Preserves angles
Rigid / Euclidean
Identity
Translation
Rotation
21Similitudes / Similarity Transforms
Similitudes
Rigid / Euclidean
Identity
Translation
Isotropic Scaling
Rotation
22Linear Transformations
Similitudes
Linear
Rigid / Euclidean
Scaling
Identity
Translation
Isotropic Scaling
Reflection
Rotation
Shear
23Linear 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
Translation is not linear because apt ? a(pt)
24Affine Transformations
Affine
Similitudes
Linear
Rigid / Euclidean
Scaling
Identity
Translation
Isotropic Scaling
Reflection
Rotation
Shear
25Projective Transformations
Projective
Affine
Similitudes
Linear
Rigid / Euclidean
Scaling
Identity
Translation
Isotropic Scaling
Reflection
Rotation
Shear
Perspective
26Physical 3D perspective
- In Rome
- Walls recede
- Makes it look longer
Side view
Borromini
27Groups
- Properties of a group (element, operation)
- There exists a neutral element
- There exists an inverse for each member
- The elements are "closed under composition"
- The composition operation is associative
- Example integers under addition
- 0 is the neutral element
- -x is the inverse of x
- xy is an integer
- (xy)zx(yz)
28Groups and Transformations
- Properties of a group
- There exists an identity mapping
- There exists an inverse mapping for each function
- The functions are "closed under composition"
- The composition operation is associative
- These properties might seem trivial at first
glance, but they are actually very important,
because when these conditions are shown for any
class of functions and their two-argument
composition operation, then they form an
algebraic group. One of the consequences is that
any series of translations can be composed to a
single translation. Another consequence is that
the inverse is unique.
29Questions?
30Visual tribute to Darcy Thompson
- The first biomathematician
- Transformation evolution
- http//www-gap.dcs.stand.ac.uk/history/Miscellane
ous/darcy.html
31Outline
- Intro to Transformations
- Classes of Transformations
- Representing Transformations
- Combining Transformations
- Fun Iterated Function Systems
- Hardcore transforming normals
32How are Transforms Represented?
x' ax by c y' dx ey f
c f
x y
x' y'
a b d e
p' M p t
33Translation in homogenous coordinates
x' ax by c y' dx ey f
Affine formulation
Homogeneous formulation
c f 1
x y 1
x' y 1
a b d e 0 0
c f
x y
x' y'
a b d e
p' M p t
p' M p
34Homogeneous 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 y z w
a e i m
b f j n
c g k o
d h l p
x' y' z' w'
p' M p
35Homogeneous Coordinates
- Most of the time w 1, and we can ignore it
- If we multiply a homogeneous coordinate by an
affine matrix, w is unchanged
x y z 1
a e i 0
b f j 0
c g k 0
d h l 1
x' y' z' 1
36Homogeneous 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)
w 2
(4, 5, 1) (8, 10, 2)
37Questions?
38Translate (tx, ty, tz)
Translate(c,0,0)
y
- Why bother with the extra dimension?Because now
translations can be encoded in the matrix!
p'
p
x
c
x y z 1
1 0 0 0
0 1 0 0
0 0 1 0
tx ty tz 1
x' y' z' 1
x' y' z'
39Scale (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
x' y' z' 1
40Rotation
ZRotate(?)
y
p'
?
p
x
z
x y z 1
cos ? sin ? 0 0
-sin ? cos ? 0 0
0 0 1 0
0 0 0 1
x' y' z' 1
41Rotation
Rotate(k, ?)
y
?
- About (kx, ky, kz), a unit vector on an
arbitrary axis(Rodrigues Formula)
k
x
z
kxkx(1-c)c kykx(1-c)kzs kzkx(1-c)-kys 0
kzkx(1-c)-kzs kzkx(1-c)c kzkx(1-c)-kxs 0
kxkz(1-c)kys kykz(1-c)-kxs kzkz(1-c)c 0
x' y' z' 1
x y z 1
0 0 0 1
where c cos ? s sin ?
42Questions?
43Outline
- Intro to Transformations
- Classes of Transformations
- Representing Transformations
- Combining Transformations
- Fun Iterated Function Systems
- Hardcore transforming normals
44How are transforms combined?
Scale then Translate
(5,3)
(2,2)
Scale(2,2)
Translate(3,1)
(1,1)
(3,1)
(0,0)
(0,0)
Use matrix multiplication p' T ( S p )
TS p
0 2
0 1
0 2
2 0
0 0
1 0
3 1
2 0
3 1
TS
Caution matrix multiplication is NOT commutative!
45Non-commutative Composition
Scale then Translate p' T ( S p ) TS p
(5,3)
(2,2)
Scale(2,2)
Translate(3,1)
(1,1)
(3,1)
(0,0)
(0,0)
Translate then Scale p' S ( T p ) ST p
(8,4)
(4,2)
Translate(3,1)
Scale(2,2)
(6,2)
(1,1)
(3,1)
(0,0)
46Non-commutative Composition
Scale then Translate p' T ( S p ) TS p
0 2 0
0 1 0
0 2 0
2 0 0
0 0 1
1 0 0
3 1 1
2 0 0
3 1 1
TS
Translate then Scale p' S ( T p ) ST p
0 2
0 1
0 2
2 0
0 0
1 0
3 1
2 0
6 2
ST
47Questions?
48Outline
- Intro to Transformations
- Classes of Transformations
- Representing Transformations
- Combining Transformations
- Fun Iterated Function Systems
- Hardcore transforming normals
49Fun Iterated Function Systems (IFS)
- Example of fractal
- Capture self similarity using set of linear
transforms fi
50Fun Iterated Function Systems (IFS)
- Contraction (reduce distances)
- An attractor is a fixed point
51Example Sierpinski Triangle
- Described by a set of n affine transformations
- In this case, n 3
- translate scale by 0.5
52Example Sierpinski Triangle
for lots of random input points (x0, y0) for
j0 to num_iters randomly pick transformation
i (xk1, yk1) fi (xk, yk) display (xk, yk)
53Example Sierpinski Triangle
for lots of random input points (x0, y0) for
j0 to num_iters randomly pick transformation
i (xk1, yk1) fi (xk, yk) display (xk, yk)
54Example Sierpinski Triangle
for lots of random input points (x0, y0) for
j0 to num_iters randomly pick transformation
i (xk1, yk1) fi (xk, yk) display (xk, yk)
55Example Sierpinski Triangle
for lots of random input points (x0, y0) for
j0 to num_iters randomly pick transformation
i (xk1, yk1) fi (xk, yk) display (xk, yk)
56Example Sierpinski Triangle
for lots of random input points (x0, y0) for
j0 to num_iters randomly pick transformation
i (xk1, yk1) fi (xk, yk) display (xk, yk)
57Example Sierpinski Triangle
for lots of random input points (x0, y0) for
j0 to num_iters randomly pick transformation
i (xk1, yk1) fi (xk, yk) display (xk, yk)
58Example Sierpinski Triangle
for lots of random input points (x0, y0) for
j0 to num_iters randomly pick transformation
i (xk1, yk1) fi (xk, yk) display (xk, yk)
59Example Sierpinski Triangle
for lots of random input points (x0, y0) for
j0 to num_iters randomly pick transformation
i (xk1, yk1) fi (xk, yk) display (xk, yk)
60Example Sierpinski Triangle
for lots of random input points (x0, y0) for
j0 to num_iters randomly pick transformation
i (xk1, yk1) fi (xk, yk) display (xk, yk)
Increasing the number of iterations
61Another IFS The Dragon
62Application Fractal Compression
- Exploit the self-similarity in an image
Compressed using Fractal Photo Lab
63Questions?
64Outline
- Intro to Transformations
- Classes of Transformations
- Representing Transformations
- Combining Transformations
- Fun Iterated Function Systems
- Hardcore transforming normals
65Normal
- Surface Normal unit vector that is locally
perpendicular to the surface
66Why is the Normal important?
- It's used for shading makes things look 3D!
object color only
Diffuse Shading
67Visualization of Surface Normal
68How do we transform normals?
nWS
nOS
World Space
Object Space
69Transform Normal like Object?
- translation?
- rotation?
- isotropic scale?
- scale?
- reflection?
- shear?
- perspective?
70Transform Normal like Object?
- translation?
- rotation?
- isotropic scale?
- scale?
- reflection?
- shear?
- perspective?
71What class of transforms?
Projective
Affine
Similitudes
Similitudes
Linear
Rigid / Euclidean
Scaling
Identity
Identity
Translation
Isotropic Scaling
Reflection
Translation
Isotropic Scaling
Reflection
Rotation
Rotation
Shear
Perspective
a.k.a. Orthogonal Transforms
72Transformation for shear and scale
Incorrect Normal Transformation
Correct Normal Transformation
73More Normal Visualizations
Incorrect Normal Transformation
Correct Normal Transformation
74So how do we do it right?
- Think about transforming the tangent plane to
the normal, not the normal vector
nOS
nWS
vWS
vOS
Original
Incorrect
Correct
Pick any vector vOS in the tangent plane, how is
it transformed by matrix M?
vWS M vOS
75Transform tangent vector v
v is perpendicular to normal n
nOST vOS 0
Dot product
nOS
nOST (M-1 M) vOS 0
(nOST M-1) (M vOS) 0
vOS
(nOST M-1) vWS 0
vWS is perpendicular to normal nWS
nWST nOST (M-1)
nWS
nWS (M-1)T nOS
vWS
nWST vWS 0
76Comment
- So the correct way to transform normals is
- But why did nWS M nOS work for similitudes?
- Because for similitude / similarity transforms,
- (M-1)T l M
- e.g. for orthonormal basis
nWS (M-1)T nOS
Sometimes noted M-T
M
M-1
77Buzzword
- Which you dont need to remember
- Covariant transformed by the matrix
- e.g. tangent
- Contravariant transformed by the transpose
inverse - e.g. the normal
78Next Transformations in Modeling
- Robot Arm
- Camera Location
- gluLookAt(eye, , center, , up, )