Professional Documents
Culture Documents
Chap 3
Chap 3
GEOMETRIC TRANSFORMATIONS
B. Boufama
University of Windsor
Chapter III: Two-Dimensional Geometric Transformations
Introduction
B. Boufama 1
Chapter III: Two-Dimensional Geometric Transformations
Translation
A translation is a geometric transformation that
moves an object along a straight-line path from
one location to another.
A point is translated by adding the vector
coordinates of translation.
Example :
a point at location (x, y), when translated with
T~ = (tx, ty ), will move the location (x0, y 0) where
x0 = x + tx
y 0 = y + ty
We can also write the above relation as
0
x x tx
0
=
+
y y ty
That is,
p0 = p + T
B. Boufama 2
Chapter III: Two-Dimensional Geometric Transformations
B. Boufama 3
Chapter III: Two-Dimensional Geometric Transformations
B. Boufama 4
Chapter III: Two-Dimensional Geometric Transformations
Rotation
B. Boufama 5
Chapter III: Two-Dimensional Geometric Transformations
B. Boufama 6
Chapter III: Two-Dimensional Geometric Transformations
B. Boufama 8
Chapter III: Two-Dimensional Geometric Transformations
B. Boufama 9
Chapter III: Two-Dimensional Geometric Transformations
Scaling
Or
P0 = S · P
A uniform scaling is obtained when, sx = sy ,
B. Boufama 10
Chapter III: Two-Dimensional Geometric Transformations
B. Boufama 11
Chapter III: Two-Dimensional Geometric Transformations
0s 0 xf − xf · s
P = P +
0 s yf − yf · s
B. Boufama 12
Chapter III: Two-Dimensional Geometric Transformations
The representation
P 0 = M1 · P + M2
can be used for any basic transformation:
• Translation : M1 is the identity matrix and M2 is the
translation vector.
• Rotation : M1 is the rotation with respect to the
origin and M2 is the translational component
resulting from the position of the rotation axis.
• Scaling : M1 is the scaling matrix while M2 is the
translational component resulting from the position
of the fixed point.
Question:
Can we combine the 2 × 2 matrix M1 with the
2-element column vector M2 into one single 2 × 3
matrix M ?
B. Boufama 13
Chapter III: Two-Dimensional Geometric Transformations
B. Boufama 14
Chapter III: Two-Dimensional Geometric Transformations
• Rotation:
0
x cos θ − sin θ 0 x
0 0
y = sin θ cos θ 0 y That is P = R · P
1 0 0 1 1
• Scaling:
0
x sx 0 0 x
y 0 = 0 sy 0 y That is P 0 = S · P
1 0 0 1 1
B. Boufama 15
Chapter III: Two-Dimensional Geometric Transformations
Composite transformations
B. Boufama 16
Chapter III: Two-Dimensional Geometric Transformations
cos(θ1 + θ2) − sin(θ1 + θ2) 0
= sin(θ1 + θ2) cos(θ1 + θ2) 0
0 0 1
B. Boufama 17
Chapter III: Two-Dimensional Geometric Transformations
B. Boufama 18
Chapter III: Two-Dimensional Geometric Transformations
General rotations
B. Boufama 19
Chapter III: Two-Dimensional Geometric Transformations
B. Boufama 20
Chapter III: Two-Dimensional Geometric Transformations
cos θ − sin θ xr (1 − cos θ) + yr sin θ
sin θ cos θ yr (1 − cos θ) − xr sin θ
0 0 1
B. Boufama 21
Chapter III: Two-Dimensional Geometric Transformations
B. Boufama 22
Chapter III: Two-Dimensional Geometric Transformations
Expanding it yields
1 0 xf sx 0 0 1 0 −xf
0 1 yf · 0 sy 0 · 0 1 −yf =
0 0 1 0 0 1 0 0 1
sx 0 xf (1 − sx)
0 sy yf (1 − sy ) = S(xf , yf , sx, sy )
0 0 1
B. Boufama 23
Chapter III: Two-Dimensional Geometric Transformations
Where,
0
x x
0
y = M · y
1 1
B. Boufama 25
Chapter III: Two-Dimensional Geometric Transformations
B. Boufama 26
Chapter III: Two-Dimensional Geometric Transformations
B. Boufama 27
Chapter III: Two-Dimensional Geometric Transformations
B. Boufama 28
Chapter III: Two-Dimensional Geometric Transformations
Affine transformation
B. Boufama 29
Chapter III: Two-Dimensional Geometric Transformations
B. Boufama 30
Chapter III: Two-Dimensional Geometric Transformations
B. Boufama 31
Chapter III: Two-Dimensional Geometric Transformations
B. Boufama 32
Chapter III: Two-Dimensional Geometric Transformations
Examples:
• Empty polygon :
glBegin(GL_LINE_LOOP);
glVertex2i(100, 100);
glVertex2i(200, 100);
glVertex2i(250, 200);
glVertex2i(200, 300);
glEnd();
• Two lines :
glBegin(GL_LINES);
glVertex2i(100, 100);
glVertex2i(200, 100);
glVertex2i(250, 200);
glVertex2i(200, 300);
glEnd();
B. Boufama 33
Chapter III: Two-Dimensional Geometric Transformations
GLint pol[8][2] ={{150, 50}, {200, 50}, {250, 100}, {250, 150}, {200, 200},
{150, 200}, {100, 150}, {100, 100}};
// The centroid of these 8 points is : (175, 125)
tx=ty=angle=moving=0;
glutMainLoop(); //infinite loop
}
void displayFunc(void){
int i;
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
gluOrtho2D(0.0,640.0,0.0,480.0);
glBegin(GL_POLYGON); // glBegin(GL_LINE_LOOP);
for(i=0; i<8; i++)
glVertex2i(pol[i][0], pol[i][1]);
glEnd();
glFlush();
}
B. Boufama 35
Chapter III: Two-Dimensional Geometric Transformations
angle= (angle+3)%360;
displayFunc();
glutTimerFunc(100, timer, v);
}
B. Boufama 36
Chapter III: Two-Dimensional Geometric Transformations
B. Boufama 37
Chapter III: Two-Dimensional Geometric Transformations
Summary
B. Boufama 38