SlideShare a Scribd company logo
2D Transformation in Computer Graphics
In Computer graphics,
Transformation is a process of modifying and re-positioning the existing graphics.
• 2D Transformations take place in a two dimensional plane.
• Transformations are helpful in changing the position, size, orientation, shape etc of the
object.
Coordinate Transformation: The object is held stationary while the coordinate system is
transformed relative to the object.
Geometric Transformation: The object itself is transformed relative to the coordinate system or
background.
Transformation Techniques-
In computer graphics, various transformation techniques are-
1. Translation
2. Rotation
3. Scaling
4. Reflection
5. Shear
Homogenous Coordinates
To perform a sequence of transformation such as translation followed by rotation and scaling, we
need to follow a sequential process −
• Translate the coordinates,
• Rotate the translated coordinates, and then
• Scale the rotated coordinates to complete the composite transformation.
To shorten this process, we have to use 3×3 transformation matrix instead of 2×2 transformation
matrix. To convert a 2×2 matrix to 3×3 matrix, we have to add an extra dummy coordinate W.
In this way, we can represent the point by 3 numbers instead of 2 numbers, which is
called Homogenous Coordinate system. In this system, we can represent all the transformation
equations in matrix multiplication.
What is the significance of 2D Transformation?
• Transformations are the building blocks of computer graphics.
• Positioning, shaping, viewing positions are done by transformations.
• Transformation is also used for determining the perspective views.
2D Translation in Computer Graphics
In Computer graphics,
2D Translation is a process of moving an object from one position to another in a two dimensional
plane.
Consider a point object O has to be moved from one position to another in a 2D plane.
Let-
• Initial coordinates of the object O = (Xold, Yold)
• New coordinates of the object O after translation = (Xnew, Ynew)
• Translation vector or Shift vector = (Tx, Ty)
Given a Translation vector (Tx, Ty)-
• Tx defines the distance the Xold coordinate has to be moved.
• Ty defines the distance the Yold coordinate has to be moved.
This translation is achieved by adding the translation coordinates to the old coordinates of the
object as-
• Xnew = Xold + Tx (This denotes translation towards X axis)
• Ynew = Yold + Ty (This denotes translation towards Y axis)
In Matrix form, the above translation equations may be represented as-
• The homogeneous coordinates representation of (X, Y) is (X, Y, 1).
• Through this representation, all the transformations can be performed using matrix / vector
multiplications.
The above translation matrix may be represented as a 3 x 3 matrix as-
Problem
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
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).
2D Scaling in Computer Graphics
In computer graphics, scaling is a process of modifying or altering the size of objects.
• Scaling may be used to increase or reduce the size of object.
• Scaling subjects the coordinate points of the original object to change.
• Scaling factor determines whether the object size is to be increased or reduced.
• If scaling factor > 1, then the object size is increased.
• If scaling factor < 1, then the object size is reduced.
Consider a point object O has to be scaled in a 2D plane.
Let-
• Initial coordinates of the object O = (Xold, Yold)
• Scaling factor for X-axis = Sx
• Scaling factor for Y-axis = Sy
• New coordinates of the object O after scaling = (Xnew, Ynew)
This scaling is achieved by using the following scaling equations-
• Xnew = Xold x Sx
• Ynew = Yold x Sy
In Matrix form, the above scaling equations may be represented as-
For homogeneous coordinates, the above scaling matrix may be represented as a 3 x 3 matrix as-
Problem
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).
Derivation of scaling matrix based on arbitrary point
Step-01: Translate
tx = - Px, ty = - Py
[T1] = |
1 0 𝑡𝑥
0 1 𝑡𝑦
0 0 1
| = |
1 0 −𝑃𝑥
0 1 −𝑃𝑦
0 0 1
|
Step-02: Scaling about the origin
[S0] = |
𝑆𝑥 0 0
0 𝑆𝑦 0
0 0 1
|
Step-03: Back Translate
tx = Px, ty = Py
[T2] = |
1 0 𝑡𝑥
0 1 𝑡𝑦
0 0 1
| = |
1 0 𝑃𝑥
0 1 𝑃𝑦
0 0 1
|
Step-04:
Scaling matrix about arbitrary point
[Sp] = [T2] [S0] [T1]
= |
1 0 𝑃𝑥
0 1 𝑃𝑦
0 0 1
| |
𝑆𝑥 0 0
0 𝑆𝑦 0
0 0 1
| |
1 0 −𝑃𝑥
0 1 −𝑃𝑦
0 0 1
|
= |
1 0 𝑃𝑥
0 1 𝑃𝑦
0 0 1
| |
𝑆𝑥 0 −𝑆𝑥. 𝑃𝑥
0 𝑆𝑦 −𝑆𝑦. 𝑃𝑦
0 0 1
|
= |
𝑆𝑥 0 −𝑆𝑥. 𝑃𝑥 + 𝑃𝑥
0 𝑆𝑦 −𝑆𝑦. 𝑃𝑦 + 𝑃𝑦
0 0 1
|
=|
𝑆𝑥 0 𝑃𝑥(1 − 𝑆𝑥)
0 𝑆𝑦 𝑃𝑦(1 − 𝑆𝑦)
0 0 1
|
Problem:
Magnify the triangle with vertices A(0, 0), B(1, -1) and C(4, 2) to twice its size by keeping the
vertex C(4, 2) fixed.
Solution:
Here, scaling factor along X-axis, Sx= 2 and scaling factor along Y-axis, Sy=2 and the arbitrary
point Px=4 and Py=2
We know that,
[
𝑥′
𝑦′
1
] = [
𝑆𝑥 0 𝑃𝑥(1 − 𝑆𝑥)
0 𝑆𝑦 𝑃𝑦(1 − 𝑆𝑦)
0 0 1
] [
𝑥
𝑦
1
] (1)
For vertex A(0, 0) the equation (1) becomes
[
𝑥′
𝑦′
1
] = [
2 0 4(1 − 2)
0 2 2(1 − 2)
0 0 1
] [
0
0
1
]
= [
2 0 −4
0 2 −2
0 0 1
] [
0
0
1
]
= [
0 + 0 − 4
0 + 0 − 2
0 + 0 + 1
]
= [
−4
−2
1
]
Therefore A’ = (x’, y’) = (-4, -2)
For vertex B(1, -1) the equation (1) becomes
[
𝑥′
𝑦′
1
] = [
2 0 4(1 − 2)
0 2 2(1 − 2)
0 0 1
] [
1
−1
1
]
= [
2 0 −4
0 2 −2
0 0 1
] [
1
−1
1
]
= [
2 − 0 − 4
0 − 2 − 2
0 + 0 + 1
]
= [
−2
−4
1
]
Therefore B’ = (x’, y’) = (-2, -4)
2D Rotation in Computer Graphics
In Computer graphics,
2D Rotation is a process of rotating an object with respect to an angle in a two dimensional plane
Consider a point object O has to be rotated from one angle to another in a 2D plane.
Let-
• Initial coordinates of the object O = (Xold, Yold)
• Initial angle of the object O with respect to origin = Φ
• Rotation angle = θ
• New coordinates of the object O after rotation = (Xnew, Ynew)
This rotation is achieved by using the following rotation equations-
• Xnew = Xold x cosθ – Yold x sinθ
• Ynew = Xold x sinθ + Yold x cosθ
In Matrix form, the above rotation equations may be represented as-
For homogeneous coordinates, the above rotation matrix may be represented as a 3 x 3 matrix as-
Problem
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).
Derivation of rotation matrix based on arbitrary point
Step-01: Translate
tx = - Px, ty = - Py
[T1] = |
1 0 𝑡𝑥
0 1 𝑡𝑦
0 0 1
| = |
1 0 −𝑃𝑥
0 1 −𝑃𝑦
0 0 1
|
Step-02: Rotate about origin
[R0] = |
𝑐𝑜𝑠𝜃 −𝑠𝑖𝑛𝜃 0
𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃 0
0 0 1
|
Step-03: Back Translate
tx = Px, ty = Py
[T2] = |
1 0 𝑡𝑥
0 1 𝑡𝑦
0 0 1
| = |
1 0 𝑃𝑥
0 1 𝑃𝑦
0 0 1
|
Step-04: Rotation matrix about arbitrary point
[Tp] = [T2] [R0] [T1]
= |
1 0 𝑃𝑥
0 1 𝑃𝑦
0 0 1
| |
𝑐𝑜𝑠𝜃 −𝑠𝑖𝑛𝜃 0
𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃 0
0 0 1
| |
1 0 −𝑃𝑥
0 1 −𝑃𝑦
0 0 1
|
= |
1 0 𝑃𝑥
0 1 𝑃𝑦
0 0 1
| |
𝑐𝑜𝑠𝜃 −𝑠𝑖𝑛𝜃 −𝑃𝑥𝑐𝑜𝑠𝜃 + 𝑃𝑦𝑠𝑖𝑛𝜃
𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃 −𝑃𝑥𝑠𝑖𝑛𝜃 − 𝑃𝑦𝑐𝑜𝑠𝜃
0 0 1
|
= |
𝑐𝑜𝑠𝜃 −𝑠𝑖𝑛𝜃 −𝑃𝑥𝑐𝑜𝑠𝜃 + 𝑃𝑦𝑠𝑖𝑛𝜃 + 𝑃𝑥
𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃 −𝑃𝑥𝑠𝑖𝑛𝜃 − 𝑃𝑦𝑐𝑜𝑠𝜃 + 𝑃𝑦
0 0 1
|
= |
𝑐𝑜𝑠𝜃 −𝑠𝑖𝑛𝜃 𝑃𝑥(1 − 𝑐𝑜𝑠𝜃) + 𝑃𝑦𝑠𝑖𝑛𝜃
𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃 𝑃𝑦(1 − 𝑐𝑜𝑠𝜃 − 𝑃𝑥𝑠𝑖𝑛𝜃
0 0 1
|
Problem
Perform a 45 degree rotation of triangle A(0, 0), B (1, 1) and C(5, 2)
i. About the origin
ii. About P(-1, -1)
Solution
i. We know that,
[
𝑥′
𝑦′
1
] = [
𝑐𝑜𝑠𝜃 −𝑠𝑖𝑛𝜃 0
𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃 0
0 0 1
] [
𝑥
𝑦
1
] (2)
For vertex A(0, 0) the equation (2) becomes
[
𝑥′
𝑦′
1
] = [
𝑐𝑜𝑠450
−𝑠𝑖𝑛450
0
𝑠𝑖𝑛450
𝑐𝑜𝑠450
0
0 0 1
] [
0
0
1
]
= [
1
√2
−
1
√2
0
1
√2
1
√2
0
0 0 1
] [
0
0
1
]
= [
0 − 0 + 0
0 + 0 + 0
0 + 0 + 1
]
= [
0
0
1
]
Therefore A’ = (x’, y’) = (0, 0)
For vertex B(1, 1) the equation (2) becomes
[
𝑥′
𝑦′
1
] = [
𝑐𝑜𝑠450
−𝑠𝑖𝑛450
0
𝑠𝑖𝑛450
𝑐𝑜𝑠450
0
0 0 1
] [
1
1
1
]
= [
1
√2
−
1
√2
0
1
√2
1
√2
0
0 0 1
] [
1
1
1
]
= [
1
√2
−
1
√2
+ 0
1
√2
+
1
√2
+ 0
0 + 0 + 1
]
= [
0
2
√2
1
]
=[
0
√2
1
]
Therefore B’ = (x’, y’) = (0, √2)
For vertex C(5, 2) the equation (2) becomes
[
𝑥′
𝑦′
1
] = [
𝑐𝑜𝑠450
−𝑠𝑖𝑛450
0
𝑠𝑖𝑛450
𝑐𝑜𝑠450
0
0 0 1
] [
5
2
1
]
= [
1
√2
−
1
√2
0
1
√2
1
√2
0
0 0 1
] [
5
2
1
]
= [
5
√2
−
2
√2
+ 0
5
√2
+
2
√2
+ 0
0 + 0 + 1
]
= [
3
√2
7
√2
1
]
=
[
3√2
2
7√2
2
1 ]
Therefore C’ = (x’, y’) = (
3√2
2
,
7√2
2
)
ii. We know that,
[
𝑥′
𝑦′
1
] = [
𝑐𝑜𝑠𝜃 −𝑠𝑖𝑛𝜃 𝑃𝑥(1 − 𝑐𝑜𝑠𝜃) + 𝑃𝑦𝑠𝑖𝑛𝜃
𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃 𝑃𝑦(1 − 𝑐𝑜𝑠𝜃) − 𝑃𝑥𝑠𝑖𝑛𝜃
0 0 1
] [
𝑥
𝑦
1
] (3)
For vertex A(0, 0) the equation (3) becomes
[
𝑥′
𝑦′
1
] = [
𝑐𝑜𝑠450
−𝑠𝑖𝑛450
−1(1 − 𝑐𝑜𝑠450) + (−1)𝑠𝑖𝑛450
𝑠𝑖𝑛450
𝑐𝑜𝑠450
−1(1 − 𝑐𝑜𝑠450) − (−1)𝑠𝑖𝑛450
0 0 1
] [
0
0
1
]
=[
1
√2
−
1
√2
−1 (1 −
1
√2
) + (−1)
1
√2
1
√2
1
√2
−1 (1 −
1
√2
) − (−1)
1
√2
0 0 1
] [
0
0
1
]
=[
1
√2
−
1
√2
−1 (1 −
1
√2
) −
1
√2
1
√2
1
√2
−1 (1 −
1
√2
) +
1
√2
0 0 1
] [
0
0
1
]
=
[
1
√2
−
1
√2
− (
√2−1
√2
) −
1
√2
1
√2
1
√2
− (
√2−1
√2
) +
1
√2
0 0 1 ]
[
0
0
1
]
=
[
1
√2
−
1
√2
−√2+1−1
√2
1
√2
1
√2
−√2+1+1
√2
0 0 1 ]
[
0
0
1
]
=
[
1
√2
−
1
√2
−√2
√2
1
√2
1
√2
−√2+2
√2
0 0 1 ]
[
0
0
1
]
=[
1
√2
−
1
√2
−√2
√2
1
√2
1
√2
√2 − 1
0 0 1
] [
0
0
1
]
=[
0 − 0 +
−√2
√2
0 + 0 + (√2 − 1)
0 + 0 + 1
]
=[
−1
√2 − 1
1
]
Therefore A’ = (x’, y’) = (-1, √2 − 1)
For vertex B(1, 1) the equation (3) becomes
[
𝑥′
𝑦′
1
] = [
𝑐𝑜𝑠450
−𝑠𝑖𝑛450
−1(1 − 𝑐𝑜𝑠450) + (−1)𝑠𝑖𝑛450
𝑠𝑖𝑛450
𝑐𝑜𝑠450
−1(1 − 𝑐𝑜𝑠450) − (−1)𝑠𝑖𝑛450
0 0 1
] [
1
1
1
]
=[
1
√2
−
1
√2
−1 (1 −
1
√2
) + (−1)
1
√2
1
√2
1
√2
−1 (1 −
1
√2
) − (−1)
1
√2
0 0 1
] [
1
1
1
]
=[
1
√2
−
1
√2
−1 (1 −
1
√2
) −
1
√2
1
√2
1
√2
−1 (1 −
1
√2
) +
1
√2
0 0 1
] [
1
1
1
]
=
[
1
√2
−
1
√2
− (
√2−1
√2
) −
1
√2
1
√2
1
√2
− (
√2−1
√2
) +
1
√2
0 0 1 ]
[
1
1
1
]
=
[
1
√2
−
1
√2
−√2+1−1
√2
1
√2
1
√2
−√2+1+1
√2
0 0 1 ]
[
1
1
1
]
=
[
1
√2
−
1
√2
−√2
√2
1
√2
1
√2
−√2+2
√2
0 0 1 ]
[
1
1
1
]
=[
1
√2
−
1
√2
−1
1
√2
1
√2
√2 − 1
0 0 1
] [
1
1
1
]
=[
1
√2
−
1
√2
− 1
1
√2
+
1
√2
+ (√2 − 1)
0 + 0 + 1
]
=
[
1−1−√2
√2
1+1+√2(√2−1)
√2
1 ]
=
[
−√2
√2
2+(√2)2−√2
√2
1 ]
=[
−1
2+2−√2
√2
1
]
=[
−1
4−√2
√2
1
]
=[
−1
2√2√2−√2
√2
1
]
=[
−1
√2(2√2−1)
√2
1
]
=[
−1
2√2 − 1
1
]
Therefore B’ = (x’, y’) = (-1, 2√2 − 1)
For vertex C(5, 2) the equation (3) becomes
[
𝑥′
𝑦′
1
] = [
𝑐𝑜𝑠450
−𝑠𝑖𝑛450
−1(1 − 𝑐𝑜𝑠450) + (−1)𝑠𝑖𝑛450
𝑠𝑖𝑛450
𝑐𝑜𝑠450
−1(1 − 𝑐𝑜𝑠450) − (−1)𝑠𝑖𝑛450
0 0 1
] [
5
2
1
]
=[
1
√2
−
1
√2
−1 (1 −
1
√2
) + (−1)
1
√2
1
√2
1
√2
−1 (1 −
1
√2
) − (−1)
1
√2
0 0 1
] [
5
2
1
]
=[
1
√2
−
1
√2
−1 (1 −
1
√2
) −
1
√2
1
√2
1
√2
−1 (1 −
1
√2
) +
1
√2
0 0 1
] [
5
2
1
]
=
[
1
√2
−
1
√2
− (
√2−1
√2
) −
1
√2
1
√2
1
√2
− (
√2−1
√2
) +
1
√2
0 0 1 ]
[
5
2
1
]
=
[
1
√2
−
1
√2
−√2+1−1
√2
1
√2
1
√2
−√2+1+1
√2
0 0 1 ]
[
5
2
1
]
=
[
1
√2
−
1
√2
−√2
√2
1
√2
1
√2
−√2+2
√2
0 0 1 ]
[
5
2
1
]
=[
1
√2
−
1
√2
−1
1
√2
1
√2
√2 − 1
0 0 1
] [
5
2
1
]
=[
5
√2
−
2
√2
− 1
5
√2
+
2
√2
+ (√2 − 1)
1
]
=
[
5−2−√2
√2
5+2+√2(√2−1)
√2
1 ]
=
[
3−√2
√2
7+(√2)2−√2
√2
1 ]
=
[
3−√2
√2
9−√2
√2
1 ]
=
[
3√2−2
2
9√2−2
2
1 ]
=
[
3√2−2
2
9√2−2
2
1 ]
=
[
3√2
2
− 1
9√2
2
− 1
1 ]
Therefore C’ = (x’, y’) = (
3√2
2
− 1,
9√2
2
− 1)
2D Reflection in Computer Graphics
• Reflection is a kind of rotation where the angle of rotation is 180 degree.
• The reflected object is always formed on the other side of mirror.
• The size of reflected object is same as the size of original object
Consider a point object O has to be reflected in a 2D plane.
Let-
• Initial coordinates of the object O = (Xold, Yold)
• New coordinates of the reflected object O after reflection = (Xnew, Ynew)
Reflection on X-axis
This reflection is achieved by using the following reflection equations-
• Xnew = Xold
• Ynew = -Yold
In Matrix form, the above reflection equations may be represented as-
For homogeneous coordinates, the above reflection matrix may be represented as a 3 x 3 matrix
as-
Reflection on Y-axis
This reflection is achieved by using the following reflection equations-
• Xnew = -Xold
• Ynew = Yold
In Matrix form, the above reflection equations may be represented as-
For homogeneous coordinates, the above reflection matrix may be represented as a 3 x 3 matrix
as-
Problem
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
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).
2D Shearing in Computer Graphics
In Computer graphics,
2D Shearing is an ideal technique to change the shape of an existing object in a two dimensional
plane.
In a two dimensional plane, the object size can be changed along X direction as well as Y direction.
So, there are two versions of shearing-
1. Shearing in X direction
2. Shearing in Y direction
Consider a point object O has to be sheared in a 2D plane.
Let-
• Initial coordinates of the object O = (Xold, Yold)
• Shearing parameter towards X direction = Shx
• Shearing parameter towards Y direction = Shy
• New coordinates of the object O after shearing = (Xnew, Ynew)
Shearing in X-axis
Shearing in X axis is achieved by using the following shearing equations-
• Xnew = Xold + Shx x Yold
• Ynew = Yold
In Matrix form, the above shearing equations may be represented as-
For homogeneous coordinates, the above shearing matrix may be represented as a 3 x 3 matrix as-
Shearing in Y-axis
Shearing in Y axis is achieved by using the following shearing equations-
• Xnew = Xold
• Ynew = Yold + Shy x Xold
In Matrix form, the above shearing equations may be represented as-
For homogeneous coordinates, the above shearing matrix may be represented as a 3 x 3 matrix as-
Problem
Given a triangle with points (1, 1), (0, 0) and (1, 0). Apply shear parameter 2 on X axis and 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).
Ad

More Related Content

What's hot (20)

Two dimensional geometric transformations
Two dimensional geometric transformationsTwo dimensional geometric transformations
Two dimensional geometric transformations
Mohammad Sadiq
 
2d-transformation
2d-transformation2d-transformation
2d-transformation
Pooja Dixit
 
3D Transformation
3D Transformation3D Transformation
3D Transformation
SwatiHans10
 
Graphics_3D viewing
Graphics_3D viewingGraphics_3D viewing
Graphics_3D viewing
Rabin BK
 
2 d geometric transformations
2 d geometric transformations2 d geometric transformations
2 d geometric transformations
Mohd Arif
 
3d transformation computer graphics
3d transformation computer graphics 3d transformation computer graphics
3d transformation computer graphics
University of Potsdam
 
2D Transformations(Computer Graphics)
2D Transformations(Computer Graphics)2D Transformations(Computer Graphics)
2D Transformations(Computer Graphics)
AditiPatni3
 
Window to viewport transformation&amp;matrix representation of homogeneous co...
Window to viewport transformation&amp;matrix representation of homogeneous co...Window to viewport transformation&amp;matrix representation of homogeneous co...
Window to viewport transformation&amp;matrix representation of homogeneous co...
Mani Kanth
 
Window to Viewport Transformation in Computer Graphics with.pptx
Window to Viewport Transformation in Computer Graphics with.pptxWindow to Viewport Transformation in Computer Graphics with.pptx
Window to Viewport Transformation in Computer Graphics with.pptx
Dolchandra
 
Two dimensional viewing
Two dimensional viewingTwo dimensional viewing
Two dimensional viewing
Mohd Arif
 
Viewing transformation
Viewing transformationViewing transformation
Viewing transformation
Udayan Gupta
 
Mid point circle algorithm
Mid point circle algorithmMid point circle algorithm
Mid point circle algorithm
Mani Kanth
 
3D Transformation
3D Transformation 3D Transformation
3D Transformation
Mahmudul Hasan
 
2D viewing & clipping
2D viewing & clipping2D viewing & clipping
2D viewing & clipping
MdAlAmin187
 
Visible surface detection in computer graphic
Visible surface detection in computer graphicVisible surface detection in computer graphic
Visible surface detection in computer graphic
anku2266
 
Ellipses drawing algo.
Ellipses drawing algo.Ellipses drawing algo.
Ellipses drawing algo.
Mohd Arif
 
3D Display
3D Display3D Display
3D Display
Toushik Paul
 
Matrix representation- CG.pptx
Matrix representation- CG.pptxMatrix representation- CG.pptx
Matrix representation- CG.pptx
RubaNagarajan
 
Projections.pptx
Projections.pptxProjections.pptx
Projections.pptx
jyoti_lakhani
 
COMPUTER GRAPHICS-"Projection"
COMPUTER GRAPHICS-"Projection"COMPUTER GRAPHICS-"Projection"
COMPUTER GRAPHICS-"Projection"
Ankit Surti
 
Two dimensional geometric transformations
Two dimensional geometric transformationsTwo dimensional geometric transformations
Two dimensional geometric transformations
Mohammad Sadiq
 
2d-transformation
2d-transformation2d-transformation
2d-transformation
Pooja Dixit
 
3D Transformation
3D Transformation3D Transformation
3D Transformation
SwatiHans10
 
Graphics_3D viewing
Graphics_3D viewingGraphics_3D viewing
Graphics_3D viewing
Rabin BK
 
2 d geometric transformations
2 d geometric transformations2 d geometric transformations
2 d geometric transformations
Mohd Arif
 
3d transformation computer graphics
3d transformation computer graphics 3d transformation computer graphics
3d transformation computer graphics
University of Potsdam
 
2D Transformations(Computer Graphics)
2D Transformations(Computer Graphics)2D Transformations(Computer Graphics)
2D Transformations(Computer Graphics)
AditiPatni3
 
Window to viewport transformation&amp;matrix representation of homogeneous co...
Window to viewport transformation&amp;matrix representation of homogeneous co...Window to viewport transformation&amp;matrix representation of homogeneous co...
Window to viewport transformation&amp;matrix representation of homogeneous co...
Mani Kanth
 
Window to Viewport Transformation in Computer Graphics with.pptx
Window to Viewport Transformation in Computer Graphics with.pptxWindow to Viewport Transformation in Computer Graphics with.pptx
Window to Viewport Transformation in Computer Graphics with.pptx
Dolchandra
 
Two dimensional viewing
Two dimensional viewingTwo dimensional viewing
Two dimensional viewing
Mohd Arif
 
Viewing transformation
Viewing transformationViewing transformation
Viewing transformation
Udayan Gupta
 
Mid point circle algorithm
Mid point circle algorithmMid point circle algorithm
Mid point circle algorithm
Mani Kanth
 
2D viewing & clipping
2D viewing & clipping2D viewing & clipping
2D viewing & clipping
MdAlAmin187
 
Visible surface detection in computer graphic
Visible surface detection in computer graphicVisible surface detection in computer graphic
Visible surface detection in computer graphic
anku2266
 
Ellipses drawing algo.
Ellipses drawing algo.Ellipses drawing algo.
Ellipses drawing algo.
Mohd Arif
 
Matrix representation- CG.pptx
Matrix representation- CG.pptxMatrix representation- CG.pptx
Matrix representation- CG.pptx
RubaNagarajan
 
COMPUTER GRAPHICS-"Projection"
COMPUTER GRAPHICS-"Projection"COMPUTER GRAPHICS-"Projection"
COMPUTER GRAPHICS-"Projection"
Ankit Surti
 

Similar to 2D Transformation in Computer Graphics (20)

2D Transformation
2D Transformation2D Transformation
2D Transformation
A. S. M. Shafi
 
Chapter 5- 3D transformations of graphics.pdf
Chapter 5- 3D transformations of graphics.pdfChapter 5- 3D transformations of graphics.pdf
Chapter 5- 3D transformations of graphics.pdf
naolseyum9
 
3D Transformation in Computer Graphics
3D Transformation in Computer Graphics3D Transformation in Computer Graphics
3D Transformation in Computer Graphics
A. S. M. Shafi
 
Computer Graphics - transformations in 2d
Computer Graphics - transformations in 2dComputer Graphics - transformations in 2d
Computer Graphics - transformations in 2d
Hisham Al Kurdi, EAVA, DMC-D-4K, HCCA-P, HCAA-D
 
Computer Graphic - Transformations in 2D
Computer Graphic - Transformations in 2DComputer Graphic - Transformations in 2D
Computer Graphic - Transformations in 2D
2013901097
 
transformation IT.ppt
transformation IT.ppttransformation IT.ppt
transformation IT.ppt
ShubhamBatwani
 
3D computer Graphic PPT.pptx in computer graphics
3D computer Graphic PPT.pptx in computer graphics3D computer Graphic PPT.pptx in computer graphics
3D computer Graphic PPT.pptx in computer graphics
gunnugunnu162
 
2 d transformation
2 d transformation2 d transformation
2 d transformation
Ankit Garg
 
moule 3 ppt1 basic 2D transformations.pptx
moule 3 ppt1 basic 2D transformations.pptxmoule 3 ppt1 basic 2D transformations.pptx
moule 3 ppt1 basic 2D transformations.pptx
RADHIKAB20
 
2D_transformatiomcomputer graphics 2d translation, rotation and scaling trans...
2D_transformatiomcomputer graphics 2d translation, rotation and scaling trans...2D_transformatiomcomputer graphics 2d translation, rotation and scaling trans...
2D_transformatiomcomputer graphics 2d translation, rotation and scaling trans...
renuka b
 
Computer graphics basic transformation
Computer graphics basic transformationComputer graphics basic transformation
Computer graphics basic transformation
Selvakumar Gna
 
Matrix 2 d
Matrix 2 dMatrix 2 d
Matrix 2 d
xyz120
 
2-D Transformations.pdf
2-D Transformations.pdf2-D Transformations.pdf
2-D Transformations.pdf
Mattupallipardhu
 
Transformations Computer Graphics.pdf
Transformations  Computer   Graphics.pdfTransformations  Computer   Graphics.pdf
Transformations Computer Graphics.pdf
IsabelleAlemu
 
2D Rotation- Transformation in Computer Graphics
2D Rotation- Transformation in Computer Graphics2D Rotation- Transformation in Computer Graphics
2D Rotation- Transformation in Computer Graphics
Susmita
 
GeometricTransformations.ppt
GeometricTransformations.pptGeometricTransformations.ppt
GeometricTransformations.ppt
Debjit Doira
 
Unit-3 overview of transformations
Unit-3 overview of transformationsUnit-3 overview of transformations
Unit-3 overview of transformations
Amol Gaikwad
 
2D-Transformations-Transformations are the operations applied to geometrical ...
2D-Transformations-Transformations are the operations applied to geometrical ...2D-Transformations-Transformations are the operations applied to geometrical ...
2D-Transformations-Transformations are the operations applied to geometrical ...
BINJAD1
 
06.Transformation.ppt
06.Transformation.ppt06.Transformation.ppt
06.Transformation.ppt
RobinAhmedSaikat
 
Computer Graphics - transformations in 3d
Computer Graphics - transformations in 3dComputer Graphics - transformations in 3d
Computer Graphics - transformations in 3d
Hisham Al Kurdi, EAVA, DMC-D-4K, HCCA-P, HCAA-D
 
Chapter 5- 3D transformations of graphics.pdf
Chapter 5- 3D transformations of graphics.pdfChapter 5- 3D transformations of graphics.pdf
Chapter 5- 3D transformations of graphics.pdf
naolseyum9
 
3D Transformation in Computer Graphics
3D Transformation in Computer Graphics3D Transformation in Computer Graphics
3D Transformation in Computer Graphics
A. S. M. Shafi
 
Computer Graphic - Transformations in 2D
Computer Graphic - Transformations in 2DComputer Graphic - Transformations in 2D
Computer Graphic - Transformations in 2D
2013901097
 
3D computer Graphic PPT.pptx in computer graphics
3D computer Graphic PPT.pptx in computer graphics3D computer Graphic PPT.pptx in computer graphics
3D computer Graphic PPT.pptx in computer graphics
gunnugunnu162
 
2 d transformation
2 d transformation2 d transformation
2 d transformation
Ankit Garg
 
moule 3 ppt1 basic 2D transformations.pptx
moule 3 ppt1 basic 2D transformations.pptxmoule 3 ppt1 basic 2D transformations.pptx
moule 3 ppt1 basic 2D transformations.pptx
RADHIKAB20
 
2D_transformatiomcomputer graphics 2d translation, rotation and scaling trans...
2D_transformatiomcomputer graphics 2d translation, rotation and scaling trans...2D_transformatiomcomputer graphics 2d translation, rotation and scaling trans...
2D_transformatiomcomputer graphics 2d translation, rotation and scaling trans...
renuka b
 
Computer graphics basic transformation
Computer graphics basic transformationComputer graphics basic transformation
Computer graphics basic transformation
Selvakumar Gna
 
Matrix 2 d
Matrix 2 dMatrix 2 d
Matrix 2 d
xyz120
 
Transformations Computer Graphics.pdf
Transformations  Computer   Graphics.pdfTransformations  Computer   Graphics.pdf
Transformations Computer Graphics.pdf
IsabelleAlemu
 
2D Rotation- Transformation in Computer Graphics
2D Rotation- Transformation in Computer Graphics2D Rotation- Transformation in Computer Graphics
2D Rotation- Transformation in Computer Graphics
Susmita
 
GeometricTransformations.ppt
GeometricTransformations.pptGeometricTransformations.ppt
GeometricTransformations.ppt
Debjit Doira
 
Unit-3 overview of transformations
Unit-3 overview of transformationsUnit-3 overview of transformations
Unit-3 overview of transformations
Amol Gaikwad
 
2D-Transformations-Transformations are the operations applied to geometrical ...
2D-Transformations-Transformations are the operations applied to geometrical ...2D-Transformations-Transformations are the operations applied to geometrical ...
2D-Transformations-Transformations are the operations applied to geometrical ...
BINJAD1
 
Ad

More from A. S. M. Shafi (20)

Data Warehouse Schema (Star, Snowflake).docx
Data Warehouse Schema (Star, Snowflake).docxData Warehouse Schema (Star, Snowflake).docx
Data Warehouse Schema (Star, Snowflake).docx
A. S. M. Shafi
 
Correlation Analysis in Machine Learning.pdf
Correlation Analysis in Machine Learning.pdfCorrelation Analysis in Machine Learning.pdf
Correlation Analysis in Machine Learning.pdf
A. S. M. Shafi
 
Naive Bayes and Decision Tree Algorithm.pdf
Naive Bayes and Decision Tree Algorithm.pdfNaive Bayes and Decision Tree Algorithm.pdf
Naive Bayes and Decision Tree Algorithm.pdf
A. S. M. Shafi
 
Frequent Pattern Growth Mining Algorithm.pdf
Frequent Pattern Growth Mining Algorithm.pdfFrequent Pattern Growth Mining Algorithm.pdf
Frequent Pattern Growth Mining Algorithm.pdf
A. S. M. Shafi
 
Direct Hashing and Pruning Algorithm in Data MIning.pdf
Direct Hashing and Pruning Algorithm in Data MIning.pdfDirect Hashing and Pruning Algorithm in Data MIning.pdf
Direct Hashing and Pruning Algorithm in Data MIning.pdf
A. S. M. Shafi
 
Association Rule Mining with Apriori Algorithm.pdf
Association Rule Mining with Apriori Algorithm.pdfAssociation Rule Mining with Apriori Algorithm.pdf
Association Rule Mining with Apriori Algorithm.pdf
A. S. M. Shafi
 
HITS Algorithm in Data and Web MIning.pdf
HITS Algorithm in Data and Web MIning.pdfHITS Algorithm in Data and Web MIning.pdf
HITS Algorithm in Data and Web MIning.pdf
A. S. M. Shafi
 
Page Rank Algorithm in Data Mining and Web Application.pdf
Page Rank Algorithm in Data Mining and Web Application.pdfPage Rank Algorithm in Data Mining and Web Application.pdf
Page Rank Algorithm in Data Mining and Web Application.pdf
A. S. M. Shafi
 
K Nearest Neighbor Classifier in Machine Learning.pdf
K Nearest Neighbor Classifier in Machine Learning.pdfK Nearest Neighbor Classifier in Machine Learning.pdf
K Nearest Neighbor Classifier in Machine Learning.pdf
A. S. M. Shafi
 
K Means Clustering Algorithm in Machine Learning.pdf
K Means Clustering Algorithm in Machine Learning.pdfK Means Clustering Algorithm in Machine Learning.pdf
K Means Clustering Algorithm in Machine Learning.pdf
A. S. M. Shafi
 
Projection
ProjectionProjection
Projection
A. S. M. Shafi
 
Line drawing algorithm
Line drawing algorithmLine drawing algorithm
Line drawing algorithm
A. S. M. Shafi
 
Fragmentation
FragmentationFragmentation
Fragmentation
A. S. M. Shafi
 
File organization
File organizationFile organization
File organization
A. S. M. Shafi
 
Bankers algorithm
Bankers algorithmBankers algorithm
Bankers algorithm
A. S. M. Shafi
 
RR and priority scheduling
RR and priority schedulingRR and priority scheduling
RR and priority scheduling
A. S. M. Shafi
 
Fcfs and sjf
Fcfs and sjfFcfs and sjf
Fcfs and sjf
A. S. M. Shafi
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
A. S. M. Shafi
 
1D Array
1D Array1D Array
1D Array
A. S. M. Shafi
 
2D array
2D array2D array
2D array
A. S. M. Shafi
 
Data Warehouse Schema (Star, Snowflake).docx
Data Warehouse Schema (Star, Snowflake).docxData Warehouse Schema (Star, Snowflake).docx
Data Warehouse Schema (Star, Snowflake).docx
A. S. M. Shafi
 
Correlation Analysis in Machine Learning.pdf
Correlation Analysis in Machine Learning.pdfCorrelation Analysis in Machine Learning.pdf
Correlation Analysis in Machine Learning.pdf
A. S. M. Shafi
 
Naive Bayes and Decision Tree Algorithm.pdf
Naive Bayes and Decision Tree Algorithm.pdfNaive Bayes and Decision Tree Algorithm.pdf
Naive Bayes and Decision Tree Algorithm.pdf
A. S. M. Shafi
 
Frequent Pattern Growth Mining Algorithm.pdf
Frequent Pattern Growth Mining Algorithm.pdfFrequent Pattern Growth Mining Algorithm.pdf
Frequent Pattern Growth Mining Algorithm.pdf
A. S. M. Shafi
 
Direct Hashing and Pruning Algorithm in Data MIning.pdf
Direct Hashing and Pruning Algorithm in Data MIning.pdfDirect Hashing and Pruning Algorithm in Data MIning.pdf
Direct Hashing and Pruning Algorithm in Data MIning.pdf
A. S. M. Shafi
 
Association Rule Mining with Apriori Algorithm.pdf
Association Rule Mining with Apriori Algorithm.pdfAssociation Rule Mining with Apriori Algorithm.pdf
Association Rule Mining with Apriori Algorithm.pdf
A. S. M. Shafi
 
HITS Algorithm in Data and Web MIning.pdf
HITS Algorithm in Data and Web MIning.pdfHITS Algorithm in Data and Web MIning.pdf
HITS Algorithm in Data and Web MIning.pdf
A. S. M. Shafi
 
Page Rank Algorithm in Data Mining and Web Application.pdf
Page Rank Algorithm in Data Mining and Web Application.pdfPage Rank Algorithm in Data Mining and Web Application.pdf
Page Rank Algorithm in Data Mining and Web Application.pdf
A. S. M. Shafi
 
K Nearest Neighbor Classifier in Machine Learning.pdf
K Nearest Neighbor Classifier in Machine Learning.pdfK Nearest Neighbor Classifier in Machine Learning.pdf
K Nearest Neighbor Classifier in Machine Learning.pdf
A. S. M. Shafi
 
K Means Clustering Algorithm in Machine Learning.pdf
K Means Clustering Algorithm in Machine Learning.pdfK Means Clustering Algorithm in Machine Learning.pdf
K Means Clustering Algorithm in Machine Learning.pdf
A. S. M. Shafi
 
Line drawing algorithm
Line drawing algorithmLine drawing algorithm
Line drawing algorithm
A. S. M. Shafi
 
RR and priority scheduling
RR and priority schedulingRR and priority scheduling
RR and priority scheduling
A. S. M. Shafi
 
Ad

Recently uploaded (20)

railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
π0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalizationπ0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalization
NABLAS株式会社
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Journal of Soft Computing in Civil Engineering
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Journal of Soft Computing in Civil Engineering
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
The Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLabThe Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLab
Journal of Soft Computing in Civil Engineering
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.
anuragmk56
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
Avnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights FlyerAvnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights Flyer
WillDavies22
 
railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
π0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalizationπ0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalization
NABLAS株式会社
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.
anuragmk56
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
Avnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights FlyerAvnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights Flyer
WillDavies22
 

2D Transformation in Computer Graphics

  • 1. 2D Transformation in Computer Graphics In Computer graphics, Transformation is a process of modifying and re-positioning the existing graphics. • 2D Transformations take place in a two dimensional plane. • Transformations are helpful in changing the position, size, orientation, shape etc of the object. Coordinate Transformation: The object is held stationary while the coordinate system is transformed relative to the object. Geometric Transformation: The object itself is transformed relative to the coordinate system or background. Transformation Techniques- In computer graphics, various transformation techniques are- 1. Translation 2. Rotation 3. Scaling 4. Reflection 5. Shear Homogenous Coordinates To perform a sequence of transformation such as translation followed by rotation and scaling, we need to follow a sequential process − • Translate the coordinates, • Rotate the translated coordinates, and then • Scale the rotated coordinates to complete the composite transformation. To shorten this process, we have to use 3×3 transformation matrix instead of 2×2 transformation matrix. To convert a 2×2 matrix to 3×3 matrix, we have to add an extra dummy coordinate W. In this way, we can represent the point by 3 numbers instead of 2 numbers, which is called Homogenous Coordinate system. In this system, we can represent all the transformation equations in matrix multiplication.
  • 2. What is the significance of 2D Transformation? • Transformations are the building blocks of computer graphics. • Positioning, shaping, viewing positions are done by transformations. • Transformation is also used for determining the perspective views. 2D Translation in Computer Graphics In Computer graphics, 2D Translation is a process of moving an object from one position to another in a two dimensional plane. Consider a point object O has to be moved from one position to another in a 2D plane. Let- • Initial coordinates of the object O = (Xold, Yold) • New coordinates of the object O after translation = (Xnew, Ynew) • Translation vector or Shift vector = (Tx, Ty) Given a Translation vector (Tx, Ty)- • Tx defines the distance the Xold coordinate has to be moved. • Ty defines the distance the Yold coordinate has to be moved.
  • 3. This translation is achieved by adding the translation coordinates to the old coordinates of the object as- • Xnew = Xold + Tx (This denotes translation towards X axis) • Ynew = Yold + Ty (This denotes translation towards Y axis) In Matrix form, the above translation equations may be represented as- • The homogeneous coordinates representation of (X, Y) is (X, Y, 1). • Through this representation, all the transformations can be performed using matrix / vector multiplications. The above translation matrix may be represented as a 3 x 3 matrix as- Problem 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.
  • 4. 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 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).
  • 5. 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).
  • 6. 2D Scaling in Computer Graphics In computer graphics, scaling is a process of modifying or altering the size of objects. • Scaling may be used to increase or reduce the size of object. • Scaling subjects the coordinate points of the original object to change. • Scaling factor determines whether the object size is to be increased or reduced. • If scaling factor > 1, then the object size is increased. • If scaling factor < 1, then the object size is reduced. Consider a point object O has to be scaled in a 2D plane. Let- • Initial coordinates of the object O = (Xold, Yold) • Scaling factor for X-axis = Sx • Scaling factor for Y-axis = Sy • New coordinates of the object O after scaling = (Xnew, Ynew) This scaling is achieved by using the following scaling equations- • Xnew = Xold x Sx • Ynew = Yold x Sy In Matrix form, the above scaling equations may be represented as- For homogeneous coordinates, the above scaling matrix may be represented as a 3 x 3 matrix as-
  • 7. Problem 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
  • 8. • 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). Derivation of scaling matrix based on arbitrary point Step-01: Translate tx = - Px, ty = - Py [T1] = | 1 0 𝑡𝑥 0 1 𝑡𝑦 0 0 1 | = | 1 0 −𝑃𝑥 0 1 −𝑃𝑦 0 0 1 | Step-02: Scaling about the origin [S0] = | 𝑆𝑥 0 0 0 𝑆𝑦 0 0 0 1 | Step-03: Back Translate tx = Px, ty = Py [T2] = | 1 0 𝑡𝑥 0 1 𝑡𝑦 0 0 1 | = | 1 0 𝑃𝑥 0 1 𝑃𝑦 0 0 1 |
  • 9. Step-04: Scaling matrix about arbitrary point [Sp] = [T2] [S0] [T1] = | 1 0 𝑃𝑥 0 1 𝑃𝑦 0 0 1 | | 𝑆𝑥 0 0 0 𝑆𝑦 0 0 0 1 | | 1 0 −𝑃𝑥 0 1 −𝑃𝑦 0 0 1 | = | 1 0 𝑃𝑥 0 1 𝑃𝑦 0 0 1 | | 𝑆𝑥 0 −𝑆𝑥. 𝑃𝑥 0 𝑆𝑦 −𝑆𝑦. 𝑃𝑦 0 0 1 | = | 𝑆𝑥 0 −𝑆𝑥. 𝑃𝑥 + 𝑃𝑥 0 𝑆𝑦 −𝑆𝑦. 𝑃𝑦 + 𝑃𝑦 0 0 1 | =| 𝑆𝑥 0 𝑃𝑥(1 − 𝑆𝑥) 0 𝑆𝑦 𝑃𝑦(1 − 𝑆𝑦) 0 0 1 | Problem: Magnify the triangle with vertices A(0, 0), B(1, -1) and C(4, 2) to twice its size by keeping the vertex C(4, 2) fixed. Solution: Here, scaling factor along X-axis, Sx= 2 and scaling factor along Y-axis, Sy=2 and the arbitrary point Px=4 and Py=2 We know that, [ 𝑥′ 𝑦′ 1 ] = [ 𝑆𝑥 0 𝑃𝑥(1 − 𝑆𝑥) 0 𝑆𝑦 𝑃𝑦(1 − 𝑆𝑦) 0 0 1 ] [ 𝑥 𝑦 1 ] (1) For vertex A(0, 0) the equation (1) becomes [ 𝑥′ 𝑦′ 1 ] = [ 2 0 4(1 − 2) 0 2 2(1 − 2) 0 0 1 ] [ 0 0 1 ] = [ 2 0 −4 0 2 −2 0 0 1 ] [ 0 0 1 ]
  • 10. = [ 0 + 0 − 4 0 + 0 − 2 0 + 0 + 1 ] = [ −4 −2 1 ] Therefore A’ = (x’, y’) = (-4, -2) For vertex B(1, -1) the equation (1) becomes [ 𝑥′ 𝑦′ 1 ] = [ 2 0 4(1 − 2) 0 2 2(1 − 2) 0 0 1 ] [ 1 −1 1 ] = [ 2 0 −4 0 2 −2 0 0 1 ] [ 1 −1 1 ] = [ 2 − 0 − 4 0 − 2 − 2 0 + 0 + 1 ] = [ −2 −4 1 ] Therefore B’ = (x’, y’) = (-2, -4) 2D Rotation in Computer Graphics In Computer graphics, 2D Rotation is a process of rotating an object with respect to an angle in a two dimensional plane Consider a point object O has to be rotated from one angle to another in a 2D plane. Let- • Initial coordinates of the object O = (Xold, Yold) • Initial angle of the object O with respect to origin = Φ • Rotation angle = θ • New coordinates of the object O after rotation = (Xnew, Ynew)
  • 11. This rotation is achieved by using the following rotation equations- • Xnew = Xold x cosθ – Yold x sinθ • Ynew = Xold x sinθ + Yold x cosθ In Matrix form, the above rotation equations may be represented as- For homogeneous coordinates, the above rotation matrix may be represented as a 3 x 3 matrix as-
  • 12. Problem 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
  • 13. = 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).
  • 14. Derivation of rotation matrix based on arbitrary point Step-01: Translate tx = - Px, ty = - Py [T1] = | 1 0 𝑡𝑥 0 1 𝑡𝑦 0 0 1 | = | 1 0 −𝑃𝑥 0 1 −𝑃𝑦 0 0 1 | Step-02: Rotate about origin [R0] = | 𝑐𝑜𝑠𝜃 −𝑠𝑖𝑛𝜃 0 𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃 0 0 0 1 | Step-03: Back Translate tx = Px, ty = Py [T2] = | 1 0 𝑡𝑥 0 1 𝑡𝑦 0 0 1 | = | 1 0 𝑃𝑥 0 1 𝑃𝑦 0 0 1 | Step-04: Rotation matrix about arbitrary point [Tp] = [T2] [R0] [T1] = | 1 0 𝑃𝑥 0 1 𝑃𝑦 0 0 1 | | 𝑐𝑜𝑠𝜃 −𝑠𝑖𝑛𝜃 0 𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃 0 0 0 1 | | 1 0 −𝑃𝑥 0 1 −𝑃𝑦 0 0 1 | = | 1 0 𝑃𝑥 0 1 𝑃𝑦 0 0 1 | | 𝑐𝑜𝑠𝜃 −𝑠𝑖𝑛𝜃 −𝑃𝑥𝑐𝑜𝑠𝜃 + 𝑃𝑦𝑠𝑖𝑛𝜃 𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃 −𝑃𝑥𝑠𝑖𝑛𝜃 − 𝑃𝑦𝑐𝑜𝑠𝜃 0 0 1 | = | 𝑐𝑜𝑠𝜃 −𝑠𝑖𝑛𝜃 −𝑃𝑥𝑐𝑜𝑠𝜃 + 𝑃𝑦𝑠𝑖𝑛𝜃 + 𝑃𝑥 𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃 −𝑃𝑥𝑠𝑖𝑛𝜃 − 𝑃𝑦𝑐𝑜𝑠𝜃 + 𝑃𝑦 0 0 1 | = | 𝑐𝑜𝑠𝜃 −𝑠𝑖𝑛𝜃 𝑃𝑥(1 − 𝑐𝑜𝑠𝜃) + 𝑃𝑦𝑠𝑖𝑛𝜃 𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃 𝑃𝑦(1 − 𝑐𝑜𝑠𝜃 − 𝑃𝑥𝑠𝑖𝑛𝜃 0 0 1 |
  • 15. Problem Perform a 45 degree rotation of triangle A(0, 0), B (1, 1) and C(5, 2) i. About the origin ii. About P(-1, -1) Solution i. We know that, [ 𝑥′ 𝑦′ 1 ] = [ 𝑐𝑜𝑠𝜃 −𝑠𝑖𝑛𝜃 0 𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃 0 0 0 1 ] [ 𝑥 𝑦 1 ] (2) For vertex A(0, 0) the equation (2) becomes [ 𝑥′ 𝑦′ 1 ] = [ 𝑐𝑜𝑠450 −𝑠𝑖𝑛450 0 𝑠𝑖𝑛450 𝑐𝑜𝑠450 0 0 0 1 ] [ 0 0 1 ] = [ 1 √2 − 1 √2 0 1 √2 1 √2 0 0 0 1 ] [ 0 0 1 ] = [ 0 − 0 + 0 0 + 0 + 0 0 + 0 + 1 ] = [ 0 0 1 ] Therefore A’ = (x’, y’) = (0, 0) For vertex B(1, 1) the equation (2) becomes [ 𝑥′ 𝑦′ 1 ] = [ 𝑐𝑜𝑠450 −𝑠𝑖𝑛450 0 𝑠𝑖𝑛450 𝑐𝑜𝑠450 0 0 0 1 ] [ 1 1 1 ] = [ 1 √2 − 1 √2 0 1 √2 1 √2 0 0 0 1 ] [ 1 1 1 ] = [ 1 √2 − 1 √2 + 0 1 √2 + 1 √2 + 0 0 + 0 + 1 ]
  • 16. = [ 0 2 √2 1 ] =[ 0 √2 1 ] Therefore B’ = (x’, y’) = (0, √2) For vertex C(5, 2) the equation (2) becomes [ 𝑥′ 𝑦′ 1 ] = [ 𝑐𝑜𝑠450 −𝑠𝑖𝑛450 0 𝑠𝑖𝑛450 𝑐𝑜𝑠450 0 0 0 1 ] [ 5 2 1 ] = [ 1 √2 − 1 √2 0 1 √2 1 √2 0 0 0 1 ] [ 5 2 1 ] = [ 5 √2 − 2 √2 + 0 5 √2 + 2 √2 + 0 0 + 0 + 1 ] = [ 3 √2 7 √2 1 ] = [ 3√2 2 7√2 2 1 ] Therefore C’ = (x’, y’) = ( 3√2 2 , 7√2 2 ) ii. We know that, [ 𝑥′ 𝑦′ 1 ] = [ 𝑐𝑜𝑠𝜃 −𝑠𝑖𝑛𝜃 𝑃𝑥(1 − 𝑐𝑜𝑠𝜃) + 𝑃𝑦𝑠𝑖𝑛𝜃 𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃 𝑃𝑦(1 − 𝑐𝑜𝑠𝜃) − 𝑃𝑥𝑠𝑖𝑛𝜃 0 0 1 ] [ 𝑥 𝑦 1 ] (3) For vertex A(0, 0) the equation (3) becomes [ 𝑥′ 𝑦′ 1 ] = [ 𝑐𝑜𝑠450 −𝑠𝑖𝑛450 −1(1 − 𝑐𝑜𝑠450) + (−1)𝑠𝑖𝑛450 𝑠𝑖𝑛450 𝑐𝑜𝑠450 −1(1 − 𝑐𝑜𝑠450) − (−1)𝑠𝑖𝑛450 0 0 1 ] [ 0 0 1 ]
  • 17. =[ 1 √2 − 1 √2 −1 (1 − 1 √2 ) + (−1) 1 √2 1 √2 1 √2 −1 (1 − 1 √2 ) − (−1) 1 √2 0 0 1 ] [ 0 0 1 ] =[ 1 √2 − 1 √2 −1 (1 − 1 √2 ) − 1 √2 1 √2 1 √2 −1 (1 − 1 √2 ) + 1 √2 0 0 1 ] [ 0 0 1 ] = [ 1 √2 − 1 √2 − ( √2−1 √2 ) − 1 √2 1 √2 1 √2 − ( √2−1 √2 ) + 1 √2 0 0 1 ] [ 0 0 1 ] = [ 1 √2 − 1 √2 −√2+1−1 √2 1 √2 1 √2 −√2+1+1 √2 0 0 1 ] [ 0 0 1 ] = [ 1 √2 − 1 √2 −√2 √2 1 √2 1 √2 −√2+2 √2 0 0 1 ] [ 0 0 1 ] =[ 1 √2 − 1 √2 −√2 √2 1 √2 1 √2 √2 − 1 0 0 1 ] [ 0 0 1 ] =[ 0 − 0 + −√2 √2 0 + 0 + (√2 − 1) 0 + 0 + 1 ] =[ −1 √2 − 1 1 ] Therefore A’ = (x’, y’) = (-1, √2 − 1) For vertex B(1, 1) the equation (3) becomes [ 𝑥′ 𝑦′ 1 ] = [ 𝑐𝑜𝑠450 −𝑠𝑖𝑛450 −1(1 − 𝑐𝑜𝑠450) + (−1)𝑠𝑖𝑛450 𝑠𝑖𝑛450 𝑐𝑜𝑠450 −1(1 − 𝑐𝑜𝑠450) − (−1)𝑠𝑖𝑛450 0 0 1 ] [ 1 1 1 ]
  • 18. =[ 1 √2 − 1 √2 −1 (1 − 1 √2 ) + (−1) 1 √2 1 √2 1 √2 −1 (1 − 1 √2 ) − (−1) 1 √2 0 0 1 ] [ 1 1 1 ] =[ 1 √2 − 1 √2 −1 (1 − 1 √2 ) − 1 √2 1 √2 1 √2 −1 (1 − 1 √2 ) + 1 √2 0 0 1 ] [ 1 1 1 ] = [ 1 √2 − 1 √2 − ( √2−1 √2 ) − 1 √2 1 √2 1 √2 − ( √2−1 √2 ) + 1 √2 0 0 1 ] [ 1 1 1 ] = [ 1 √2 − 1 √2 −√2+1−1 √2 1 √2 1 √2 −√2+1+1 √2 0 0 1 ] [ 1 1 1 ] = [ 1 √2 − 1 √2 −√2 √2 1 √2 1 √2 −√2+2 √2 0 0 1 ] [ 1 1 1 ] =[ 1 √2 − 1 √2 −1 1 √2 1 √2 √2 − 1 0 0 1 ] [ 1 1 1 ] =[ 1 √2 − 1 √2 − 1 1 √2 + 1 √2 + (√2 − 1) 0 + 0 + 1 ] = [ 1−1−√2 √2 1+1+√2(√2−1) √2 1 ] = [ −√2 √2 2+(√2)2−√2 √2 1 ]
  • 19. =[ −1 2+2−√2 √2 1 ] =[ −1 4−√2 √2 1 ] =[ −1 2√2√2−√2 √2 1 ] =[ −1 √2(2√2−1) √2 1 ] =[ −1 2√2 − 1 1 ] Therefore B’ = (x’, y’) = (-1, 2√2 − 1) For vertex C(5, 2) the equation (3) becomes [ 𝑥′ 𝑦′ 1 ] = [ 𝑐𝑜𝑠450 −𝑠𝑖𝑛450 −1(1 − 𝑐𝑜𝑠450) + (−1)𝑠𝑖𝑛450 𝑠𝑖𝑛450 𝑐𝑜𝑠450 −1(1 − 𝑐𝑜𝑠450) − (−1)𝑠𝑖𝑛450 0 0 1 ] [ 5 2 1 ] =[ 1 √2 − 1 √2 −1 (1 − 1 √2 ) + (−1) 1 √2 1 √2 1 √2 −1 (1 − 1 √2 ) − (−1) 1 √2 0 0 1 ] [ 5 2 1 ] =[ 1 √2 − 1 √2 −1 (1 − 1 √2 ) − 1 √2 1 √2 1 √2 −1 (1 − 1 √2 ) + 1 √2 0 0 1 ] [ 5 2 1 ] = [ 1 √2 − 1 √2 − ( √2−1 √2 ) − 1 √2 1 √2 1 √2 − ( √2−1 √2 ) + 1 √2 0 0 1 ] [ 5 2 1 ] = [ 1 √2 − 1 √2 −√2+1−1 √2 1 √2 1 √2 −√2+1+1 √2 0 0 1 ] [ 5 2 1 ]
  • 20. = [ 1 √2 − 1 √2 −√2 √2 1 √2 1 √2 −√2+2 √2 0 0 1 ] [ 5 2 1 ] =[ 1 √2 − 1 √2 −1 1 √2 1 √2 √2 − 1 0 0 1 ] [ 5 2 1 ] =[ 5 √2 − 2 √2 − 1 5 √2 + 2 √2 + (√2 − 1) 1 ] = [ 5−2−√2 √2 5+2+√2(√2−1) √2 1 ] = [ 3−√2 √2 7+(√2)2−√2 √2 1 ] = [ 3−√2 √2 9−√2 √2 1 ] = [ 3√2−2 2 9√2−2 2 1 ] = [ 3√2−2 2 9√2−2 2 1 ] = [ 3√2 2 − 1 9√2 2 − 1 1 ] Therefore C’ = (x’, y’) = ( 3√2 2 − 1, 9√2 2 − 1)
  • 21. 2D Reflection in Computer Graphics • Reflection is a kind of rotation where the angle of rotation is 180 degree. • The reflected object is always formed on the other side of mirror. • The size of reflected object is same as the size of original object Consider a point object O has to be reflected in a 2D plane. Let- • Initial coordinates of the object O = (Xold, Yold) • New coordinates of the reflected object O after reflection = (Xnew, Ynew) Reflection on X-axis This reflection is achieved by using the following reflection equations- • Xnew = Xold • Ynew = -Yold In Matrix form, the above reflection equations may be represented as- For homogeneous coordinates, the above reflection matrix may be represented as a 3 x 3 matrix as-
  • 22. Reflection on Y-axis This reflection is achieved by using the following reflection equations- • Xnew = -Xold • Ynew = Yold In Matrix form, the above reflection equations may be represented as- For homogeneous coordinates, the above reflection matrix may be represented as a 3 x 3 matrix as- Problem 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).
  • 23. 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).
  • 24. Problem 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).
  • 25. 2D Shearing in Computer Graphics In Computer graphics, 2D Shearing is an ideal technique to change the shape of an existing object in a two dimensional plane. In a two dimensional plane, the object size can be changed along X direction as well as Y direction. So, there are two versions of shearing- 1. Shearing in X direction 2. Shearing in Y direction Consider a point object O has to be sheared in a 2D plane. Let- • Initial coordinates of the object O = (Xold, Yold) • Shearing parameter towards X direction = Shx • Shearing parameter towards Y direction = Shy • New coordinates of the object O after shearing = (Xnew, Ynew)
  • 26. Shearing in X-axis Shearing in X axis is achieved by using the following shearing equations- • Xnew = Xold + Shx x Yold • Ynew = Yold In Matrix form, the above shearing equations may be represented as- For homogeneous coordinates, the above shearing matrix may be represented as a 3 x 3 matrix as- Shearing in Y-axis Shearing in Y axis is achieved by using the following shearing equations- • Xnew = Xold • Ynew = Yold + Shy x Xold In Matrix form, the above shearing equations may be represented as-
  • 27. For homogeneous coordinates, the above shearing matrix may be represented as a 3 x 3 matrix as- Problem Given a triangle with points (1, 1), (0, 0) and (1, 0). Apply shear parameter 2 on X axis and 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
  • 28. 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
  • 29. 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).