0% found this document useful (0 votes)
35 views63 pages

6 2023 11 18!11 57 55 PM

The document discusses two-dimensional transformations in computer graphics, including translation, scaling, rotation, reflection, and shearing. It provides mathematical descriptions and examples for each transformation type, detailing how to manipulate objects in a plane. The document emphasizes the importance of these transformations for simulating object movement and manipulation within graphics systems.

Uploaded by

beatzwaje124
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views63 pages

6 2023 11 18!11 57 55 PM

The document discusses two-dimensional transformations in computer graphics, including translation, scaling, rotation, reflection, and shearing. It provides mathematical descriptions and examples for each transformation type, detailing how to manipulate objects in a plane. The document emphasizes the importance of these transformations for simulating object movement and manipulation within graphics systems.

Uploaded by

beatzwaje124
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 63

‫الجامعة المستنصرية‬

‫كلية العلوم ‪ /‬قسم علوم الحاسوب‬


‫المرحلة الثالثة ‪ /‬مسائي‬
Part Five
1. Two Dimension Transformation
2. Translation
3. Scaling
4. Rotation
• Rotation about the origin
• Rotate about a specific point ( XP, YP )
5. Reflection
• Reflection on an arbitrary line
6. Shearing
• Y- shearing
• X- shearing
7. Spatial Transformations
• Affine Transformation
• Projective transformation
Two Dimension Transformation
Fundamental to all computer graphics systems is the ability to simulate the
movement and the manipulation of objects in the plane. These processes are
described in terms of :
1. Translation
2. Scaling
3. Rotation
4. Reflection
5. Shearing
Our object is to describe these operations in mathematical form suitable for
computer processing.
There are two complementary points of view for describing object movement:
1- Geometric transformation:
The object itself is moved relative to a stationary coordinate system or background.
Geometric transformation is applied to each point of the object.
2- Coordinate transformation:
The object is held stationary while the coordinate system is moved relative to the
object.
Example the motion of a car in a scene; we can keep the car fixed while moving the
background scenery.
Translation
In translation, an object is displaced a given distance and direction from its original
position.
 A point in the ( X,Y ) plane can be translated by adding translation amount to the
coordinates of the point.

 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

 If TX is positive then the point moves to right


 If TX is negative then the point moves to left
 If TY is positive then the point moves up
 If TY is negative then the point moves down
The transformation of Translation can be represented by (3*3) matrix:

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 1: First point Second point


X1 new= 5 + 7= 12 X2 new= 20 + 7= 27
TX=7 , TY=5
Y1 new= 5 + 5= 10 Y2 new= 5 + 5 = 10

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

(5*1) + (5*0) + (1*7) (5*0) + (5*1) + (1*5) (5*0) + (5*0) + (1*1)


(20*1) + (5*0) + (1*7) (20*0) + (5*1) + (1*5) (20*0) + (5*0) + (1*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

The solve 2: X1 new Y1 new 1 1 1 1 1 0 0


TX=7 , TY=5 5 1 1 0 1 0
X2 new Y2 new 1 = *
X3 new Y3 new 1 3 5 1 6 4 1

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.

• If SF (scale factor) > 1 then the object is enlarged


• If SF (scale factor) < 1 then the object is compressed
• If SF (scale factor) = 1 then the object is unchanged
 SX is the scale factor in the X direction
 SY is the scale factor in the Y direction

 To scale a point P(X,Y) we use the equations:


Xnew = X * SX Ynew = Y * SY
If SX and SY have the same value (SX=SY) then the scaling is said to be homogeneous
(or balanced).

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

for the point (20,8) for the point (12, 8)


X4 new= 20*SX= 20*2= 40 X3 new= 12*SX= 12*2=24
Y4 new= 8 * SY= 8*2=16 Y3 new= 8 *SY= 8*2=16 Original rectangle

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

for the point (20,8) for the point (12, 8)


X4 new= 20*SX= 20*0.5= 10 X3 new= 12*SX= 12*0.5=6
Y4 new= 8 * SY= 8*0.5=4 Y3 new= 8 *SY= 8*0.5=4

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

for the point (12, 4) for the point (12, 8)


X1 new= 12+TX= 12 + (-12)= 0 Y1 X3 new= 12+TX= 12+(-12)= 0
new= 4 +TY= 4 + (-4) = 0 Y3 new= 8 +TY= 8+(-4)= 4

for the point (20,4) for the point (20,8)


X2 new= 20+TX= 20+(-12)= 8 X4 new= 20+TX= 20+(-12)= 8
Y2 new= 4 + TY= 4+ (-4)= 0 Y4 new= 8 +TY= 8+(-4)= 4

2- Scale the object by SX=2 and SY=2 Xnew = X * SX Ynew = Y * SY

for the point (0, 0) for the point (0, 4)


X1 new= 0*SX= 0*2= 0 X3 new= 0*SX= 0*2= 0
Y1 new= 0 *SY= 0*2= 0 Y3 new= 4 * SY= 4*2= 8

for the point (8, 0) for the point (8,4)


X2 new= 8*SX= 8*2= 16 X4 new= 8*SX= 8*2= 16
Y2 new= 0 *SY= 0*2= 0 Y4 new= 4 * SY= 4*2= 8
3- Back translate the scaled object with TX= 12 and TY= 4

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

for the point (16,0) for the point (16,8)


X2 new= 16+TX= 16+12= 28 X4 new= 16+TX= 16+12= 28
Y2 new= 0 + TY= 0+4= 4 Y4 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.

(a) counterclockwise if Ǿ is a positive angle (b) clockwise if Ǿ is a negative angle

Rotation about the origin

The rotation matrix to rotate an object about the origin in an anticlockwise direction is:

Cos 𝜽 Sin 𝜽 0 𝑿𝒏𝒆𝒘 = 𝑿 ∗ 𝐂𝐨𝐬 𝜽 − 𝒀 ∗ 𝐒𝐢𝐧 𝜽


-Sin 𝜽 Cos 𝜽 0 𝒀𝒏𝒆𝒘 = 𝒀 ∗ 𝐂𝐨𝐬 𝜽 + 𝑿 ∗ 𝐒𝐢𝐧 𝜽
0 0 1
The form of the rotation matrix to rotate an Cos 𝜽 Sin 𝜽 0
object about the origin in an anticlockwise -Sin 𝜽 Cos 𝜽 0
direction : 0 0 1

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: 𝑿𝒏𝒆𝒘 = 𝑿 ∗ 𝐂𝐨𝐬 𝜽 − 𝒀 ∗ 𝐒𝐢𝐧 𝜽
𝒀𝒏𝒆𝒘 = 𝒀 ∗ 𝐂𝐨𝐬 𝜽 + 𝑿 ∗ 𝐒𝐢𝐧 𝜽

First point Second point


𝑿𝒏𝒆𝒘 = 1*0 – 6* 1 = -6 𝑿𝒏𝒆𝒘 = 5*0 – 1* 1 = -1
𝒚𝒏𝒆𝒘 = 6*0 + 1*1 = 1 𝒚𝒏𝒆𝒘 = 1*0 + 5*1 = 5

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

anticlockwise if Ǿ is a positive angle


Rotation in clockwise direction:

In order to rotate in clockwise direction we use a negative angle, and because:


Cos (-Ǿ) = Cos Ǿ
Sin (-Ǿ) = - Sin Ǿ
Therefore, The form of the rotation matrix to rotate an object about the origin in
clockwise direction :
Cos Ǿ -Sin Ǿ 0 Xnew =X * Cos Ǿ + Y * Sin Ǿ
Sin Ǿ Cos Ǿ 0 Ynew = Y * Cos Ǿ - X * Sin Ǿ
0 0 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

clockwise if Ǿ is a negative angle


Rotate about a specific point ( XP, YP )

We need three steps:


1- Translate the points (and the object) so that the point (XP,YP) lies on the
origin
XP1= X - XP
YP1= Y – YP

2- Rotate the translated point (and the translated object) by Ǿ degree about
the origin to obtain the new point (XP2,YP2)

XP2=XP1 * Cos Ǿ - YP1 * Sin Ǿ


YP2=YP1 * Cos Ǿ + XP1 * Sin Ǿ

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- Translation XP= 3 , YP= 2


XP1= X - XP Point (3,2) Point (6,2)
YP1= Y – YP X1new= 3 – 3 = 0 X2new= 6 – 3 = 3
Y1new= 2 – 2 = 0 Y2new= 2 – 2 = 0

Point (3,4) Point (6,4)


X3new= 3 – 3 = 0 X4new= 6 – 3 = 3
Y3new= 4 – 2 = 2 Y4new= 4 – 2 = 2

2- Rotation When Ǿ =90


Sin (90) = 1 0 1 0
Cos (90) = 0 -1 0 0
XP2=XP1 * Cos Ǿ - YP1 * Sin Ǿ
0 0 1
YP2=YP1 * Cos Ǿ + XP1 * Sin Ǿ
Point (0,0) Point (3,0)
X1new= 0 * (0) – 0 * (1) = 0 X2new= 3 * (0) – 0 * (1) = 0
Y1new= 0 * (0) + 0 * (1) = 0 Y2new= 0 * (0) + 3 * (1) = 3
Point (0,2) Point (3,2)
X3new= 0 * (0) – 2 * (1) = -2 X4new= 3 * (0) – 2 * (1) = -2
Y3new= 2 * (0) + 0 * ( 1) = 0 Y4new= 2 * (0) + 3 * (1) = 3
3- Back Translation
XP3= XP2 + XP
YP3= YP2 + YP Point (0,0) Point (-2,0)
X1new= 0 + 3 = 3 X3new= -2 + 3 = 1
Y1new= 0 + 2 = 2 Y3new= 0 + 2 = 2

Point (0,3) Point (-2,3)


X2new= 0 + 3 = 3 X4new= -2 + 3 = 1
Y2new= 3 + 2 = 5 Y4new= 3 + 2 = 5

1 2 3
Reflection

A reflection is a transformation that produces a mirror image of an object


relative to an axis of reflection. We can choose an axis of reflection in the x-y
plane or perpendicular to the x-y plane. The figure below gives an example of
the reflection in the y-direction and in the x-direction.
1- Reflection on the X-axis 1 0 0
Xnew = X 0 -1 0
OR
Ynew = -Y 0 0 1

2- Reflection on the Y-axis


-1 0 0
Xnew = -X OR 0 1 0
Ynew = Y 0 0 1

3- Reflection on the origin -1 0 0


Xnew = -X 0 -1 0
OR
Ynew = -Y 0 0 1

4- Reflection on the line Y = X 0 1 0


1 0 0
Xnew = Y
OR 0 0 1
Ynew = X

5- Reflection on the line Y= -X 0 -1 0


-1 0 0
Xnew = -Y OR
Ynew = -X 0 0 1
Example 8:
Reflect the point P(3, 2) in : A- X axis; B- Y axis; C- origin; D-line Y=X;

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

Q1: perform the reflection for the triangle in the


figure below:
1- X-axis
2- Y-axis

Q2: perform the sharing operation to the object in the


figure below with:
1- Shy=3
2-Shx=2

Q3: Perform the scaling operation to the object in


the figure below around the fixed point (-3,-3)
Example 9 :
Reflect the triangle with vertices at A(2, 4), B(4, 6), C(2, 6) in : A- X axis

1- The solve:
Xnew = X
Ynew = -Y

Point (2,4 ) Point (4,6 ) Point (2,6 ) (+x, -y )


X1new = 2 X1new = 4 X1new = 2
Y1new = -4 Y1new = -6 Y1new = -6

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

Point (2,4 ) Point (4,6 ) Point (2,6 )


X1new = -2 X1new =- 4 X1new = -2
Y1new = 4 Y1new = 6 Y1new = 6

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 .

To reflect the point P1 on the line L, we follow the following steps:


1 0 0
1. Move all the points up or down (in the direction T= 0 1 0
of Y axis) so that L pass through the origin 0 -k 1

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 Ǿ

 So the line y =0.5 x + 2 has gradient m = 0.5


and intersect with the Y-axis at the point where y =2
0.6 0.8 0
 So K=2 , Tan Ǿ = 0.5 ==> Ǿ = 26.57 S= 0.8 - 0.6 0
2Ǿ=53.13 , Cos 2Ǿ = 0.6 , Sin 2Ǿ = 0.8
- 1.6 3.2 1

To reflected the triangle on the line:

2 4 1 0.6 0.8 0 2.8 2.4 1


4 6 1 * 0.8 - 0.6 0 = 5.6 2.8 1
2 6 1 - 1.6 3.2 1 4.4 1.2 1
Shearing
It produces a distortion of an object. There are two types of shearing
1- Y- shearing
It transforms the point (X, Y) to the point (Xnew, Ynew) where
Xnew = X
1 Shy 0
Ynew = Y + Shy * X where Shy≠0
The matrix is 0 1 0
0 0 1

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

Xnew = X + Shx * Y where Shx≠0 1 0 0


Ynew = Y Shx 1 0
The matrix is
0 0 1
Example 11:
Share the object (1,1) , (3,1) , (1,3) , (3,3) with Shy=2

The solve 1: Shy=2


Xnew = X Point (1,1) Point (3,1)
Ynew = Y + Shy * X X1new = 1 =1 X2new = 3 =3
Y1new = 1+2*1=3 Y2new = 1+2*3=7

Point (1,3) Point (3,3)


X3new = 1 =1 X3new = 3 =3
Ynew = 3 +2*1 = 5 Ynew = 3+2*3=9

The solve 2: Shy=2


X1 new Y1 new 1 1 1 1
1 2 0
X2 new Y2 new 1 3 1 1
= 0 1 0
X3 new Y3 new 1 1 3 1 *
0 0 1
X3 new Y3 new 1 3 3 1

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

The solve 2: Shx=2

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

Another Geometric Transformations are Affine and Projective


Transformation.
 These give the facility to change the location of pixels within a figure by
using a mathematical transformation.
 The pixels are relocated from (x, y) coordinates in the input figure to the
𝒙,𝒚
(ഥ ഥ) coordinates in the output figure.
 These transformations are used for correcting geometric distortion in an
image as well as being used in registration techniques.

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.

This type of transformation 1.N/2


1.1
needs three points, as shown
in the Figure below

M.1 M.N

In the above figure : The affine transformation.


The solid line represents the three points in the input figure while the dashed
line defines the three output points in the same figure M and N are indicated
in this figure as the row and column .
Example:-
Affine transformation
(Input) : Triangle — [(0,1) (0,3) (-1,2) ]
(Output) : Target — [(0, 0) (0, 4) (1,2) ] as shown
ഥ=𝒂𝒙𝒙 𝒙 + 𝒂𝒙𝒚 𝒚 + 𝒃𝒙
𝒙 ഥ=𝒂𝒚𝒙 𝒙 + 𝒂𝒚𝒚 𝒚 + 𝒃𝒚
𝒚

0=𝒂𝒙𝒙 (𝟎) + 𝒂𝒙𝒚 (𝟏) + 𝒃𝒙 0=𝒂𝒚𝒙 (𝟎) + 𝒂𝒚𝒚 (𝟏) + 𝒃𝒙


0=𝒂𝒙𝒙 (𝟎) + 𝒂𝒙𝒚 (𝟑) + 𝒃𝒙 4=𝒂𝒚𝒙 (𝟎) + 𝒂𝒚𝒚 (𝟑) + 𝒃𝒙
1=𝒂𝒙𝒙 (−𝟏) + 𝒂𝒙𝒚 (𝟐) + 𝒃𝒙 2=𝒂𝒚𝒙 (−𝟏) + 𝒂𝒚𝒚 (𝟐) + 𝒃𝒙

𝒂𝒙𝒙 = −𝟏 , 𝒂𝒙𝒚 = 𝟎 , 𝒃𝒙 =0 𝒂𝒚𝒚 = 𝟐, 𝒂𝒚𝒙 = 𝟎 , 𝒃𝒚 =-2

ഥ= −𝟏 ∗ 𝒙 + 𝟎 ∗ 𝒚 + 𝟎
𝒙 ഥ=𝟎 ∗ 𝒙 + 𝟐 ∗ 𝒚 + (−𝟐)
𝒚
ഥ=−𝒙
𝒙 ഥ=𝟐𝒚 − 𝟐
𝒚
−𝟏 𝟎 𝟎
𝒙′ 𝒚′ 𝟏 = 𝒙 𝒚 𝟏 𝟎 𝟐 𝟎
𝟎 −𝟐 𝟏
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

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.
Q2:- I Plot X Y e
Consider the line from (3, 4) to (10, 8), 3 4 1
use the Bresenham's algorithm 1 (3, 4)
to rasterize the line 4 5 -13
-5
𝟏. △x = │ x2 −𝒙𝟏│ △ x =| 10 - 3 | = 7
2. △y = │ y2 −𝒚𝟏│ △ y =| 8 - 4 | = 4 2 (4, 5)

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

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 .
Q2:- I Plot X Y e
Consider the line from (4, 5) to (11, 9), 4 5 1
use the Bresenham's algorithm 1 (4, 5)
to rasterize the line 4 5 -13
-5
𝟏. △x = │ x2 −𝒙𝟏│ △ x =| 11 - 4 | = 7
2. △y = │ y2 −𝒚𝟏│ △ y =| 9 - 5 | = 4 2 (5, 6)

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

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 .
Q2:- I Plot X Y e
Consider the line from (2, 3) to (9, 7), 2 3 1
use the Bresenham's algorithm 1 (2, 3)
to rasterize the line 3 4 -13
-5
𝟏. △x = │ x2 −𝒙𝟏│ △ x =| 11 - 4 | = 7
2. △y = │ y2 −𝒚𝟏│ △ y =| 9 - 5 | = 4 2 (3, 4)

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

You might also like