0% found this document useful (0 votes)
87 views83 pages

2D Transformations in Computer Graphics

The document provides a comprehensive overview of geometric transformations in 2D computer graphics, focusing on translation, scaling, reflection, shearing, and rotation. It includes practice problems with detailed solutions for each type of transformation, illustrating how to apply mathematical equations to obtain new coordinates for various shapes. The content is structured for a mechanical engineering course at the University of Tabuk, specifically for a Computer Aided Design class in Spring 2025.

Uploaded by

omaruhu822
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)
87 views83 pages

2D Transformations in Computer Graphics

The document provides a comprehensive overview of geometric transformations in 2D computer graphics, focusing on translation, scaling, reflection, shearing, and rotation. It includes practice problems with detailed solutions for each type of transformation, illustrating how to apply mathematical equations to obtain new coordinates for various shapes. The content is structured for a mechanical engineering course at the University of Tabuk, specifically for a Computer Aided Design class in Spring 2025.

Uploaded by

omaruhu822
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

University of Tabuk

College of Engineering
Mechanical Engineering
Department

CAD
MCEN 1309
Spring 2025

Computer Aided Design

Chapter 2-1:

Geometric Transformation
(2D Transforms)

Dr. Abderraouf GHERISSI


2024-2025
2D Transforms
+
PRACTICE PROBLEMS BASED ON 2D TRANSLATION IN COMPUTER GRAPHICS-

Problem-01:

Given a circle C with radius 10 and center coordinates (1, 4). Apply the translation with distance 5
towards X axis and 1 towards Y axis. Obtain the new coordinates of C without changing its radius.

Solution-

Given-
•Old center coordinates of C = (Xold, Yold) = (1, 4)
•Translation vector = (Tx, Ty) = (5, 1)

Let the new center coordinates of C = (Xnew, Ynew).

Applying the translation equations, we have-


•Xnew = Xold + Tx = 1 + 5 = 6
•Ynew = Yold + Ty = 4 + 1 = 5

Thus, New center coordinates of C = (6, 5).


Problem-02:

Given a square with coordinate points A(0, 3), B(3, 3), C(3, 0), D(0, 0). Apply the translation
with distance 1 towards X axis and 1 towards Y axis. Obtain the new coordinates of the square.

Solution-

Given-
•Old coordinates of the square = A (0, 3), B(3, 3), C(3, 0), D(0, 0)
•Translation vector = (Tx, Ty) = (1, 1)

For Coordinates A(0, 3)

Let the new coordinates of corner A = (Xnew, Ynew).

Applying the translation equations, we have-


•Xnew = Xold + Tx = 0 + 1 = 1
•Ynew = Yold + Ty = 3 + 1 = 4

Thus, New coordinates of corner A = (1, 4).


For Coordinates B(3, 3)

Let the new coordinates of corner B = (Xnew, Ynew).

Applying the translation equations, we have-


•Xnew = Xold + Tx = 3 + 1 = 4
•Ynew = Yold + Ty = 3 + 1 = 4

Thus, New coordinates of corner B = (4, 4).

For Coordinates C(3, 0)

Let the new coordinates of corner C = (Xnew, Ynew).

Applying the translation equations, we have-


•Xnew = Xold + Tx = 3 + 1 = 4
•Ynew = Yold + Ty = 0 + 1 = 1

Thus, New coordinates of corner C = (4, 1).


For Coordinates D(0, 0)

Let the new coordinates of corner D = (Xnew, Ynew).

Applying the translation equations, we have-


•Xnew = Xold + Tx = 0 + 1 = 1
•Ynew = Yold + Ty = 0 + 1 = 1

Thus, New coordinates of corner D = (1, 1).


Thus, New coordinates of the square = A (1, 4), B(4, 4), C(4, 1), D(1, 1).
Problem:
Translate a 2D point P(2, 3) by tx = 4 and ty = -2 using a homogeneous transformation matrix.
Problem:
Translate the 2D shape formed by the following 5 points using a translation vector (tx = 3, ty = -2):
P1(1,2), P2(4,5), P3(0,0), P4(−2,3), P5(6,−1)?

Homogeneous Translation Matrix:

Homogeneous coordinates

Convert back to Cartesian coordinates by ignoring the last row:


P1′​(4,0); P2′(7,3); P3′(3,−2); P4′(1,1); P5′(9,−3)
Problem-01:

Given a square object with coordinate points A(0, 3), B(3, 3), C(3, 0), D(0, 0). Apply the scaling
parameter 2 towards X axis and 3 towards Y axis and obtain the new coordinates of the object.

Solution-

Given-
•Old corner coordinates of the square = A (0, 3), B(3, 3), C(3, 0), D(0, 0)
•Scaling factor along X axis = 2
•Scaling factor along Y axis = 3

For Coordinates A(0, 3)

Let the new coordinates of corner A after scaling = (Xnew, Ynew).

Applying the scaling equations, we have-


•Xnew = Xold x Sx = 0 x 2 = 0
•Ynew = Yold x Sy = 3 x 3 = 9

Thus, New coordinates of corner A after scaling = (0, 9).


For Coordinates B(3, 3)

Let the new coordinates of corner B after scaling = (Xnew, Ynew).

Applying the scaling equations, we have-


•Xnew = Xold x Sx = 3 x 2 = 6
•Ynew = Yold x Sy = 3 x 3 = 9

Thus, New coordinates of corner B after scaling = (6, 9).

For Coordinates C(3, 0)

Let the new coordinates of corner C after scaling = (Xnew, Ynew).

Applying the scaling equations, we have-


•Xnew = Xold x Sx = 3 x 2 = 6
•Ynew = Yold x Sy = 0 x 3 = 0

Thus, New coordinates of corner C after scaling = (6, 0).


For Coordinates D(0, 0)

Let the new coordinates of corner D after scaling = (Xnew, Ynew).

Applying the scaling equations, we have-


•Xnew = Xold x Sx = 0 x 2 = 0
•Ynew = Yold x Sy = 0 x 3 = 0

Thus, New coordinates of corner D after scaling = (0, 0).

Thus, New coordinates of the square after scaling = A (0, 9), B(6, 9), C(6, 0), D(0, 0).
Problem:
Scale the following 4 points of a rectangle using a scaling factor of Sx=2 in the x-direction and
Sy=0.5 in the y-direction:
P1​(0,0), P2​(4,0), P3​(4,2), P4​(0,2)

Homogeneous coordinates:

Scaling Transformation Matrix

P1′​(0,0); P2′(8,0); P3′(8,1); P4′(0,1)


Problem:
Given 5 points forming a shape: A(1,2), B(3,2), C​(3,4), D(1,4), E​(2,3)

Scale this shape with respect to an origin at E(2,3) using scaling factors Sx=2 (horizontal)
and Sy=0.5 (vertical).

Homogeneous coordinates:

Translation to Origin O(0,0)


Apply the scaling matrix S:

Translate Back to Original Origin E(2,3)

The final scaled points:

P1′​(0,2.5);P2′(4,2.5); P3′(4,3.5); P4′(0,3.5); P5′(2,3)


PRACTICE PROBLEMS BASED ON 2D REFLECTION IN COMPUTER GRAPHICS-

Problem-01:

Given a triangle with coordinate points A(3, 4), B(6, 4), C(5, 6). Apply the reflection on the X
axis and obtain the new coordinates of the object.

Solution-

Given-
•Old corner coordinates of the triangle = A (3, 4), B(6, 4), C(5, 6)
•Reflection has to be taken on the X axis

For Coordinates A(3, 4)

Let the new coordinates of corner A after reflection = (Xnew, Ynew).

Applying the reflection equations, we have-


•Xnew = Xold = 3
•Ynew = -Yold = -4

Thus, New coordinates of corner A after reflection = (3, -4).


For Coordinates B(6, 4)

Let the new coordinates of corner B after reflection = (Xnew, Ynew).

Applying the reflection equations, we have-


•Xnew = Xold = 6
•Ynew = -Yold = -4

Thus, New coordinates of corner B after reflection = (6, -4).

For Coordinates C(5, 6)

Let the new coordinates of corner C after reflection = (Xnew, Ynew).

Applying the reflection equations, we have-


•Xnew = Xold = 5
•Ynew = -Yold = -6

Thus, New coordinates of corner C after reflection = (5, -6).

Thus, New coordinates of the triangle after reflection = A (3, -4), B(6, -4), C(5, -6).
Problem-02:

Given a triangle with coordinate points A(3, 4), B(6, 4), C(5, 6). Apply the reflection on the Y axis
and obtain the new coordinates of the object.

Solution-

Given-
•Old corner coordinates of the triangle = A (3, 4), B(6, 4), C(5, 6)
•Reflection has to be taken on the Y axis

For Coordinates A(3, 4)

Let the new coordinates of corner A after reflection = (Xnew, Ynew).

Applying the reflection equations, we have-


•Xnew = -Xold = -3
•Ynew = Yold = 4

Thus, New coordinates of corner A after reflection = (-3, 4).


For Coordinates B(6, 4)

Let the new coordinates of corner B after reflection = (Xnew, Ynew).

Applying the reflection equations, we have-


•Xnew = -Xold = -6
•Ynew = Yold = 4

Thus, New coordinates of corner B after reflection = (-6, 4).

For Coordinates C(5, 6)

Let the new coordinates of corner C after reflection = (Xnew, Ynew).

Applying the reflection equations, we have-


•Xnew = -Xold = -5
•Ynew = Yold = 6

Thus, New coordinates of corner C after reflection = (-5, 6).

Thus, New coordinates of the triangle after reflection = A (-3, 4), B(-6, 4), C(-5, 6).
Problem:
Reflect a shape defined by 4 points across the x-axis. The given points are:

A​(1,2), B​(3,2), C​(3,4), D​(1,4)

A′​(1,−2); B′(3,−2); C′(3,−4); D′(1,−4)


Problem: Reflection Across the X-Axis
Reflect a shape defined by 4 points across the
line y=2. The given points are:
A(1,2), B(3,2), C​(3,4), D(1,4)

Homogeneous coordinates:

The translation matrix:


Translate Back to y=2

Result: A′​(1,2),B′(3,2) C′(3,0),D′(1,0)


Problem-01:

Given a triangle with points (1, 1), (0, 0) and (1, 0).
- Apply shear parameter 2 on X axis and find out the new coordinates of the object?
- Apply shear 2 on Y axis and find out the new coordinates of the object?

Solution: Given
•Old corner coordinates of the triangle = A (1, 1), B(0, 0), C(1, 0)
•Shearing parameter towards X direction (Shx) = 2
•Shearing parameter towards Y direction (Shy) = 2
Shearing in X Axis

For Coordinates A(1, 1)

Let the new coordinates of corner A after shearing = (Xnew, Ynew).

Applying the shearing equations, we have-


•Xnew = Xold + Shx x Yold = 1 + 2 x 1 = 3
•Ynew = Yold = 1

Thus, New coordinates of corner A after shearing = (3, 1).


For Coordinates B(0, 0)

Let the new coordinates of corner B after shearing = (Xnew, Ynew).

Applying the shearing equations, we have-


•Xnew = Xold + Shx x Yold = 0 + 2 x 0 = 0
•Ynew = Yold = 0

Thus, New coordinates of corner B after shearing = (0, 0).

For Coordinates C(1, 0)

Let the new coordinates of corner C after shearing = (Xnew, Ynew).

Applying the shearing equations, we have-


•Xnew = Xold + Shx x Yold = 1 + 2 x 0 = 1
•Ynew = Yold = 0

Thus, New coordinates of corner C after shearing = (1, 0).


Thus, New coordinates of the triangle after shearing in X axis = A (3, 1), B(0, 0), C(1, 0).
Shearing in Y Axis-

For Coordinates A(1, 1)

Let the new coordinates of corner A after shearing = (Xnew, Ynew).

Applying the shearing equations, we have-


•Xnew = Xold = 1
•Ynew = Yold + Shy x Xold = 1 + 2 x 1 = 3

Thus, New coordinates of corner A after shearing = (1, 3).

For Coordinates B(0, 0)

Let the new coordinates of corner B after shearing = (Xnew, Ynew).

Applying the shearing equations, we have-


•Xnew = Xold = 0
•Ynew = Yold + Shy x Xold = 0 + 2 x 0 = 0

Thus, New coordinates of corner B after shearing = (0, 0).


For Coordinates C(1, 0)

Let the new coordinates of corner C after shearing = (Xnew, Ynew).


Applying the shearing equations, we have-
•Xnew = Xold = 1
•Ynew = Yold + Shy x Xold = 0 + 2 x 1 = 2

Thus, New coordinates of corner C after shearing = (1, 2).


Thus, New coordinates of the triangle after shearing in Y axis = A (1, 3), B(0, 0), C(1, 2).
Problem:
Apply a shear transformation that includes both shx=0.5 and shy=0.3 directions. For the
triangle with points: A(1,1), B(3,1), C(2,4)

shx​=0.5 (shear along x)


shy=0.3 (shear along y)

The shear matrix in 2D homogeneous coordinates is:

A′(1.5,1.3); B′(3.5,1.9); C′(4,5.6)


(sinθ= y/R) (cosθ= x/R)
Problem:

A triangle with points: A(1,1) B(3,1) C(2,4)


- Rotate the shape around the origin by θ=55 degree.

The 2D rotation matrix in homogeneous form is:


PRACTICE PROBLEMS BASED ON 2D ROTATION IN COMPUTER GRAPHICS-

Problem-01:

Given a line segment with starting point as (0, 0) and ending point as (4, 4). Apply 30 degree rotation
anticlockwise direction on the line segment and find out the new coordinates of the line.

Solution-

We rotate a straight line by its end points with the same angle. Then, we re-draw a line between the
new end points.

Given-
•Old ending coordinates of the line = (Xold, Yold) = (4, 4)
•Rotation angle = θ = 30º

Let new ending coordinates of the line after rotation = (Xnew, Ynew).
Applying the rotation equations, we have-

Xnew
= Xold x cosθ – Yold x sinθ
= 4 x cos30º – 4 x sin30º
= 4 x (√3 / 2) – 4 x (1 / 2)
= 2√3 – 2
= 2(√3 – 1)
= 2(1.73 – 1)
= 1.46

Ynew
= Xold x sinθ + Yold x cosθ
= 4 x sin30º + 4 x cos30º
= 4 x (1 / 2) + 4 x (√3 / 2)
= 2 + 2√3
= 2(1 + √3)
= 2(1 + 1.73)
= 5.46

Thus, New ending coordinates of the line after rotation = (1.46, 5.46).
Problem-02:

Given a triangle with corner coordinates (0, 0), (1, 0) and (1, 1). Rotate the triangle by 90 degree
anticlockwise direction and find out the new coordinates.

Solution-

We rotate a polygon by rotating each vertex of it with the same rotation angle.

Given-
•Old corner coordinates of the triangle = A (0, 0), B(1, 0), C(1, 1)
•Rotation angle = θ = 90º

For Coordinates A(0, 0)

Let the new coordinates of corner A after rotation = (Xnew, Ynew).

Applying the rotation equations, we have-

Xnew
= Xold x cosθ – Yold x sinθ
= 0 x cos90º – 0 x sin90º
=0
Ynew
= Xold x sinθ + Yold x cosθ
= 0 x sin90º + 0 x cos90º
=0

Thus, New coordinates of corner A after rotation = (0, 0).

For Coordinates B(1, 0)

Let the new coordinates of corner B after rotation = (Xnew, Ynew).

Xnew
= Xold x cosθ – Yold x sinθ
= 1 x cos90º – 0 x sin90º
=0

Ynew
= Xold x sinθ + Yold x cosθ
= 1 x sin90º + 0 x cos90º
=1+0
=1

Thus, New coordinates of corner B after rotation = (0, 1).


For Coordinates C(1, 1)

Let the new coordinates of corner C after rotation = (Xnew, Ynew).

Xnew
= Xold x cosθ – Yold x sinθ
= 1 x cos90º – 1 x sin90º
=0–1
= -1

Ynew
= Xold x sinθ + Yold x cosθ
= 1 x sin90º + 1 x cos90º
=1+0
=1

Thus, New coordinates of corner C after rotation = (-1, 1).

Thus, New coordinates of the triangle after rotation = A (0, 0), B(0, 1), C(-1, 1).
Rotation of a Point Q (xq, yq, 1) about a Point P (p, q, 1)

Since the rotation matrix R about the z-axis and translation matrix T in the x-y plane are known from Eqs.
(2.4) and (2.3) respectively, rotation of Q about P can be regarded as translating P to coincide with the origin,
followed by rotation about the z-axis by an angle θ, and lastly, placing P back to its original position (Figure
2.6). These transformations can be concatenated as
Problem:
Rotate a shape defined by 6 points around an arbitrary point P (xc, yc) by an angle θ=45°

P1​(1,1),P2​(2,1),P3​(2,2),P4​(1,2),P5​(1.5,2.5),P6​(1.5,0.5)

Where the arbitrary center of rotation: P(xc, yc) = (3,2)

T1=

R=

T2=
P2’= ?, P3’=? , P4’=? , P5’=? , P6’=?​
Translation about a vector V(vx, vy)
Combined Rotation and Translation

Translation

Rotation
Combined Rotation and Translation
Problem: Apply a rotation of 45° and a translation by (3,2) to a 6-point shape with the
following vertices:
P1(1,1),P2(2,1),P3(2,2),P4(1,2),P5(1.5,2.5),P6(1.5,0.5)
Use homogeneous transformation matrices.
Reflection
Note that identical result may be obtained by rotating the trapezium by 180 about the y axis.
No distortion in the shape of the trapezium. Since reflection results by combining translation and/ or
rotation, it is a rigid body transformation.
Reflection About an Arbitrary Line
Let D be a point on line L and S be an object in two-dimensional space. It is required to
reflect S about L. This reflection can be obtained as a sequence of the following
transformations:
Steps for Reflection About y = mx+c:

[Link] the line y = mx+c to pass through


the origin by subtracting c from all y
coordinates.

2. Rotate the system to align the line y = mx


with the x-axis using an angle θ =arctan(m)

[Link] the points about the x-axis.

4. Apply the inverse rotation and translation to


return to the original position.
Example
Reflect the shape formed by the points A(1,1);B(2,3);C(4,2) and D(3,1) about the line y=2x+1.
Use homogeneous coordinates.
Clarify the equations, the matrices and the steps of calculation.

To reflect about the line y= 2x + 1

Translate the line to pass through the origin


The line y=2x + 1 can be rewritten as y - 1 = 2(x - 0).
So, translate by (0,−1)

The slope of the line 2x−y+1=0 is 2, so the angle θ with


the x-axis is θ = tan−1 (Slope) = atan (2) =63.43°

The rotation matrix R :


Reflect about the x-axis

The inverse rotation matrix R^-1

The inverse translation matrix T^-1

The total transformation matrix H


[A] =

θ = 63.43°
Reflection Through a Point

A point P (x, y, 1) when reflected through the origin is written as P* (x*, y*, 1) = (−x, −y, 1) or For
reflection of an object about a point Pr, we would require to shift Pr to the origin, perform the above
reflection and then transform Pr back to its original position.
Problem: The reflection through a point
Reflect the point A(5,7) through P(2,3). involves translation to the
origin, reflection, and
translation back:
[Link] point P to the
origin (0,0).
[Link] a reflection matrix
through the origin.
[Link] back to P
The transformation matrix is:
Shift 4

AC -- Shift 4

Shift 4
Any Questions?

You might also like