2. 10/5/2022 2
Intro & General Information
Geometric Transformations
Construction
(translate, rotate, scale, mirror)
Viewing
(projections, zooming)
Animation
(processes, vibration)
3. Coordinate Systems
In order to specify the geometry of a given solid, it is necessary to
use a variety of coordinate systems. Its Major classifications are:
World Coordinate System: Also known as the "universe" or
sometimes "model" coordinate system. This is the base reference
system for the overall model, ( generally in 3D ), to which all other
model coordinates relate
User Coordinate System: Also known as “working” coordinate
system. When it is difficult to define certain geometries using
WCS, In such cases user coordinate system can be defined relative
to the WCS.
Display Coordinates: This refers to the actual coordinates to be
used for displaying the image on the screen.
4. 10/5/2022 4
General Information
Transformation of a point is basic in GT. It can be formulated as follows:
Given a point P that belongs to a geometric model find the corresponding
point P* in the new position such that
P* = f(P, transformation parameters)
• The transformation parameters should provide ONE-TO-ONE-
MAPPING.
• Multiple transformations can be combined to yield a single
transformation which should have the same effect as the sequential
application of original ones. CONCATENATION /kənˌkatnˈāSH(ə)n/
Equation of P* for graphics hardware should be in matrix notation:
P* = [T]P,
where [T] is the transformation matrix.
5. Geometric Transformations
Sometimes also called modeling
transformations
Geometric transformations: Changing an object’s
position (translation), orientation (rotation) or size
(scaling)
Modeling transformations: Constructing a scene
or hierarchical description of a complex object
Others transformations: reflection and
shearing operations
5
6. 1. Geometric Transformations
What is transformation?
> It is the backbone of computer graphics, enabling us to
manipulate the shape, size, and location of the object.
> Changing something to something else via rules.
Why are they important to graphics?
> It can be used to effect the following changes in a geometric
object:
1. Change the location
2. Change the shape
3. Change the size
4. Rotate
7. 2. Types of Transformations
i. Geometric/Object Transformation
> This transformation alters the coordinate values of the object. Basic
operations are scaling, translation, rotation and combination of one
or more of these basic transformations.
> Object transformation = Move (transform) an object in the 2D/3D space.
ii. Visual/ Coordinate System Transformation
> In this transformation there is no change in either the geometry or the
coordinates of the object. A copy of the object is placed at the desired sight,
without changing the coordinate values of the object.
> Coordinate system transformation = Move (transform) the coordinate
system. View the objects from the new coordinate system.
10. 10/5/2022 10
Translation
Translation is a rigid-body transformation (Euclidean) when
each entity of the model remains parallel, or each point
moves an equal distance in a given direction:
P* = P + d (for both 2D and 3D). In a scalar form (for 3D):
x* = x + xd
y* = y + yd
z* = z + zd
C (11,7)
A (8,5)
B (10,8)
A*
C*
B*
y
x
O
Question: Find the coordinates of vertices A*, B*,
and C* of the translated triangle.
The distance vector of translation: D = [-7 -4]T.
Verify that the lengths of the edges are unchanged.
11. i. Translation - 2D
Moving an object is called a translation.
We translate a point by adding to the x and y coordinates,
respectively, the amount the point should be shifted in the x and y
directions.
We translate an object by translating each vertex in the object.
12. Basic 2D Geometric
Transformations
2D Translation
x’ = x + tx , y’ = y + ty
P’=P+T
Translation moves the object without deformation
(rigid-body transformation)
P
P’
T
y
x
t
t
T
y
x
P
y
x
P ,
'
'
'
,
12
13. Basic 2D Geometric
Transformations (cont.)
2D Translation
To move a line segment, apply the transformation
equation to each of the two line endpoints and
redraw the line between new endpoints
To move a polygon, apply the transformation
equation to coordinates of each vertex and
regenerate the polygon using the new set of vertex
coordinates
13
14. Scaling is used to change the size of an entity or a model.
P* = [S]P
sx 0 0
For general case [S] = 0 sy 0 ,
0 0 sz
If 0 < s < 1 - compression
If s > 1 - stretching
sx = sy = sz - uniform scaling, otherwise - non-uniform
10/5/2022 14
Scaling
where sx, sy, and sz are the scaling
factors in the X, Y, and Z directions
respectively.
Question: The larger circle is the scaled copy
of the smaller one. Can you say that we have a
uniform scaling? Why? Define y* and R*.
O(4,2)
O*(10,y*)
O
x
y
R 1
R*
15. ii. Scaling
> Changing the size of an object is called a scale. We scale an
object by scaling the x and y coordinates of each vertex in the
object.
16. 2D Rotation
Rotation axis
Rotation angle
rotation point or pivot point (xr,yr)
yr
xr
θ
Basic 2D Geometric
Transformations (cont.)
16
2D Geometric Transformations
17. 2D Rotation
If θ is positive counterclockwise rotation
If θ is negative clockwise rotation
Remember:
cos(a + b) = cos a cos b - sin a sin b
cos(a - b) = cos a sin b + sin a cos b
Basic 2D Geometric
Transformations (cont.)
17
2D Geometric Transformations
18. 10/5/2022 18
Rotation
Rotation is a non-commutative transformation (depends on sequence).
cos
0
sin
0
1
0
sin
0
cos
cos
sin
0
sin
cos
0
0
0
1
1
0
0
0
cos
sin
0
sin
cos
cos
sin
sin
cos
cos
sin
sin
cos
sin
sin
cos
cos
)
sin(
)
cos(
P
sin
cos
P
P
P
*
*
*
*
*
y
x
z
R
R
R
z
y
x
y
x
z
r
r
r
r
z
r
r
z
y
x
z
r
r
z
y
x
R
P*
P
x
y*
x*
y
X
Y
Z
Question: Let the length of a major and minor
axes of an ellipse with the center on the origin
of the CS be 2a and 2b respectively, and - the
angle between the major axis and the x-axis.
Then, derive the expression of an ellipse in the
(O,x,y) system.
19. iii. Rotation about the origin
ø Consider rotation about the origin by Θ degrees
ø Radius stays the same, angle increases by Θ.
20. 2D Rotation
At first, suppose the pivot point is at the origin
x’=r cos(θ+Φ) = r cos θ cos Φ - r sin θ sin Φ
y’=r sin(θ+Φ) = r cos θ sin Φ + r sin θ cos Φ
x = r cos Φ, y = r sin Φ
x’=x cos θ - y sin θ
y’=x sin θ + y cos θ
Φ
(x,y)
r
r θ
(x’,y’)
Basic 2D Geometric
Transformations (cont.)
20
2D Geometric Transformations
21. Basic 2D Geometric
Transformations
2D Rotation
P’=R·P
cos
sin
sin
cos
R
Φ
(x,y)
r
r θ
(x’,y’)
21
2D Geometric Transformations
25. 2D Scaling
Scaling is used to alter the size of an object
Simple 2D scaling is performed by multiplying
object positions (x, y) by scaling factors sx and sy
x’ = x · sx
y’ = y · sx
or P’ = S·P
y
x
s
s
y
x
y
x
0
0
'
'
Basic 2D Geometric
Transformations (cont.)
25
26. 2D Scaling
Any positive value can be used as scaling factor
Values less than 1 reduce the size of the object
Values greater than 1 enlarge the object
If scaling factor is 1 then the object stays unchanged
If sx = sy , we call it uniform scaling
If scaling factor <1, then the object moves closer to the
origin and If scaling factor >1, then the object moves
farther from the origin
x’ x
Basic 2D Geometric
Transformations (cont.)
26
27. 2D Scaling
Why does scaling also reposition object?
Answer: See the matrix (multiplication)
Still no clue?
𝑥′
𝑦′
=
𝑠𝑥 0
0 𝑠𝑦
∗
𝑥
𝑦 =
𝑥 ∗ 𝑠𝑥 + 𝑦 ∗ 0
𝑥 ∗ 0 + 𝑦 ∗ 𝑠𝑦
Basic 2D Geometric
Transformations (cont.)
27
28. 2D Scaling
We can control the location of the scaled object by
choosing a position called the fixed point (xf,yf)
x’ – xf = (x – xf) sx y’ – yf = (y – yf) sy
x’=x · sx + xf (1 – sx)
y’=y · sy + yf (1 – sy)
Polygons are scaled by applying the above formula
to each vertex, then regenerating the polygon using
the transformed vertices
Basic 2D Geometric
Transformations (cont.)
28
29. Example:
If the triangle A(1, 1), B(2, 1), C(1, 3) is scaled by a
factor 2, find the new coordinates of the triangle.
31. Cont’d…
Example:
• Rotate the rectangle (0, 0), (2, 0), (2, 2), (0, 2) by 30o
ccw about its centroid and find the new coordinates
of the rectangle.
33. 4. Homogeneous Coordinates
> In order to represent a translation as a matrix multiplication
operation we use 3 x 3 matrices and pad the points to become 3 x 1
matrices.
> This coordinate system (using three values to represent a 2D point) is
called homogeneous coordinates.
> Let the added extra coordinate be W, to a point: P (x, y, W).
> Two sets of homogeneous coordinates represent the same point if
they are a multiple of each other.
> If W ≠ 0 , divide by it to get Cartesian coordinates of point: (x/W,
y/W, 1).
> If W = 0, point is said to be at infinity.
40. 10/5/2022 40
Homogeneous Transformation
When we scale then rotate, the transformed image is given by:
P* = ([R][S])P
where [S], [R], [R] [S] are 3x3 transformation matrices. This is not the case
for a translation (P* = P + d). The goal is to find a [D] such that
P + d = [D]P
in order to perform valid matrix multiplication.
This is found by using a homogeneous coordinates.
Homogeneous Transformation maps n-dimensional space into (n+1)- dim.
3D representation of the point vector - P = [x, y, z]T
Homogeneous rep. of the same vector - P = [xw, yw, zw, w]T where w = 1
41. Matrix Representations and
Homogeneous Coordinates
Many graphics applications involve
sequences of geometric transformations
Animations
Design and picture construction applications
We will now consider matrix representations
of these operations
Sequences of transformations can be efficiently
processed using matrices
41
2D Geometric Transformations
42. Matrix Representations and
Homogeneous Coordinates (cont.)
P’ = M1 · P + M2
P and P’ are column vectors
M1 is a 2 by 2 array containing multiplicative
factors
M2 is a 2 element column matrix containing
translational terms
For translation M1 is the identity matrix
For rotation or scaling, M2 contains the
translational terms associated with the pivot point
or scaling fixed point
42
2D Geometric Transformations
43. To produce a sequence of operations, such
as scaling followed by rotation then
translation, we could calculate the
transformed coordinates one step at a time
A more efficient approach is to combine
transformations, without calculating
intermediate coordinate values
Matrix Representations and
Homogeneous Coordinates (cont.)
43
2D Geometric Transformations
44. Multiplicative and translational terms for a 2D
geometric transformation can be combined
into a single matrix if we expand the
representations to 3 by 3 matrices
We can use the third column for translation terms,
and all transformation equations can be
expressed as matrix multiplications
Matrix Representations and
Homogeneous Coordinates (cont.)
44
2D Geometric Transformations
45. Expand each 2D coordinate (x,y) to three
element representation (xh,yh,h) called
homogeneous coordinates
h is the homogeneous parameter such that
x = xh/h, y = yh/h,
infinite homogeneous representations for a
point
A convenient choice is to choose h = 1
Matrix Representations and
Homogeneous Coordinates (cont.)
45
2D Geometric Transformations
46. 10/5/2022 46
Homogeneous Transformation
The transformation matrices in new (homogeneous) representation:
1
0
0
0
0
0
0
R
1
0
0
0
0
1
0
0
0
0
1
0
0
0
0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
1
0
0
0
1
0
0
0
1
33
32
31
23
22
21
13
12
11
r
r
r
r
r
r
r
r
r
M
s
s
s
S
z
y
x
D
z
y
x
d
d
d
47. 2D Translation Matrix
or, P’ = T(tx,ty)·P
1
1
0
0
1
0
0
1
1
'
'
y
x
t
t
y
x
y
x
Matrix Representations and
Homogeneous Coordinates (cont.)
47
2D Geometric Transformations
48. 2D Rotation Matrix
or, P’ = R(θ)·P
1
1
0
0
0
cos
sin
0
sin
cos
1
'
'
y
x
y
x
Matrix Representations and
Homogeneous Coordinates (cont.)
48
2D Geometric Transformations
49. 2D Scaling Matrix
or, P’ = S(sx,sy)·P
1
1
0
0
0
0
0
0
1
'
'
y
x
s
s
y
x
y
x
Matrix Representations and
Homogeneous Coordinates (cont.)
49
2D Geometric Transformations
50. Inverse Transformations
2D Inverse Translation Matrix
By the way:
1
0
0
1
0
0
1
1
y
x
t
t
T
I
T
T
*
1
50
2D Geometric Transformations
51. Inverse Transformations (cont.)
2D Inverse Rotation Matrix
And also:
1
0
0
0
cos
sin
0
sin
cos
1
R
I
R
R
*
1
51
2D Geometric Transformations
52. Inverse Transformations (cont.)
2D Inverse Rotation Matrix:
If θ is negative clockwise
In
Only sine function is affected
Therefore we can say
Is that true?
Proof: It’s up to you
I
R
R
*
1
T
R
R
1
52
2D Geometric Transformations
53. Inverse Transformations (cont.)
2D Inverse Scaling Matrix
Of course:
1
0
0
0
1
0
0
0
1
1
y
x
s
s
S
I
S
S
*
1
53
2D Geometric Transformations
54. 2D Composite Transformations
We can setup a sequence of transformations
as a composite transformation matrix by
calculating the product of the individual
transformations
P’=M2·M1·P
=M·P
54
2D Geometric Transformations
55. 2D Composite Transformations
(cont.)
Composite 2D Translations
If two successive translation are applied to a point P,
then the final transformed location P' is calculated as
1
0
0
1
0
0
1
1
0
0
1
0
0
1
1
0
0
1
0
0
1
2
1
2
1
1
1
2
2
y
y
x
x
y
x
y
x
t
t
t
t
t
t
t
t
P
T
P
T
T
P
)
,
(
)
,
(
)
,
(
' 2
1
2
1
1
1
2
2 y
y
x
x
y
x
y
x t
t
t
t
t
t
t
t
55
2D Geometric Transformations
57. Composite 2D Scaling
1
0
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0
0
0
0
0
2
1
2
1
1
1
2
2
y
y
x
x
y
x
y
x
s
s
s
s
s
s
s
s
)
,
(
)
,
(
)
,
( 2
1
2
1
1
1
2
2 y
y
x
x
y
x
y
x s
s
s
s
s
s
s
s
S
S
S
2D Composite Transformations
(cont.)
57
2D Geometric Transformations
58. Don’t forget:
Successive translations are additive
Successive scalings are multiplicative
For example: If we triple the size of an object
twice, the final size is nine (9) times the original
9 times?
Why?
Proof: Again up to you
2D Composite Transformations
(cont.)
58
2D Geometric Transformations
59. General Pivot Point Rotation
Steps:
1. Translate the object so that the pivot point is
moved to the coordinate origin.
2. Rotate the object about the origin.
3. Translate the object so that the pivot point is
returned to its original position.
59
2D Geometric Transformations
61. General 2D Pivot-Point Rotation
1
0
0
1
0
0
1
1
0
0
0
cos
sin
0
sin
cos
1
0
0
1
0
0
1
r
r
r
r
y
x
y
x
1
0
0
sin
)
cos
1
(
cos
sin
sin
)
cos
1
(
sin
cos
r
r
r
r
x
y
y
x
2D Composite Transformations
(cont.)
61
2D Geometric Transformations
62. General Fixed Point Scaling
Steps:
1. Translate the object so that the fixed point
coincides with the coordinate origin.
2. Scale the object about the origin.
3. Translate the object so that the pivot point is
returned to its original position.
62
2D Geometric Transformations
63. General Fixed Point Scaling
(cont.)
(xr, yr) (xr, yr)
63
2D Geometric Transformations
65. 2D Composite Transformations
(cont.)
General 2D scaling directions:
Above: scaling parameters were along x and y
directions
What about arbitrary directions?
Answer: See next slides
65
2D Geometric Transformations
66. General 2D Scaling Directions
Scaling parameters s1 and s2 along orthogonal directions defined by the
angular displacement θ. 66
2D Geometric Transformations
67. General 2D Scaling Directions
(cont.)
General procedure:
1. Rotate so that directions coincides with x and y
axes
2. Apply scaling transformation 𝑆 𝑠1, 𝑠2
3. Rotate back
The composite matrix:
𝑅−1 Θ ∗ 𝑆 𝑠1, 𝑠2 ∗ 𝑅 Θ =
𝑠1 cos2 Θ + 𝑠2 sin2 Θ 𝑠2 − 𝑠1 cos Θ sin Θ 0
𝑠2 − 𝑠1 cos Θ sin Θ 𝑠1 sin2 Θ + 𝑠2 cos2 Θ 0
0 0 1
67
2D Geometric Transformations
68. 2D Composite Transformations
(cont.)
Matrix Concatenation Properties:
Matrix multiplication is associative !
M3· M2· M1= (M3· M2 ) · M1 = M3· ( M2 · M1 )
A composite matrix can be created by multiplicating left-
to-right (premultiplication) or right-to-left
(postmultiplication)
Matrix multiplication is not commutative !
M2 · M1 ≠ M1 · M2
68
2D Geometric Transformations
69. 2D Composite Transformations
(cont.)
Matrix Concatenation Properties:
But:
Two successive rotations
Two successive translations
Two successive scalings
are commutative!
Why?
Proof: You got it: Up to you
69
2D Geometric Transformations
70. 10/5/2022 7
0
Mirror
Plane* => Negate the corresponding coordinate
Mirror through Line* => Reflect through 2 planes intersecting at the axis
Point* => Reflect through 3 planes intersecting at the point
* plane - principal plane, line - X, Y, or Z axes, point - CS origin
P* = [M]P,
where [M] = =
Question: Define the signs (in the matrix)
for the reflections (mirroring) through:
a) x = 0, y = 0, z = 0 planes
b) X, Y, and Z axes
c) the CS origin
33
22
11
0
0
0
0
0
0
m
m
m
1
0
0
0
1
0
0
0
1
71. Reversing the order
in which a sequence of transformations is performed may affect the transformed
position of an object.
In (a), an object is first translated in the x direction, then rotated counterclockwise
through an angle of 45°.
In (b), the object is first rotated 45° counterclockwise, then translated in the x
direction
71
2D Geometric Transformations
72. Other 2D Transformations
Reflection
Transformation that produces a mirror image of an
object
72
2D Geometric Transformations
73. Reflection
Image is generated relative to an axis of reflection
by rotating the object 180° about the reflection
axis
Reflection about the line y=0 (the x axis) (previous
slide)
1
0
0
0
1
0
0
0
1
Other 2D Transformations (cont.)
73
2D Geometric Transformations
74. Other 2D Transformations (cont.)
Reflection
Reflection about the line x=0 (the y axis)
1
0
0
0
1
0
0
0
1
74
2D Geometric Transformations
75. −1 0 0
0 − 1 0
0 0 1
Reflection about the origin
Other 2D Transformations (cont.)
75
2D Geometric Transformations
76. Reflection about the line y=x
0 1 0
1 0 0
0 0 1
Other 2D Transformations (cont.)
76
2D Geometric Transformations
77. Reflection about the line y=-x
0 − 1 0
−1 0 0
0 0 1
Other 2D Transformations (cont.)
77
2D Geometric Transformations
78. Shear
Transformation that distorts the shape of an object
such that the transformed shape appears as the
object was composed of internal layers that had
been caused to slide over each other
y
x
(0,1) (1,1)
(1,0)
(0,0)
y
x
(2,1) (3,1)
(1,0)
(0,0)
shx=2
Other 2D Transformations (cont.)
78
2D Geometric Transformations
79. Shear
An x-direction shear relative to the x axis
An y-direction shear relative to the y axis
1
0
0
0
1
0
0
1
y
sh
1
0
0
0
1
0
0
1 x
sh
y
y
y
sh
x
x x
'
'
Other 2D Transformations (cont.)
79
2D Geometric Transformations
80. Shear
x-direction shear relative to other reference lines
1
0
0
0
1
0
*
1 ref
x
x y
sh
sh
y
y
y
y
sh
x
x ref
x
'
*
'
Other 2D Transformations (cont.)
80
2D Geometric Transformations
81. Example
A unit square (a) is transformed to a shifted parallelogram
(b) with shx = 0.5 and yref = −1 in the shear matrix from Slide 56
81
2D Geometric Transformations
82. Shear
y-direction shear relative to the line x = xref
1
0
0
*
1
0
0
1
ref
y
y x
sh
sh
ref
y x
x
sh
x
y
x
x
*
'
'
Other 2D Transformations (cont.)
82
2D Geometric Transformations
83. Example
A unit square (a) is turned into a shifted parallelogram
(b) with parameter values shy = 0.5 and xref = −1 in the y -direction shearing
transformation from Slide 58
83
2D Geometric Transformations
84. This slide is intentionally left blank
Your responsibility to fill it
Raster Methods for
Transformations and OpenGL
84
2D Geometric Transformations
85. Transformation Between
Coordinate Systems
Individual objects may be defined in their
local cartesian reference system.
The local coordinates must be transformed
to position the objects within the scene
coordinate system.
85
2D Geometric Transformations
86. Steps for coordinate transformation
1. Translate so that the origin (x0, y0 ) of the
x′-y′ system is moved to the origin of the
x-y system.
2.Rotate the x′ axis on to the axis x.
Transformation Between
Coordinate Systems
86
2D Geometric Transformations
91. An alternative method:
-Specify a vector V that indicates the direction
for the positive y′ axis. Let
-Obtain the unit vector u=(ux ,u y) along the x′
axis by rotating v 900 clockwise.
𝐯 =
𝐕
𝐕
= (𝑣𝑥, 𝑣𝑦)
Transformation Between
Coordinate Systems (cont.)
91
2D Geometric Transformations
92. Elements of any rotation matrix can be
expressed as elements of orthogonal unit
vectors. That is, the rotation matrix can be
written as
𝐑 =
𝑢𝑥 𝑢𝑦 0
𝑣𝑥 𝑣𝑦 0
0 0 1
Transformation Between
Coordinate Systems (cont.)
92
2D Geometric Transformations
94. OpenGL Geometric
Transformation Functions
A separate function is available for each of the
basic geometric transformations
AND
All transformations are specified in three
dimensions
Why?
Answer: Remember; OpenGL was developed as
3D library
But how to perform 2D transformations?
Answer: Set z = 0
94
2D Geometric Transformations
95. Basic OpenGL Geometric
Transformations
Translation
glTranslate* (tx, ty, tz);
* is either f or d
tx, ty and tz are any real number
For 2D, set tz=0.0
Rotation
glRotate* (theta, vx, vy, vz);
* is either f or d
theta is rotation angle in degrees (internally converted to
radian)
Vector v=(vx, vy, vz) defines the orientation for a rotation axis
that passes through the coordinate origin
For 2D, set vz=1.0 and vx=vy=0.0
95
2D Geometric Transformations
96. Basic OpenGL Geometric
Transformations (cont.)
Scaling
glScale* (sx, sy, sz);
* is either f or d
sx, sy and sz are any real number
Negative values generate reflection
Zero values can cause error because inverse matrix
cannot be calculated
All routines construct a 4x4 transformation
matrix
OpenGL uses composite matrices
Be careful with the order 96
2D Geometric Transformations
97. OpenGL Matrix Operations
glMatrixMode(.);
Projection Mode: Determines how the scene is
projected onto the screen
Modelview Mode: Used for storing and combining
geometric transformations
Texture Mode: Used for mapping texture patterns
to surfaces
Color Mode: Used to convert from one color mode
to another
97
2D Geometric Transformations
98. OpenGL Matrix Operations
Modelview matrix, used to store and combine
geometric transformations
glMatrixMode(GL_MODELVIEW);
A call to a transformation routine generates a
matrix that is multiplied by the current matrix
To assign the identity matrix to the current
matrix
glLoadIdentity();
98
2D Geometric Transformations
99. OpenGL Matrix Operations
(cont.)
Alternatively:
glLoadMatrix* (elements16);
To assign other values to the elements of the
current matrix
In column-major order:
First four elements in first column
Second four elements in second column
Third four elements in third column
Fourth four elements in fourth column
99
2D Geometric Transformations
100. OpenGL Matrix Operations
(cont.)
Concatenating a specified matrix with current
matrix:
glMultMatrix* (otherElements16);
Current matrix is postmultiplied (right-to-left) by
the specified matrix
Warning:
Matrix notation mjk means:
In OpenGL: j column, k row
In mathematics: j row, k column
100
2D Geometric Transformations
101. OpenGL Matrix Stacks
OpenGL maintains a matrix stack for
transformations
Initially the modelview stack contains only the
identity matrix
More about it:
Coming soon
101
2D Geometric Transformations
102. OpenGL Transformation Routines
For example, assume we want to do in the following
order:
translate by +2, -3, +4,
rotate by 450 around axis formed between origin and 1, 1, 1
scale with respect to the origin by 2 in each direction.
Our code would be
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); //start with identity
glScalef(2.0,2.0,2.0); //Note: Start with the LAST operation
glRotatef(45.0,1.0,1.0,1.0);
glTranslatef(2.0,-3.0, 4.0); //End with the FIRST operation
102
2D Geometric Transformations
105. References
Donald Hearn, M. Pauline Baker, Warren R.
Carithers, “Computer Graphics with OpenGL, 4th
Edition”; Pearson, 2011
Sumanta Guha, “Computer Graphics Through
OpenGL: From Theory to Experiments”, CRC Press,
2010
Edward Angel, “Interactive Computer Graphics. A
Top-Down Approach Using OpenGL”, Addison-
Wesley, 2005
105
106. Ex. 1: Rotation of object about arbitrary point P (x, y) by θ
> Translate point (x, y) to origin
by (-x, -y)
> Rotate by θ
> Translate the point by (x, y)
109. 3 D - Rigid body transformations
Methods for object modeling transformation in three dimensions
are extended from two dimensional methods by including
consideration for the z coordinate.
Preserve lines, angles and distances.
# Generalize from 2D by including z
coordinate
# Straight forward for translation and
scale
# Rotation more difficult
# Homogeneous coordinates: 4
components
# Transformation matrices: 4×4
éléments.
110. 3D Point:
We will consider points as column vectors.
Thus, a typical point with coordinates (x, y, z) is
represented as:
3D Point Homogenous Coordinate:
A 3D point P is represented in homogeneous
coordinates by a 4-dim, Vector.
We don't lose anything.
The main advantage: it is easier to compose
translation and rotation.
Everything is matrix multiplication.
111. i. 3D Translation
In homogeneous coordinates, 3D transformations are represented by
4×4 matrixes:.
P is translated to P' by:
An object is translated in 3D
dimensional by transforming
each of the defining points of
the objects .
112. Cont’d…
# An object represented as a set of polygon surfaces, is translated by
translate each vertex of each surface and redraw the polygon
facets in the new position.
113. ii. 3D Rotation
In general, rotations are specified by a rotation axis and an angle.
In two-dimensions there is only one choice of a rotation axis that leaves
points in the plane.
The easiest rotation axes are those that parallel to the coordinate axis.
Positive rotation angles produce counterclockwise rotations about a
coordinate axis, if we are looking along the positive half of the axis
toward the coordinate origin.
119. iV. 3D Reflections
About an axis: equivalent to 180°rotation about that axis.
About a plane: A reflection through the xy plane.
A reflections through the xz and the yz planes are defined
similarly.
120. Exercise
You sat in the car, and find the side mirror 40mm on your
right and 30mm in your front. You started your car and drove
200mm forward, turned 30 degrees to right, moved 200mm
forward again, and turned 45 degrees to the right, and
stopped.
What is the position of the side mirror now, relative to where
you were sitting in the beginning?
121. Solution
# The side mirror position is locally (40, 30).
# The matrix of first driving forward 200mm is:
122. Cont’d…
The matrix to turn to the right 30 deg and 45 degrees
(rotating -30 and -45 degrees about the origin) are:
The 3rd transformation is moving
by 200mm along an axis oriented 60
degree with the x-axis.