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
R P a v 1 ? a ? 0
R P a v - lt a lt
P
Affine Sum/Combination R P a (Q - P) a
Q (1- a) P a1 P a2 Q where a1 a2 1
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
15Linear Transformations
- Let T A?B, where A and B vector spaces
- T is linear transformations iff
- T(ab) T(a) T(b) a, b ?vector space V
- T(?a) ?T(a) ? is a scalar
- T(?i ?iai) ?i?iT(ai)
16Affine Transformations
- Let T A?B, where A and B affine spaces
- T is affine transformations iff
- T is a linear transformations on vectors
- T maps vectors to vectors and points to points
- T(P a) T(P) T(a) where P is a point and a
is a vector
17Affine Transformations (2)
- Properties of affine transformations
- T preserves affine combinations
- T(?i ?iPi) ?i?iT(Pi)
- Where ?i ?i 0 or 1
- T maps lines to lines
- T( (1 - ?)P ? Q) (1 - ?) T(P) ? T(Q)
- Ratios of distance along a line is preserved
- T maps parallel lines to parallel lines
-
18Representations of Points and Vectors
Coordinate system
- Unique representation of v?
- Point and vector have the different
representations?
P (x, y, z)
19Changes of Coordinate Systems
The 3x3 matrix is then given by
20Changes 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
21Changes 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
22Problem 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
23Homogeneous Coordinates
Frame is specified by
where
are linearly independent basis vectors and P0
arbitrary point
Frame
Homogeneous coordinate representation
24Representation of VectorsIn Homogeneous
Coordinates
25Affine AdditionIn Homogeneous Coordinate
Representation
Point
Point
Scalar times vector
26Transform as aChange of Frame
y
Want to translate by Dx 2, Dy4
(2, 3) in x-y (4,7) in x -y
y
(4, 7)
x
Dx 2, Dy4
x
1. Transform frame 2. Find representation in
orignial frame
27Transform as aChange of Frame
Representation
Frame
28Transformation Matrix
Original Frame
Transformed Frame
Express elements of transformed frame in original
frame
where
29Transformation of Representation
where is of the form
30Affine Transformations
T(point) -gt point
T(vector) -gt vector
31What Do We Require of Transforms?Line Preserving
P1
Line Not Preserved
P2
32Affine TransformationLine Preservation
Matrix multiplication is linear. Therefore
T(p)aT(v)
pav
v
T(v)
p
T(p)
Meets our requirements!
33Translation
Assumptions
Translate the new frame
34Scaling
Scale the new frame
35Rotation
Rotation around the z axis
36Rotation About x, y and z axes
Similar derivations give
37Concatenation of Transformations
Frame Transformation Approach Post-multiply
Apply T1, Then apply T2
Point Transformation Approach Pre-multiply
38Rotation About an Fixed Point
- Strategy
- translate the cube to the origin,
- rotate it about the origin,
- translate it back again at
39Sequence of transformations
40General Rotation
- Any rotation about the origin is equivalent to 3
successive rotations about 3 axes, x, y, and z.
?
?
41The Instance Transformation
- Each occurrence of an object in the scene?an
instance of the objects prototype
42Rotation About an Arbitrary Axis
43Rotation (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.
?
44Rotation (contd)
45 Rotation (contd)
46Rotation (contd)
47Rotation (contd)
48Rotation (contd)
- The complete sequence of matrices to be applied
49OpenGL 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.
50Predefined 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.
51Rotation 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)
52Transformation Matrices in OpenGL
Matrix Mode
3D Model Vertices
2D
3D
Vertices
Modelview
Projection