Title: Geometric Transformations
1Geometric Transformations
- Translation
- Rotation Matrices
- Translation Matrices
- Homogeneous Coordinates
- Composite Transformations
- Vectors vs. Coordinates
Textbook Pages 7 to 43
2Some Linear Algebra
Y
(10, 10, 0)
Well refer to tuples in many different ways
(x, y, z)
X
P(x, y, z)
Z
3Vectors and Coordinates in 3D
Y
(10, 10, 0)
- Points
- A location in space
X
Y
Z
(10, 10, 0)
- Vector
- A direction in space
X
How do you tell them apart? The only distinction
is the meaning Sometimes well use varying
notation
Z
4Point and Vector Axioms
- The difference between two points is a vector
V P - Q
- The sum of a vector and a point is a point
Q V P
The sum of two vectors is a vector
W U V
Q
U
V
(Q - R) (P - Q) (P R)
R
P
W
TT
5Translation
- Translation
- Translation is moving objects in space
- Simply add to the coordinates
- Translation amount is a vector
PPV
The model is made up of small triangles. Each
triangle corner is called a vertex. Each vertex
is a point. When we render, we change the vertex
values.
6Translation is easy, Rotation is harder
- Rotation is so important well do it four
different ways!
- We need to be able to point things the way they
need to go!
72D Rotation
Y
- Rotation by angle q around origin
- P1 rotated to P2
- Positive rotation is counter-clockwise
q
X
Rotating points means rotation around the origin.
Rotating vectors just means rotating the vector
direction, since it is relative to the origin.
8Many ways to same the same thing
Transposed Notation
- Transpose Rule
- Transpose of a matrix is the matrix flipped on
the diagonal
9Rotation Example
Y
- Example, q35o0.61 radians
q
X
10Extending to 3D Rotation around the Z axis
- Rotation around Z axis
- Note that Z is not changed
11Rotation around Z in 3D
- Can you deduce other axis rotations?
TT
12Other Axis Rotations
13Suppose I want to do this?
14What if we want to do more than one rotation on
the same object?
15What we want
Point before rotation
Point after one rotation
Point after second rotation
Point after one rotation
My snail has about 24,000 vertices. We do this a
lot. Any improvements in efficiency possible?
16Composed Rotations
- We can multiply matrices together
- Matrix multiplication is associative
We can do many complex rotations and reduce them
all into one single matrix.
TT
17XNA
Matrix transform Matrix.CreateRotationX(MathHelp
er.ToRadians(30))
Matrix.CreateRotationY((float)Math.PI)
Many operations reduce to just one matrix.
Operations occur left-to-right
18Rotation around arbitrary axis
Matrix.CreateFromAxisAngle(new Vector3(7, 3, 4),
0.52f)
This will rotate around any vector you come up
with.
19Back to Translation
- We can express translation all these ways
Can we express it this way?
What do you think?
20This is no way to express translation as a 3x3
matrix
- So, were going to use a 4x4 matrix instead
- Notice that the 1 is preserved
- Its along for the ride to make translation easier
Well just add an extra 1 whenever we multiply a
matrix by a vector/point
21We can put rotation in the same system
22Rotation around X axis
Rotation around Y axis
Rotation around Z axis
Translation
TT
23A Warning about the Transposition
- Im presenting this in the XNA format
- Your textbook uses the more common notation
All matrices are transposed and all operations
are reversed. Operations will occur left to
right. Youll just have to get used to it.
24XNA Matrix type
public struct Matrix public float
M11 public float M12 public
float M13 public float M14
public float M21 public float M22
public float M23 public float M24
public float M31 public float M32
public float M33 public float
M34 public float M41 public
float M42 public float M43
public float M44
- Yep, its a 4x4 matrix
- M(row)(column)
25XNA Matrix.CreateRotationX
public static Matrix CreateRotationX(float
radians) Matrix matrix float num2
(float)Math.Cos((double)radians) float num
(float)Math.Sin((double)radians) matrix.M11
1f matrix.M12 0f matrix.M13 0f
matrix.M14 0f matrix.M21 0f
matrix.M22 num2 matrix.M23 num
matrix.M24 0f matrix.M31 0f
matrix.M32 -num matrix.M33 num2
matrix.M34 0f matrix.M41 0f
matrix.M42 0f matrix.M43 0f
matrix.M44 1f return matrix
26XNA Matrix.CreateTranslation
public static Matrix CreateTranslation(Vector3
position) Matrix matrix matrix.M11
1f matrix.M12 0f matrix.M13 0f
matrix.M14 0f matrix.M21 0f
matrix.M22 1f matrix.M23 0f
matrix.M24 0f matrix.M31 0f
matrix.M32 0f matrix.M33 1f
matrix.M34 0f matrix.M41 position.X
matrix.M42 position.Y matrix.M43
position.Z matrix.M44 1f return
matrix
27Important Details
- Rotation is around the origin
- Rotation is counter-clockwise when looking from
the vector direction
Suppose I wanted to rotate the ship around the
engine instead of the center?
28Rotate and Place
- Common Activity
- Need something somewhere and pointing some
direction
29What I want
30How to do?
(87.5, 90, -108)
100cm
TT
31How to do?
(87.5, 90, -108)
100cm
Matrix transform Matrix.CreateRotationX((float)
Math.PI / 2) Matrix.CreateTransl
ation(87.5f, 90, -8)
Screwdriver tip before rotation (0, 100,
0) Screwdriver tip after rotation (0, 0, -100)
Common activity Rotate to the desired
orientation, then move to the desired place
32We have it there, how to we rotate it?
33We have it there, how to we rotate it? ANSWER
Matrix transform Matrix.CreateRotationY(angle)
Matrix.CreateRotationX((fl
oat)Math.PI / 2)
Matrix.CreateTranslation(87.5f, 90, -8)
34Rotation around a point
- Suppose you were given the screwdriver already
there? - How would you rotate it?
- We want to rotate around (87.5, 90, -108).
(87.5, 90, -108)
- To rotate around a point
- Translate point to origin, rotate, translate
point back
1
3
2
35Rotation around a point
Matrix transform2 Matrix.CreateTranslation(-87.5
f, -90, 108) Matrix.CreateRotati
onZ(angle) Matrix.CreateTranslat
ion(87.5f, 90, -108)
- To rotate around a point
- Translate point to origin, rotate, translate
point back
1
3
2
36Scaling
- Scaling is around the axis
- You can scale uniformly or differently for each
axis
Matrix.CreateScale(2.0f) Matrix.CreateScale(1,
2, 1)
37Skew
- Skew turns rectangles into parallelograms
- Z Z sY
- This is a Z relative to Y skew.
- Other combinations are possible.
S-2.8
38Matrices for scaling and skew
Uniform Scaling
Non-uniform Scaling
Z relative to Y skew