Geometric Transformations - PowerPoint PPT Presentation

1 / 38
About This Presentation
Title:

Geometric Transformations

Description:

Translation. Rotation Matrices. Translation Matrices. Homogeneous Coordinates ... The difference between two points is a vector. The sum of a vector and a point ... – PowerPoint PPT presentation

Number of Views:17
Avg rating:3.0/5.0
Slides: 39
Provided by: cbo4
Category:

less

Transcript and Presenter's Notes

Title: Geometric Transformations


1
Geometric Transformations
  • Translation
  • Rotation Matrices
  • Translation Matrices
  • Homogeneous Coordinates
  • Composite Transformations
  • Vectors vs. Coordinates

Textbook Pages 7 to 43
2
Some Linear Algebra
Y
(10, 10, 0)
Well refer to tuples in many different ways
(x, y, z)
X
  • Tuple notation

P(x, y, z)
Z
  • Matrix (vector) notation

3
Vectors 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
4
Point 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
5
Translation
  • 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.
6
Translation 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!

7
2D Rotation
Y
  • Rotation by angle q around origin
  • P1 rotated to P2
  • Positive rotation is counter-clockwise

q
X
  • Rotation solution

Rotating points means rotation around the origin.
Rotating vectors just means rotating the vector
direction, since it is relative to the origin.
8
Many ways to same the same thing
  • Conventional Notation

Transposed Notation
  • Transpose Rule
  • Transpose of a matrix is the matrix flipped on
    the diagonal

9
Rotation Example
Y
  • Example, q35o0.61 radians

q
X
10
Extending to 3D Rotation around the Z axis
  • Rotation around Z axis
  • Note that Z is not changed

11
Rotation around Z in 3D
  • Z is unchanged
  • Can you deduce other axis rotations?

TT
12
Other Axis Rotations
  • Rotation around Y
  • Rotation around X

13
Suppose I want to do this?
  • As given to me
  • Ready for takeoff

14
What if we want to do more than one rotation on
the same object?
  • Rotation around X
  • then Rotation around Y

15
What we want
  • First rotation

Point before rotation
Point after one rotation
Point after second rotation
  • Second rotation

Point after one rotation
My snail has about 24,000 vertices. We do this a
lot. Any improvements in efficiency possible?
16
Composed 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
17
XNA
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
18
Rotation around arbitrary axis
Matrix.CreateFromAxisAngle(new Vector3(7, 3, 4),
0.52f)
This will rotate around any vector you come up
with.
19
Back to Translation
  • We can express translation all these ways

Can we express it this way?
What do you think?
20
This 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
21
We can put rotation in the same system
  • Rotation around X axis
  • And the other two

22
Rotation around X axis
Rotation around Y axis
Rotation around Z axis
Translation
TT
23
A 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.
24
XNA 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)

25
XNA 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
26
XNA 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
27
Important 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?
28
Rotate and Place
  • Common Activity
  • Need something somewhere and pointing some
    direction

29
What I want
30
How to do?
(87.5, 90, -108)
100cm
TT
31
How 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
32
We have it there, how to we rotate it?
33
We 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)
34
Rotation 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
35
Rotation 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
36
Scaling
  • Scaling is around the axis
  • You can scale uniformly or differently for each
    axis

Matrix.CreateScale(2.0f) Matrix.CreateScale(1,
2, 1)
37
Skew
  • Skew turns rectangles into parallelograms
  • Z Z sY
  • This is a Z relative to Y skew.
  • Other combinations are possible.

S-2.8
38
Matrices for scaling and skew
Uniform Scaling
Non-uniform Scaling
Z relative to Y skew
Write a Comment
User Comments (0)
About PowerShow.com