6 2023 11 18!11 57 55 PM
6 2023 11 18!11 57 55 PM
Each point P(X,Y) which is to be moved by TX unites parallel to the X-axis and by
TY units parallel to the Y-axis to the new point P2(X2,Y2) we use the equations:
X2 = X + TX
Y2 = Y + TY
1 0 0
0 1 0
TX TY 1
Example 1:
Move the line (5, 5) , (20, 5) , 7 units in the X direction and 5 units in the Y direction.
The solve 2: 1 0 0
TX=7 , TY=5 X1 new Y1 new 1 5 5 1
X2 new Y2 new 1 = 20 5 1 * 0 1 0
7 5 1
12 10 1
27 10 1
X1 new = 12 Y1 new = 10
X2 new = 27 Y2 new = 10
Example 2:
Move the rectangle (1, 1) , (5, 1) ,(3,5) with 6 units in the X direction and 4 units in the
Y direction.
First point Second point Third point
The solve 1: X1 new= 1 + 6 = 7 X2 new= 5 + 6 = 11 X3 new= 3 + 6 = 9
TX=6 , TY=4 Y1 new= 1 + 4 = 5 Y2 new= 1 + 4 = 5 Y3 new= 5 + 4 = 9
7 5 1
11 5 1
9 9 1
X1 new = 7 Y1 new = 5
X2 new = 11 Y2 new = 5
X3 new = 9 Y3 new = 9
Scaling
Scaling is the process of expanding or compressing the dimensions of an object
(changing the size of an object). The size of an object can be change by multiplying the
points of an object by scaling factor.
SX 0 0
By using the matrix representation
0 SY 0
0 0 1 SX 0 0
X new Y new 1 X Y 1 0 SY 0
= *
0 0 1
Example 3:
Scale the rectangle (12, 4), (20, 4), (20, 8), (12, 8) with SX=2, SY=2.
The solve 1: SX=2 , SY=2
for the point (12, 4) for the point (20,4)
X1 new= 12*SX= 12*2=24 X2 new= 20*SX= 20*2= 40
Y1 new= 4 *SY= 4*2=8 Y2 new= 4 * SY= 4*2=8
The solve 2 :
X1 new Y1 new 1 12 4 1
2 0 0
X2 new Y2 new 1 20 4 1
0 2 0
X3 new Y3 new 1
=
12 8 1 *
0 0 1
X4 new Y4 new 1 20 8 1
Rectangle after scaling
24 8 1
= 40 8 1
24 16 1 • If SF (scale factor) > 1 then
the object is enlarged
40 16 1
Example 4:
Scale the rectangle (12, 4), (20, 4), (20, 8), (12, 8) with SX=0.5, SY=0.5.
The solve 1: SX=0.5 , SY=0.5
for the point (12, 4) for the point (20,4)
X1 new= 12*SX= 12*0.5=6 X2 new= 20*SX= 20*0.5= 10
Y1 new= 4 *SY= 4*0.5=2 Y2 new= 4 * SY= 4*0.5=2
The solve 2 :
Original rectangle
X1 new Y1 new 1 12 4 1
0.5 0 0
X2 new Y2 new 1 20 4 1
= * 0 0.5 0
X3 new Y3 new 1 12 8 1
0 0 1
X4 new Y4 new 1 20 8 1
6 2 1
Rectangle after scaling
= 10 2 1
6 4 1 • If SF (scale factor) < 1 then
10 4 1 the object is compressed
Notice that after a scaling transformation is performed, the new object is
located at a different position relative to the origin.
In fact, in scaling transformation, the only point that remains fixed is the
origin.
If we want to let one point of an object that remains at the same location
(fixed), scaling can be performed by three steps:
1. Translate the fixed point to the origin, and all the points of the object must
be moved the same distance and direction that the fixed point moves.
2. Scale the translated object from step one
3. Back translate the scaled object to its original position
Example 5:
Scale the rectangle (12,4),(20,4),(12,8),(20,8) with SX=2, SY=2 so the point (12,4) being
the fixed point.
The solve:
1- Translate the object with TX= -12 and TY= -4 X2=X+TX
so the point (12,4) lies on the origin Y2=Y+TY
X2=X+TX
Y2=Y+TY
for the point (0, 0) for the point (0, 8)
X1 new= 0+TX= 0 + 12= 12 X3 new= 0+TX= 0+12= 12
Y1 new= 0 +TY= 0 +4 = 4 Y3 new= 8 +TY= 8+4= 12
1 2 3
Rotation
Another useful transformation is the rotation of an object about specified
pivot point. In rotation, the object is rotated Ǿ about the origin.
The convention is that :
1- The direction of rotation is counterclockwise if Ǿ is a positive angle
2- The direction of rotation is clockwise if Ǿ is a negative angle.
The rotation matrix to rotate an object about the origin in an anticlockwise direction is:
0 1 0
Sin (90) = 1
When Ǿ =90 -1 0 0
Cos (90) = 0
0 0 1
Sin (180) = 0 -1 0 0
When Ǿ =180 0 -1 0
Cos (180) = -1
0 0 1
0 -1 0
When Ǿ =270 Sin (270) = -1
1 0 0
Cos (270) = 0
0 0 1
Sin (360) = 0 1 0 0
When Ǿ =360
Cos (360) = 1 0 1 0
0 0 1
Example 6:
Rotate the line P1 (1, 6) and P2 (5, 1) anticlockwise 90 degree.
The solve 1: 𝑿𝒏𝒆𝒘 = 𝑿 ∗ 𝐂𝐨𝐬 𝜽 − 𝒀 ∗ 𝐒𝐢𝐧 𝜽
𝒀𝒏𝒆𝒘 = 𝒀 ∗ 𝐂𝐨𝐬 𝜽 + 𝑿 ∗ 𝐒𝐢𝐧 𝜽
The solve 2:
0 1 0
X1 new Y1 new 1 1 6 1
= * -1 0 0
X2 new Y2 new 1 5 1 1
0 0 1
-6 1 1
=
-1 5 1
Example 7:
Rotate the line P1 (1, 6) and P2 (5, 1) in clockwise (-90) degree.
0 -1 0
X1 new Y1 new 1 1 6 1
= * 1 0 0
X2 new Y2 new 1 5 1 1
0 0 1
6 -1 1
=
1 -5 1
2- Rotate the translated point (and the translated object) by Ǿ degree about
the origin to obtain the new point (XP2,YP2)
3- Back translation
XP3= XP2 + XP
YP3= YP2 + YP
Example 7:
Rotate the rectangle (3, 2),(6, 2),(3, 4),(6, 4) counterclockwise with Ǿ =90 around
the point (3,2).
1 2 3
Reflection
The solve:
A- X axis
1 0 0
X1 new Y1 new 1 3 2 1 0 -1 0 = 3 -2 1
= *
0 0 1
B- Y axis -1 0 0
X1 new Y1 new 1 3 2 1 0 1 0
= * = -3 2 1
0 0 1
C- Origin -1 0 0
X1 new Y1 new 1 3 2 1 0 -1 0 = -3 -2 1
= *
0 0 1
D- Line Y=X 0 1 0
1 0 0
X1 new Y1 new 1 3 2 1 = 2 3 1
= * 0 0 1
Home work
1- The solve:
Xnew = X
Ynew = -Y
2- The solve:
X1 new Y1 new 1 2 4 1 1 0 0
X2 new Y2 new 1 = 4 6 1 * 0 -1 0
X3 new Y3 new 1 2 6 1 0 0 1
2 -4 1
= 4 -6 1
2 -6 1
Example 10 :
Reflect the triangle with vertices at A(2, 4), B(4, 6), C(2, 6) in : Y axis;
1- The solve
(-x, +y )
Xnew = - X
Ynew = Y
2- The solve
X1 new Y1 new 1 2 4 1 -1 0 0
X2 new Y2 new 1 = 4 6 1 * 0 1 0
X3 new Y3 new 1 2 6 1 0 0 1
-2 4 1
= -4 6 1
-2 6 1
Reflection on an arbitrary line
To reflect an object on a line that does not pass through the origin, which is
the general case:
As shown in the figure, let the line L intercept with Y axis in the point (0,K)
and have an angle of inclination Ǿ degree with respect to the positive
direction of X axis .
Cos θ -Sin θ 0
2. Rotate all the points through (-Ǿ) degree about R= Sin θ Cos θ 0
the origin making L lie along the X-axis 0 0 1
1 0 0
3. Reflect the point P1 on the X-axis R efX= 0 -1 0
0 0 1
Cos θ Sin θ 0
4. Rotate back the points by (Ǿ) degree so that L R -1 = -Sin θ Cos θ 0
back to its original orientation
0 0 1
1 0 0
5. Shift in the direction of Y axis so that L is T-1 = 0 1 0
back in its original position
0 k 1
The sequence of matrices needed to Cos 2Ǿ Sin 2Ǿ 0
perform this non-standard reflection is:
S= Sin 2Ǿ -Cos 2Ǿ 0
S=T * R * RefX * R -1 * T -1 -K Sin 2Ǿ K+K Cos 2Ǿ 1
Example 11 :
Find the single matrix that causes all the points in the plane to be reflected in the
line with equation Y=0.5X+2 , then apply this matrix to reflect the triangle with
vertices at A(2, 4), B(4, 6), C(2, 6) in the line.
The solve
The Cartesian equation of a line in 2D is y= m * x +b
where b is the intersection of the lint with the Y-axis
and m is gradient of the line m= Δy / Δx = Tan Ǿ
Y shearing moves a vertical line up or down depending on the sign of the shear
factor Shy. A horizontal line is distorted into a line with slop Shy. And vis versa.
2- X- shearing
It transforms the point (X, Y) to the point (Xnew , Ynew) where
1 3 1
3 7 1
=
1 5 1
3 9 1
Example 12:
Share the object (1,1) , (3,1) , (1,3) , (3,3) with Shx=2.
The solve 1: Shx=2
Xnew = X + Shx * Y Point (1,1) Point (3,1)
Ynew = Y X1new = 1 +2*1 =3 X2new = 3 +2*1 =5
Y1new = 1 Y2new = 1
Point (1,3) Point (3,3)
X3new = 1 +2*3 =7 X3new = 3 +2*3 =9
Ynew = 3 Ynew = 3
X1 new Y1 new 1 1 1 1
1 0 0
X2 new Y2 new 1 3 1 1
= 2 1 0
X3 new Y3 new 1 1 3 1 * 0 0 1
X3 new Y3 new 1 3 3 1
3 1 1
5 1 1
=
7 3 1
9 3 1
Spatial Transformations
1- Affine Transformation
A coordinate transformation of the form:
ഥ=𝒂𝒙𝒙 𝒙 + 𝒂𝒙𝒚 𝒚 + 𝒃𝒙
𝒙
ഥ=𝒂𝒚𝒙 𝒙 + 𝒂𝒚𝒚 𝒚 + 𝒃𝒚
𝒚
Is called a two-dimensional affine transformation.
Each of the transformed coordinates x and y is a linear function of the
original coordinates x and y, and parameters and are constants determined
by the transformation type.
Affine transformations have the general properties that the
1. Straight lines remain straight.
2. Parallel lines remain parallel.
3. Rectangles might become parallelograms.
These transformations include translation, rotation, and scaling.
M.1 M.N
ഥ= −𝟏 ∗ 𝒙 + 𝟎 ∗ 𝒚 + 𝟎
𝒙 ഥ=𝟎 ∗ 𝒙 + 𝟐 ∗ 𝒚 + (−𝟐)
𝒚
ഥ=−𝒙
𝒙 ഥ=𝟐𝒚 − 𝟐
𝒚
−𝟏 𝟎 𝟎
𝒙′ 𝒚′ 𝟏 = 𝒙 𝒚 𝟏 𝟎 𝟐 𝟎
𝟎 −𝟐 𝟏
2- Projective transformation
This type of geometric transformation also includes translation, rotation, and
scaling.
In these transformations the straight lines remain straight but parallel lines
converge towards the vanishing points.
This type of transformation needs four points, as shown in the below figure.
1,2 2,2
The projective transformations.
The solid line represented the input
-0.2,1.8 2.2,1.8
quadrilateral
while the dashed line defines the
desired output quadrilateral 1.2,1.2 1.8,1.2
1,1 2,1
Geometric Transformations can rotate a figure, enlarge and shrink it, and
move it in different directions.
Example 1:
Share the object (3, 2) , (7, 2) , (5, 5)
with Shy=3
The solve 1:
Shy=3
Xnew = X
Ynew = Y + Shy * X
Point (3, 2)
X1new = 3
Y1new = 2 + 3 * 3 = 11
Point (7, 2)
X3new = 7
Ynew = 2 + 3 * 7 = 23
Point (5, 5)
X2new = 5
Y2new = 5 + 3 * 5 = 20
Q1:
Share the object (2, 2) , (5, 2) , (5, 4), (2, 4 ) with Shx= -3
Q2:
Move the square (1,2) , (4,2) , (4,5) , (1,5) with 3 units in the X-axis ,and 4
units in the Y-axis and then share its with Shy= -2
Q3:
Execute the scaling operation of the triangle in the figure below with SX=2,
SY=2 and then share its with Shx= 3
Q1: Draw the object (5, 30), (-5, 30), ( -11, 24), (11, 24), (5, 18), (-5, 18), (0, 0)
1. Share the object with Shx=-1
2. Scale on Sx=2 and Sy=1
3. Rotate the object 2 clockwise with Ǿ= П/6,
draw the object after each rotation.
Example 1:
What (3*3) matrix will
change the center of the
scene to the origin, and
reflect the mountains in the
lake? [the center of the
scene is (4,0) ]
Example 2 : Generate Figure2
from Figure1 using matrices
H.W.: Obtain object B from object A using 2D
transformation (Reflection, { Scaling with fixed
point (0,3), Sx and Sy =1.5} and translation ) as
shown in the figure below
Q1:
Translate a polygon with coordinates A(2,5), B(7,10) and C(10,2) by 3 units
in x direction and 4 unit in y direction.
Q2:
Translate the triangle with vertices A(2,4), B(1,7), and C(4,6) by translation
vector T(2,4).
Q3:
Scale the polygon with coordinates A(2,5), B(7,10), and C(10,2) by two units
in the x-direction and two units in the y-direction.
Q4:
Perform the scaling transformation to the triangle with vertices A(6,10),
B(10,6), and C(4,2) with scaling factors sx=0.5 and sy=0.5.
Q5:
Perform the counterclockwise 45 rotate of triangle A(2,3), B(5,5), C(4,3)
about the point (3,4).
Q2:-
Consider the line from (3, 4) to (10, 8), use the Bresenham's algorithm to
rasterize the line
3. x=x1 x=3 5 5 3
y=y1 y=4 3 (5, 5)
𝟒. 𝒆 =𝟐 ∗△ y - △x e = 2*4 – 7 = 8 - 7 = 1 6 6 -11
5. i = 1 i=1 -3
6. Plot (x , y) 6: plot ( 3, 4 )) 4 (6, 6)
7. While (e ≥ 0 ) while ( e>= 0 ) { 7 6 5
{ {
5 (7, 6 )
y =y+1 y=4+1=5
8 7 -9
𝒆 =e −𝟐 ∗△ x e = 1 – 2 * 7 = -13
} } -1
x =x+1 x=3+1=4 6 ( 8, 7 )
𝒆 =e +𝟐 ∗△ y e = -13 + 2 * 4 = -5 9 7 7
8. i=i+1 i = 1+ 1 = 2 7 ( 9, 7 )
9. If ( i ≤ △ x ) then if ( 2 <= 5) then 10 8 -7
go to step 6 go to step 6 1
10. Stop (10 , 8)
Q3: Answer the following:
1. Execute the reflection transformation on the below figure on the X-axis.
2. Execute the translation transformation on the figure result from step 1 by
Tx=8 and Ty=0.
The solve
1- Reflection
2, 0 2, 0
2, 3 2, -3
0, 3 0, -3
3, 5 3, -5
6, 3 6, -3
4, 3 4, -3
4, 0 4, 0
2- Translation
2, 0 10 , 0 6, -3 14, -3
2, 3 10, 3 4, -3 12, -3
0, 3 8, 3 4,0 12, 0
3, 5 11, 5
6, 3 14, 5
4, 3 12, 5
4, 0 12, 0
2, -3 10, -3
0, -3 8, -3
3, -5 11, -3
Q2:-
Consider the line from (4, 5) to (11, 9), use the Bresenham's algorithm to
rasterize the line
3. x=x1 x=4 5 5 3
y=y1 y=5 3 (6, 6)
𝟒. 𝒆 =𝟐 ∗△ y - △x e = 2*4 – 7 = 8 - 7 = 1 6 6 -11
5. i = 1 i=1 -3
6. Plot (x , y) 6: plot ( 4, 5 )) 4 (7, 7)
7. While (e ≥ 0 ) while ( e>= 0 ) { 7 6 5
{ {
5 (8, 7 )
y =y+1 y=5+1=6
8 7 -9
𝒆 =e −𝟐 ∗△ x e = 1 – 2 * 7 = -13
} } -1
x =x+1 x=4+1=5 6 ( 9, 8 )
𝒆 =e +𝟐 ∗△ y e = -13 + 2 * 4 = -5 9 7 7
8. i=i+1 i = 1+ 1 = 2 7 ( 10, 8 )
9. If ( i ≤ △ x ) then if ( 2 <= 5) then 10 8 -7
go to step 6 go to step 6 1
10. Stop (11 , 9)
Q3: Answer the following:
1. Execute the reflection transformation on the below figure on the X-axis.
2. Execute the translation transformation on the figure result from step 1 by
Tx = -8 and Ty = 0.
The solve
1- Reflection
2- Translation
Q2:-
Consider the line from (2, 3) to (9, 7), use the Bresenham's algorithm to
rasterize the line
3. x=x1 x=4 5 5 3
y=y1 y=5 3 (6, 6)
𝟒. 𝒆 =𝟐 ∗△ y - △x e = 2*4 – 7 = 8 - 7 = 1 6 6 -11
5. i = 1 i=1 -3
6. Plot (x , y) 6: plot ( 4, 5 )) 4 (7, 7)
7. While (e ≥ 0 ) while ( e>= 0 ) { 7 6 5
{ {
5 (8, 7 )
y =y+1 y=5+1=6
8 7 -9
𝒆 =e −𝟐 ∗△ x e = 1 – 2 * 7 = -13
} } -1
x =x+1 x=4+1=5 6 ( 9, 8 )
𝒆 =e +𝟐 ∗△ y e = -13 + 2 * 4 = -5 9 7 7
8. i=i+1 i = 1+ 1 = 2 7 ( 10, 8 )
9. If ( i ≤ △ x ) then if ( 2 <= 5) then 10 8 -7
go to step 6 go to step 6 1
10. Stop (11 , 9)
Q3: Answer the following:
1. Execute the reflection transformation on the below figure on the X-axis.
2. Execute the translation transformation on the figure result from step 1 by
Tx = 8 and Ty = 6.
The solve
1- Reflection
2- Translation
Q1:
Rotate the object in figure 1 in
clockwise (-90) degree.
Q2:
Rotate the rectangle in figure 2 in an
anticlockwise with Ǿ = 90 around the
point (5, 7).
Q3 :
Reflect the triangle in figure 3 in:
A- X axis; B- Y axis;
C- origin; D- line Y=X
Q1:
Move the square form (5, 4), (10, 4),(10, 9), (5, 9) with 7 units in the X
direction and 8 units in the Y direction.
The solve:
TX= 7 , TY= 8
First point
X1 new= 5 + 7 = 12
Y1 new= 4 + 8 = 12
Second point
X2 new= 10 + 7 = 17
Y2 new= 4 + 8 = 12
Third point
X3 new= 10 + 7 = 17
Y3 new= 9 + 8 = 17
Third point
X3 new= 5 + 7 = 12
Y3 new= 9 + 8 = 17
The solve:
TX= 7 , TY= 8
X1 new Y1 new 1 5 4 1 1 0 0
0 1 0
X2 new Y2 new 1 = 10 4 1 *
X3 new Y3 new 1 10 9 1 7 8 1
X4 new Y4 new 1 5 9 1
12 12 1
17 12 1
17 17 1
12 17 1
X1 new = 12 Y1 new = 12
X2 new = 17 Y2 new = 12
X3 new = 17 Y3 new = 17
X4 new = 12 Y4 new = 17
Example 6 :
Scale the square (1,2) , (4,2) , (1,5) , (4,5) with 4 units in the X-axis ,and 2 units
in the Y-axis
The solve :
SX=4
SY=2
X1 new Y1 new 1 1 2 1
4 0 0
X2 new Y2 new 1 4 2 1
0 2 0
X3 new Y3 new 1
=
1 5 1 *
0 0 1
X4 new Y4 new 1 4 5 1
4 4 1
16 4 1
=
4 10 1
16 10 1
Q1:
Execute the scaling operation of the triangle in the figure below with SX=2,
SY=2.
Q2 :
Move the the square (1,2) , (4,2) , (4,5) , (1,5) with -4 units in the X-axis ,and -3
units in the Y-axis
Q1
Execute the scale transformation on the triangle (2, 2),(5, 7),(8,2) with SX=3,
SY=2 so the point (5,4) is the fixed point.
Q2
Execute the scale transformation on the triangle (2, 2),(5, 7),(8,2) with SX=2,
SY=3 so the point (5,4) is the fixed point.
Q1
Execute the scale transformation on the triangle (2, 2),(5, 7),(8,2) with SX=3, SY=2 so
the point (5,4) is the fixed point.
The solve:
X2=X+TX
1- Translate the object with TX= 5 and TY= 4
Y2=Y+TY
so the point (5, 4) lies on the origin
for the point (2, 2) for the point (-3, -2) for the point (-9, -4)
X1 new= 2 - TX = 2 -5 = -3 X2 new= -3 * SX = -3 *3 = -9 X1 new= 2 + TX = -9 +5 = -4
Y1 new= 2 - TY = 2 - 4 = -2 Y2 new= -2 * SY = -2 * 2 = -4 Y1 new= 2 + TY = -4 + 4 = 0
for the point (5, 7) for the point (0, 3) for the point (0, 6)
X1 new= 5 - TX = 5 - 5= 0 X2 new= 0 * SX = 0 * 3= 0 X1 new= 0 + TX = 0 + 5= 5
Y1 new= 7 - TY = 7- 4= 3 Y2 new= 3 * SY = 3* 2= 6 Y1 new= 6 + TY = 6+ 4= 10
for the point (8, 2) for the point (3, -2) for the point (9, -4)
X1 new= 8 - TX = 8 – 5 = 3 X2 new= 3 * SX = 3 * 3 = 9 X1 new= 9 + TX =9 + 5 = 14
Y1 new= 2 - TY = 2 – 4 = -2 Y2 new= -2 * SY = -2 * 2 = -4 Y1 new= -4+ TY = -4 + 4 = 0
Q1
Execute the scale transformation on the triangle (2, 2),(5, 7),(8,2) with SX=2, SY=3 so
the point (5,4) is the fixed point.
The solve:
X2=X+TX
1- Translate the object with TX= 5 and TY= 4
Y2=Y+TY
so the point (5, 4) lies on the origin
for the point (2, 2) for the point (-3, -2) for the point (-6, -6)
X1 new= 2 - TX = 2 -5 = -3 X2 new= -3 * SX = -3 *2 = -6 X1 new= 2 + TX = -6 +5 = -1
Y1 new= 2 - TY = 2 - 4 = -2 Y2 new= -2 * SY = -2 * 3 = -6 Y1 new= 2 + TY = -6 + 4 = -2
for the point (5, 7) for the point (0, 3) for the point (0, 9)
X1 new= 5 - TX = 5 - 5= 0 X2 new= 0 * SX = 0 * 2= 0 X1 new= 0 + TX = 0 + 5= 5
Y1 new= 7 - TY = 7- 4= 3 Y2 new= 3 * SY = 3* 3= 9 Y1 new= 6 + TY = 9+ 4= 13
for the point (8, 2) for the point (3, -2) for the point (6, -6)
X1 new= 8 - TX = 8 – 5 = 3 X2 new= 3 * SX = 3 * 2 = 6 X1 new= 9 + TX =6 + 5 = 11
Y1 new= 2 - TY = 2 – 4 = -2 Y2 new= -2 * SY = -2 * 3 = -6 Y1 new= -4+ TY = -6+ 4 = -2