Professional Documents
Culture Documents
Geometric Transformations
2D and 3D
x1
= (3(v1+w1)+2(v2+w2) , -3(v1+w1)+4(v2+w2)) e1
𝑇=
𝑎
𝑐 [ 𝑏
𝑑 ] x1
A transformation of an arbitrary column vector x = has the form:
x2
x1 a b x1 ax1 bx2
T
x
2 c d x
2 1 cx dx 2
1 a b 1 a 0 a b 0 b
T T
0 c d 0 c 1 c d 1 d
Notice that the columns of the matrix representation of our transformation matrix T are
precisely T applied to e1 and e2:
Scaling in 2D (2/2)
S is a diagonal matrix; we can quickly Properties of scaling to look out for:
check using matrix multiplication Does not preserve angles between lines
that our derivation is correct: in the plane (except when scaling is
uniform, i.e. sx = sy)
sx 0 x s x x x'
Sv If the object doesn’t start at the origin,
s y y s y y y '
0 scaling will move it closer to or farther
from the origin (often not desired)
S multiplies each coordinate of v by
the appropriate scaling factor, as
expected
In general, the ith entry of Dv, where D
is diagonal, is (D[i,i] * v[i]), product of
two scalars
Andries van Dam © 9/18/18 12/47
CS123 | INTRODUCTION TO COMPUTER GRAPHICS
Rotation in 2D (1/2)
Rotate by θ about the origin
v’ = Rθv, where
x
v= y
(original vertex)
v’ = x'
y '
(new vertex)
Rotation in 2D (2/2)
Let’s try matrix-vector multiplication
x’ = x cos() – y sin()
y’ = x sin() + y cos()
Back to Translation
Our translation matrix (T) can now be represented by embedding the
translation vector in the right column:
1 0 dx
T 0 1 dy
0 0 1
To verify that this is the right matrix, multiply it by our homogenized point:
1 0 dx x x dx
Tv 0 1 dy y y dy v'
0 0 1 1 1
Coordinates have been translated, and v’ is still homogeneous
Andries van Dam © 9/18/18 19/47
CS123 | INTRODUCTION TO COMPUTER GRAPHICS
Transformations Homogenized
Let’s homogenize our all matrices! Doesn’t affect linearity of scaling and rotation
Our new transformation matrices look like this…
Transformation Matrix
[ ]
Scaling 𝑠𝑥 0 0
0 𝑠𝑦 0
0 0 1
Rotation
[ ]
𝑐𝑜𝑠 (𝜃) − 𝑠𝑖𝑛 (𝜃) 0
𝑠𝑖𝑛(𝜃) 𝑐𝑜𝑠 (𝜃) 0
0 0 1
[ ]
Translation 1 0 𝑑𝑥
0 1 𝑑𝑦
0 0 1
Note: These transformations are called affine transformations, which means they
preserve ratios of distances between points on a straight line (but not necessarily (0, 0) )
Andries van Dam © 9/18/18 20/47
CS123 | INTRODUCTION TO COMPUTER GRAPHICS
Examples
Scaling: Scale by 15 in the x direction, 17 in the y direction
[ ]
15 0 0
0 17 0
0 0 1
Rotation: Rotate by 123o
[ ]
𝑐𝑜𝑠 (123) − 𝑠𝑖𝑛 (123) 0
𝑠𝑖𝑛 (123) 𝑐𝑜𝑠 (123) 0
0 0 1
Translation: Translate by -16 in the x direction, +18 in the y direction
[ ]
1 0 −16
0 1 18
0 0 1
Andries van Dam © 9/18/18 21/47
CS123 | INTRODUCTION TO COMPUTER GRAPHICS
Inverses
When we want to undo a transformation, we’ll need to find the matrix’s inverse.
Thanks to homogenization, they are all invertible!
Transformation Matrix Inverse Does it make sense?
Using the properties above, we see that this is the identity matrix, so MT = M-1
Andries van Dam © 9/18/18 24/47
CS123 | INTRODUCTION TO COMPUTER GRAPHICS
Consider our functions f and g as matrices (M1 and M2) and our input as a
vector v
Our composition is equivalent to M1M2v
Note that we apply the matrices in sequence right to left. We can use associativity to compose
them first; it is often useful to be able to apply a single matrix if, for example, we want to use it
to transform many points at once
Important: order matters! Matrix multiplication is NOT commutative.
Be sure to check out the Transformation Game at
http://www.cs.brown.edu/exploratories/freeSoftware/repository/edu/brown/cs/explorator
ies/applets/transformationGame/transformation_game_guide.html
Let’s see an example…
Andries van Dam © 9/18/18 27/47
CS123 | INTRODUCTION TO COMPUTER GRAPHICS
Translate by 4
x = 6, y = 0, then
3
2
rotate by 45o 1
0
1 2 3 4 5 6 7 8 9 10
Y
Rotate by 45o,
6
5
then translate 4
3
by x = 6, y = 0 2
1
0
1 2 3 4 5 6 7 8 9 10
X
Apply
Andries to ©
van Dam all vertices
9/18/18 29/47
CS123 | INTRODUCTION TO COMPUTER GRAPHICS
Inverses Revisited
What is the inverse of a sequence of transformations?
(M M …M )-1 = M -1M -1…M -1
1 2 n n n-1 1
Dimension++ (3D!)
How should we treat geometric transformations in 3D?
Just add one more coordinate/axis!
x
A point is represented as
y
z
A matrix for a linear transformation T can be represented as
0
0
where e3 is the standard basis vector along the z-axis,
1
Transformations in 3D
Transformation Matrix Comments
Scaling sx
0
0 0 0 Looks just like the 2D version.
sy 0 0 We just added an sz term.
0 0 sz 0
0 0 0 1
Rodrigues’s Formula…
Rotation by angle θ around vector u = [ux uy uz]T
Note: this is an arbitrary unit vector u in xyz-space
Here’s a not so friendly-looking rotation matrix
cos u x2 (1 cos ) u x u y (1 cos ) u z sin u x u z (1 cos ) u y sin
u x u y (1 cos ) u z sin cos u y2 (1 cos ) u y u z (1 cos ) u x sin
u x u z (1 cos ) u y sin u y u z (1 cos ) u x sin cos u z2 (1 cos )
This is called the coordinate form of Rodrigues’s formula
Let’s try a different approach…
Note these differ only in how the 3x3 submatrix is embedded in the homogeneous matrix, but the
row-column order is different for Rzx
You can compose these matrices to form a composite rotation matrix
Andries van Dam © 9/18/18 38/47
CS123 | INTRODUCTION TO COMPUTER GRAPHICS
Example in 3D!
Let’s take some 3D object, say a cube centered at (2,2,2)
Rotate clockwise in object’s space by 30o around x axis, 60o around y, and 90o
around z
Scale in object space by 1 in the x, 2 in the y, and 3 in the z
Translate by (2,2,4) in world space
Transformation sequence: TT0-1SxyRxyRzxRyzTo, where T0 translates to (0,0):
stanchion base
head trunk arm arm
3D scenes are often stored in a directed acyclic graph (DAG) called a scene graph
WPF (Windows Presentation Foundation)
Open Scene Graph (used in the Cave)
X3D ™ (VRML ™ was a precursor to X3D)
most game engines
Typical scene graph format:
objects (cubes, sphere, cone, polyhedra etc.):
stored as nodes (default: unit size at origin)
attributes (color, texture map, etc.): stored as separate nodes
Example scenegraph from a game engine
Transformations: also nodes
Andries van Dam © 9/18/18 42/47
CS123 | INTRODUCTION TO COMPUTER GRAPHICS
Together the above hierarchy of transformations forms the “robot” scene as a whole
Andries van Dam © 9/18/18 44/47
CS123 | INTRODUCTION TO COMPUTER GRAPHICS
already
This might occur if you have multiple group1
obj4
obj3
similar components to your scene.
For example, the robot’s 2 arms
Here, group 3 has been used twice. obj1 group3 group2
group 3 as a whole
T0T1 vs. T0T2T4
Further Reading
More information can be found in the textbook
Chapter 12 goes into more detail about some of the linear algebra
involved in graphics