Title: Geometric Transformations
1Geometric Transformations
- In this chapter, you will learn
- Scalars, points and vectors
- Vector and affine spaces
- Changes of coordinate systems
- Homogeneous coordinates (and why we need)
- Affine transformation translation, rotation,
scaling and shearing - Transformations in homogeneous coordinates
- Concatenation of transformations
- Geometric transformation using OpenGL
2Transformations
- Maps an object into another object
- In general, a transformation maps every point on
an object to another point in the underlying
coordinate space. - Why do we want/need transformations?
- Change size, location, orientation of objects
without changing underlying model (or primitive
drawing commands) - Animation
- Instancing
3What Do We Require of Transforms?Line Preserving
P1
Line Not Preserved
P2
4Geometric Pipeline
Pixels
Vertices
Transformer
Clipper
Projector
Rasterizer
5Vector Space vs Affine Space
- Vector Space
- Contains 2 distinct entities vectors and scalars
- Supports 2 operations addition and
multiplication - Scalar-vector multiplication and vector-vector
addition - Affine space
- Extension of vector space
- Supports
- Vector-point addition that produces a new point
- Point-point subtraction that produces a vector
- Euclidean space
- Extension of vector space that adds a measure of
size or distance
6Abstract Data TypesAffine Space
- Scalar a, b, d, e
- Magnitude (e.g. real numbers)
- Vector u, v, w, x
- Direction
- Magnitude
- No Position
- Point P, Q, R, X
- Position
- No Direction
- No Magnitude
7Commutative, Associative and Distributive
- Commutative
- ab ba
- Associative
- (a(bc)) ((ab)c)
- Distributive
- a(bc) ab bc
8Defined OperationsScalars
- Addition ab
- Additive identity zero
- Additive inverse - b
- Subtraction defined in terms of additive inverse
- Multiplication d j
- Multiplicative identity 1
- Multiplicative inverse 1/ d
- Division defined in terms of multiplicative
inverse
9Defined OperationsVectors
Dot Product
Cross Product
Addition
v
u
u v
q
v
u
Produces vector w orthogonal to u and v.
u v u v cos q
Magnitude
(produces scalar)
A2 u 2 v 2
w u x v w u v sin q
(produces vector)
10Defined OperationsPoints
Subtraction (Addition of points has no meaning.)
P
u P - R
R
Produces vector
11Defined OperationsScalars and Vectors
Multiplication of vector by scalar Produces
vector
u
v a u
a u a u
12Defined OperationsPoints and Vectors
Affine Addition Point Vector Point
Q
v
P
Q P v
Related to point subtraction.
13Lines in Affine Space
R
R
Q
v
Q P v
P
R P a v - lt a lt
Line segment from P to Q defined when 0 a 1
14Planes in Affine Space
Planes are defined uniquely by three points P,
Q, R
W(l)
Q
u Q - P v R - P
u
T( b)
R
P
v
S(a)
S(a) P a v T(b) P b u W(a, b, l) S -
l (T - S) P a v - l (b u - a v) W (a, b, l)
P a ( 1 l ) v - l b u W P d v c u
15Representations of Points and Vectors
Coordinate system
- Unique representation of v?
- Point and vector have the different
representation?
P (x, y, z)
16Changes of Coordinate Systems
The 3x3 matrix is then given by
17Changes of Coordinate Systems (2)
Given a vector w that has the representation
?1,?2,?3 w.s.t. v1, v2, v3
Assume that b has the representation of w w.s.t.
u1, u2, u3
Where
18Changes of Coordinate Systems (3)
Rotation and scaling of a basis
The inverse of matrix (MT) takes us from a to b
Translation of a basis
19Problem in 3D Coordinate Systems
- Failure to distinguish between points and vectors
- E.g. two vectors formed by point from (1,1,1) to
(2,3,4), and point from (0,0,0) to (1,2,3) are
the same - Make implementation more difficulty because
multiplication in 3D cannot represent a change of
frames - Composition is difficult to expression because
translation is expressed in addition while
rotation and scale are expressed in
multiplications - gt Use of Homogenous Coordinate
20Homogeneous Coordinates
Frame is specified by
where
are linearly independent basis vectors and P0
arbitrary point
Frame
Homogeneous coordinate representation
21Representation of VectorsIn Homogeneous
Coordinates
22Affine AdditionIn Homogeneous Coordinate
Representation
Point
Point
Scalar times vector
23Transform as aChange of Frame
y
Want to translate by Dx 2, Dy4
(2, 3) in xy (4,7) in x y
y
x
(2, 3)
Dx 2, Dy4
x
1. Transform frame 2. Find representation in
orignial frame
24Transform as aChange of Frame
Representation
Frame
25Transformation Matrix
Original Frame
Transformed Frame
Express elements of transformed frame in original
frame
where
26Transformation of Representation
where is of the form
27Affine Transformations
T(point) -gt point
T(vector) -gt vector
28What Do We Require of Transforms?Line Preserving
P1
Line Not Preserved
P2
29Affine TransformationLine Preservation
Matrix multiplication is linear. Therefore
T(p)aT(v)
pav
v
T(v)
p
T(p)
Meets our requirements!
30Translation
Assumptions
Translate the new frame
31Scaling
Scale the new frame
32Rotation
Rotation around the z axis
33Rotation About x and y axes
Similar derivations give
34Concatenation of Transformations
Apply T1, Then apply T2
35Rotation About an Fixed Point
- Strategy
- translate the cube to the origin,
- rotate it about the origin,
- translate it back again at
36Sequence of transformations
37General Rotation
- Any rotation about the origin is equivalent to 3
successive rotations about 3 axes, x, y, and z.
?
?
38The Instance Transformation
- Each occurrence of an object in the scene?an
instance of the objects prototype
39Rotation About an Arbitrary Axis
40Rotation (contd)
- Strategy
- translate the fixed point to the origin,
- align the axis of rotation with the z axis,
- complete the rotation of the cube,
- undo the rotation of the rotation axis,
- translate the fixed point back again.
?
41Rotation (contd)
42 Rotation (contd)
43Rotation (contd)
44Rotation (contd)
45Rotation (contd)
- The complete sequence of matrices to be applied
46OpenGL Matrix Operations
glLoadIdentity() Loads an identity matrix onto
the top of the current stack glLoadMatrixf(pointe
r_to_matrix) Loads arbitrary matrix onto top of
the current stack glMultMatrixf(pointer_to_matrix
) Postmultiplies current matrix by arbitrary
matrix Matricies are one-dimensional arrays of
type GLfloat in column major order.
47Predefined Postmultiplier Operatorsin OpenGL
glTranslatef(dx, dy, dz) Multiplies current
matrix with translation matrix. dx, dy, and dz
are translations along x,y, and z
axes. glRotatef(angle, x, y, z) Multiplies
current matrix with rotation about the line from
the origin through the point (x, y, z) by angle.
Right hand rule applies. glScalef(sx, sy,
sz) Multiplies current matrix with scaling
matrix. sx, sy, sz are the scale factors along
the x, y, and z axes.
48Rotation About a Fixed Point in OpenGL
- glMatrixMode(GL_MODELVIEW)
- glLoadIdentity()
- Move the fixed point to the origin
- glTranslatef(4.0, 5.0, 6.0)
- Rotate about the origin
- glRotatef(45.0, 1.0, 2.0, 3.0)
- Move the fixed point back again
- glTranslatef(-4.0, -5.0, -6.0)
49Transformation Matrices in OpenGL
Matrix Mode
3D Model Vertices
2D
3D
Vertices
Modelview
Projection