CG 3
CG 3
CG 3
This transformation can also be described as a rotation about a rotation axis that is perpendicular
to the xy plane and passes through the pivot point.
Transformation equation for rotating a point (x, y) through an angle θ about the origin is:
x' = x cos θ – y sin θ
y' = x sin θ + y cos θ
Bekretsyon B Page 1
2D Transformations
Objects transformed with scaling equation are both scaled and repositioned. Scaling factors with
values less than 1 move objects closer to the coordinate origin, while values greater than 1 move
coordinate positions farther from the origin.
We can control the location of a scaled object by choosing a position, called the fixed point-that
is to remain unchanged after the scaling. Coordinates for the fixed point (xf, yf) can be chosen as
Bekretsyon B Page 2
2D Transformations
one of the vertices, the object centroid, or any other position. A polygon is then scaled relative to
the fixed point by scaling the distance from each vertex to the fixed point. For a vertex with
coordinates (x, y), the scaled coordinates (x', y ') are calculated as:
We can combine the multiplicative and translational terms for two-dimensional geometric
transformations into a single matrix representation by expanding the 2 by 2 matrix
representations to 3 by 3 matrices. This allows us to express all transformation equations as
matrix multiplications, providing that we also expand the matrix representations for coordinate
positions.
Bekretsyon B Page 3
2D Transformations
Thus, a general homogeneous coordinate representation can also be written as (h.x, h.y, h)
For two-dimensional geometric transformations, we can choose the homogenous parameter h to
be any nonzero value. A convenient choice is simply to set h = 1. Each two-dimensional position
is then represented with homogeneous coordinates (x, y, 1).
Coordinates are represented with three-element row vectors, and transformation operations are
written as 3 by 3 matrices
For translation, we have:
1 0 0
[x , y , 1] = [𝑥, 𝑦, 1] [ 0
′ ′ 1 0]
𝑡𝑥 𝑡𝑦 1
Similarly, rotation transformation equations about the coordinate origin are now written as:
𝑐𝑜𝑠𝜃 𝑠𝑖𝑛𝜃 0
[x ′ , y ′ , 1] = [x, y, 1] [− 𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃 0]
0 0 1
A scaling transformation relative to the coordinate origin is now expressed as the matrix
multiplication
𝑠𝑥 0 0
[x ′ , y ′ , 1] = [x, y, 1] [ 0 𝑠𝑦 0]
0 0 1
If, for example, we want to translate, rotate and scale an object (in that order), we can combine
the matrices to form a single transformation matrix:
𝑀𝑇𝐹 = 𝑀𝑇𝐿 × 𝑀𝑅𝑇 × 𝑀𝑆𝑐
Which gives an overall transformation matrix of the form:
𝑎 𝑑 0
[𝑏 𝑒 0]
𝑐 𝑓 1
𝑎 𝑑
Where the matrix [ ] is for rotation, the diagonal (a e) for scaling and (c f) for translation.
𝑏 𝑒
Matrix representations are standard methods for implementing transformations in graphics
systems.
Examples
1. Given a square with vertices at p1 = (10, 15), p2 = (15, 15), p3 = (15, 20) and p4 = (10, 20).
Translate the points by (10, 5) using translation matrix.
Bekretsyon B Page 4
2D Transformations
Solution:
1 0 0
Tx = 10, Ty = 5 => 𝑀𝑇𝐿 = ( 0 1 0)
10 5 1
1 0 0
P1 = (10, 15)=> (10 15 1) ( 0 1 0) = (20 20 1) => 𝑃1′ = (20 20 )
10 5 1
1 0 0
P2 = (15, 15)=> (15 15 1) ( 0 1 0) = (25 20 1) => 𝑃2′ = (25 20 )
10 5 1
1 0 0
P3 = (15, 20)=> (15 20 1) ( 0 1 0) = (25 25 1) => 𝑃3′ = (25 25 )
10 5 1
1 0 0
P4 = (10, 20)=> (10 20 1) ( 0 1 0) = (20 25 1) => 𝑃4′ = (20 25 )
10 5 1
2. A square is given by p1 = (20, 20), p2 =(20, 40), p3 = (40, 20) and p4 = (40, 40). Scale the
square relative to the origin where sx = 1.5 and sy = 2.
Solution
1.5 0 0
𝑀𝑆𝐶 = ( 0 2 0)
0 0 1
1.5 0 0
P1 = (20, 20)=> (20 20 1) ( 0 2 0) = (30 40 1) => 𝑃1′ = (30 40 )
0 0 1
Similarly compute 𝑃2′ , 𝑃3′ 𝑎𝑛𝑑 𝑃4′
3. Use the square and scaling factor of question 2 to scale about a fixed point (xf, yf) = (20, 20).
Solution
1 0 0
Step 1. Translate to the origin by (xf, yf): 𝑀𝑇𝐿1 = ( 0 1 0)
−20 −20 1
1.5 0 0
Step 2. Scale the object: 𝑀𝑆𝐶 = ( 0 2 0)
0 0 1
1 0 0
Step 3. Translate back by (xf, yf): 𝑀𝑇𝐿2 = ( 0 1 0)
20 20 1
Then
1 0 0 1.5 0 0 1 0 0 1.5 0 0
𝑀𝑇𝐹 = ( 0 1 0) ∗ ( 0 2 0) ∗ ( 0 1 0) = ( 0 2 0)
−20 −20 1 0 0 1 20 20 1 −10 −20 1
Bekretsyon B Page 5
2D Transformations
1.5 0 0
P1 = (20, 20)=> (20 20 1) ( 0 2 0) = (20 20 1) => 𝑃1′ = (20 20 )
−10 −20 1
Similarly compute 𝑃2′ , 𝑃3′ 𝑎𝑛𝑑 𝑃4′
4. A square has corners (10, 10), (10, 20), (20, 10) and (20, 20). Rotate the square about the
origin by 370 in the anti-clockwise direction.
Solution
cos 37 𝑠𝑖𝑛37 0 0.8 0.6 0
𝑀𝑅𝑇 = [− 𝑠𝑖𝑛37 cos 37 0] = [−0.6 0.8 0]
0 0 1 0 0 1
0.8 0.6 0
P1 = (10, 10)=> (10 10 1) (−0.6 0.8 0) = (2 14 1) => 𝑃1′ = (2 14 )
0 0 1
0.8 0.6 0
P2 = (10, 20)=> (10 20 1) (−0.6 0.8 0) = (−4 22 1) => 𝑃2′ = (−4 22 )
0 0 1
Similarly compute 𝑃3′ 𝑎𝑛𝑑 𝑃4′
3.3 Other Transformations
1) Reflection
A reflection is a transformation that produces a mirror image of an object. The mirror image for a
two-dimensional reflection is generated relative to an axis of reflection by rotating the object
1800 about the reflection axis. We can choose an axis of reflection in the xy plane or
perpendicular to the xy plane. When the reflection axis is a line in the xy plane, the rotation path
about this axis is in a plane perpendicular to the xy plane. For reflection axes that are
perpendicular to the xy plane, the rotation path is in the xy plane.
Reflection about the line y = 0, the x axis, is accomplished with the transformation matrix:
1 0 0
[0 −1 0]
0 0 1
This transformation keeps x values the same but flips the y values of coordinate positions. The
resulting orientation of an object after it has been reflected about the x axis is shown below
Bekretsyon B Page 6
2D Transformations
A reflection about the y axis flips x coordinates while keeping y coordinates the same. The
matrix for this transformation is:
−1 0 0
[0 1 0]
0 0 1
The resulting orientation of an object after it has been reflected about the y axis (line x =0) is:
Reflections about any line y = mx + b in the xy plane can be accomplished with a combination of
translate- rotate-reflect transformation.
In general, we first translate the line so that it passes through the origin. Then we can rotate the
line onto one of the coordinate axes and reflect about that axis. Finally, we restore the line to its
original position with the inverse rotation and translation transformations
2) Shear
A transformation that distorts the shape of an object is called a shear. Two common shearing
transformations are those that shift coordinate x values and those that shift y values.
An x-direction shear relative to the x axis is produced with the transformation matrix
Bekretsyon B Page 7
2D Transformations
1 𝑠ℎ𝑥 0
[1 1 0]
0 0 1
which transforms coordinate positions as
x' = x + shx y, y' = y
Any real number can be assigned to the shear parameter shx . A coordinate position (x, y) is then
shifted horizontally by an amount proportional to its distance (y value) from the x axis (y = 0).
Setting shx to 2, for example, changes the square into a parallelogram as shown below.
A y-direction shear relative to the line x = xref is generated with the transformation matrix
1 0 0
[𝑠ℎ𝑦 1 −𝑠ℎ𝑦 ∙ 𝑥𝑟𝑒𝑓 ]
0 0 1
which generates coordinate positions
x' = x, y' = shy (x – xref) + y
Bekretsyon B Page 8
2D Transformations
This transformation shifts coordinate position vertically by an amount proportional to its distance
from the reference line x = xref
The following figure illustrates the conversion of a square into parallelogram with shy = ½ and
xref = -1
Summary Questions
A. Fill in the blank space
1. _______ is a change of object position.
2. The translation distance pair (tx, ty) is called ______________.
3. _______ is a change of orientation of an object.
4. As translation vector is to translation _________ is to rotation and _______ to scaling.
5. _________ is a transformation that produces a mirror image of an object.
B. Say true or false
1. Translations and rotations are rigid-body transformations that move objects without deformation.
2. Negative values for the rotation angle define counterclockwise rotations about the pivot point.
3. Objects transformed with scaling are both scaled and repositioned.
4. A transformation that distorts the shape of an object is called reflection.
5. To translate or rotate a polygon just translate or rotate the vertices and redraw the polygon in the new
location.
C. Answer Accordingly
1. Write a program that translates a triangle its vertices are at coordinates (0, 0),(320, 200) and (150,
200) with translation vector (50, 40).
2. Write a program that rotates the triangle of question 1 by 450 degree about point (200, 200).
3. Write a program that scales the triangle of question 1 by factor (0.5, 0.5)
4. Write a program to continuously rotate an object about a pivot point.
5. Using lines, rectangle and circle write a program that draws 2D house translate, scale it by any value.
6. Write a program draws a square and rotates when a key is pressed. Again when a key is pressed it
translates.
7. Write a program that reflects the triangle you created in question 1 about y = x.
8. Create a rectangle with vertices (270,340), (270, 140), (370, 140) and (370, 340). Shear the rectangle
relative to line y = 140 with shear parameter shx = 2.
9. Given a pivot point (10, 10) and rotation angle 370 find the overall rotating matrix.
Bekretsyon B Page 9
2D Transformations
10. Write a C++ program that performs a 53 clockwise rotation on a rectangle described by coordinates
(30, 30), (130, 30), (130, 90), (30, 90) about the point(80, 60) and then draws the object. Use two
functions in your program; one to perform the rotation and the other to draw the rotated object.
11. Magnify a triangle with vertices (1, 1), (4, 1) and (2, 3) to twice its size while keeping the vertex (2,3)
fixed.
Answers to Summary Questions
A. 1. Translation 2. Translation/Shift vector 3. Rotation 4. Rotation/Pivot point, Scaling factor 5.
Reflection
B. 1. True 2. False 3. True 4. False 5. True
Bekretsyon B Page 10