SlideShare a Scribd company logo
1 of 29
Download to read offline
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).

More Related Content

What's hot

scan conversion of point , line and circle
scan conversion of point , line and circlescan conversion of point , line and circle
scan conversion of point , line and circleDivy Kumar Gupta
Β 
3D Graphics : Computer Graphics Fundamentals
3D Graphics : Computer Graphics Fundamentals3D Graphics : Computer Graphics Fundamentals
3D Graphics : Computer Graphics FundamentalsMuhammed Afsal Villan
Β 
Computer graphics chapter 4
Computer graphics chapter 4Computer graphics chapter 4
Computer graphics chapter 4PrathimaBaliga
Β 
Polygon filling
Polygon fillingPolygon filling
Polygon fillingAnkit Garg
Β 
Unit-IV Windowing and Clipping.pdf
Unit-IV Windowing and Clipping.pdfUnit-IV Windowing and Clipping.pdf
Unit-IV Windowing and Clipping.pdfAmol Gaikwad
Β 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clippingMohd Arif
Β 
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
Β 
Two dimensional viewing
Two dimensional viewingTwo dimensional viewing
Two dimensional viewingMohd Arif
Β 
3D transformation in computer graphics
3D transformation in computer graphics3D transformation in computer graphics
3D transformation in computer graphicsSHIVANI SONI
Β 
2D Transformations(Computer Graphics)
2D Transformations(Computer Graphics)2D Transformations(Computer Graphics)
2D Transformations(Computer Graphics)AditiPatni3
Β 
2D transformation (Computer Graphics)
2D transformation (Computer Graphics)2D transformation (Computer Graphics)
2D transformation (Computer Graphics)Timbal Mayank
Β 
Projection In Computer Graphics
Projection In Computer GraphicsProjection In Computer Graphics
Projection In Computer GraphicsSanu Philip
Β 
Matrix representation- CG.pptx
Matrix representation- CG.pptxMatrix representation- CG.pptx
Matrix representation- CG.pptxRubaNagarajan
Β 
3D Transformation in Computer Graphics
3D Transformation in Computer Graphics3D Transformation in Computer Graphics
3D Transformation in Computer GraphicsA. S. M. Shafi
Β 
Circle generation algorithm
Circle generation algorithmCircle generation algorithm
Circle generation algorithmAnkit Garg
Β 
Attributes of Output Primitives
Attributes of Output PrimitivesAttributes of Output Primitives
Attributes of Output PrimitivesRenita Santhmayora
Β 

What's hot (20)

scan conversion of point , line and circle
scan conversion of point , line and circlescan conversion of point , line and circle
scan conversion of point , line and circle
Β 
3D Graphics : Computer Graphics Fundamentals
3D Graphics : Computer Graphics Fundamentals3D Graphics : Computer Graphics Fundamentals
3D Graphics : Computer Graphics Fundamentals
Β 
BRESENHAM’S LINE DRAWING ALGORITHM
BRESENHAM’S  LINE DRAWING ALGORITHMBRESENHAM’S  LINE DRAWING ALGORITHM
BRESENHAM’S LINE DRAWING ALGORITHM
Β 
Computer graphics chapter 4
Computer graphics chapter 4Computer graphics chapter 4
Computer graphics chapter 4
Β 
Polygon filling
Polygon fillingPolygon filling
Polygon filling
Β 
Unit-IV Windowing and Clipping.pdf
Unit-IV Windowing and Clipping.pdfUnit-IV Windowing and Clipping.pdf
Unit-IV Windowing and Clipping.pdf
Β 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clipping
Β 
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...
Β 
Two dimensional viewing
Two dimensional viewingTwo dimensional viewing
Two dimensional viewing
Β 
3D transformation in computer graphics
3D transformation in computer graphics3D transformation in computer graphics
3D transformation in computer graphics
Β 
3 d viewing
3 d viewing3 d viewing
3 d viewing
Β 
2D Transformations(Computer Graphics)
2D Transformations(Computer Graphics)2D Transformations(Computer Graphics)
2D Transformations(Computer Graphics)
Β 
2D transformation (Computer Graphics)
2D transformation (Computer Graphics)2D transformation (Computer Graphics)
2D transformation (Computer Graphics)
Β 
Projection In Computer Graphics
Projection In Computer GraphicsProjection In Computer Graphics
Projection In Computer Graphics
Β 
Matrix representation- CG.pptx
Matrix representation- CG.pptxMatrix representation- CG.pptx
Matrix representation- CG.pptx
Β 
3D Transformation in Computer Graphics
3D Transformation in Computer Graphics3D Transformation in Computer Graphics
3D Transformation in Computer Graphics
Β 
Circle generation algorithm
Circle generation algorithmCircle generation algorithm
Circle generation algorithm
Β 
Attributes of Output Primitives
Attributes of Output PrimitivesAttributes of Output Primitives
Attributes of Output Primitives
Β 
Three dimensional concepts - Computer Graphics
Three dimensional concepts - Computer GraphicsThree dimensional concepts - Computer Graphics
Three dimensional concepts - Computer Graphics
Β 
Clipping
ClippingClipping
Clipping
Β 

Similar to 2D Transformation in Computer Graphics

2D Transformation
2D Transformation2D Transformation
2D TransformationA. S. M. Shafi
Β 
transformation IT.ppt
transformation IT.ppttransformation IT.ppt
transformation IT.pptShubhamBatwani
Β 
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 graphicsgunnugunnu162
Β 
2 d transformation
2 d transformation2 d transformation
2 d transformationAnkit 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.pptxRADHIKAB20
Β 
Matrix 2 d
Matrix 2 dMatrix 2 d
Matrix 2 dxyz120
Β 
2-D Transformations.pdf
2-D Transformations.pdf2-D Transformations.pdf
2-D Transformations.pdfMattupallipardhu
Β 
2D Rotation- Transformation in Computer Graphics
2D Rotation- Transformation in Computer Graphics2D Rotation- Transformation in Computer Graphics
2D Rotation- Transformation in Computer GraphicsSusmita
Β 
GeometricTransformations.ppt
GeometricTransformations.pptGeometricTransformations.ppt
GeometricTransformations.pptDebjit Doira
Β 
Unit-3 overview of transformations
Unit-3 overview of transformationsUnit-3 overview of transformations
Unit-3 overview of transformationsAmol Gaikwad
Β 
06.Transformation.ppt
06.Transformation.ppt06.Transformation.ppt
06.Transformation.pptRobinAhmedSaikat
Β 
Computer Graphic - Transformations in 3d
Computer Graphic - Transformations in 3dComputer Graphic - Transformations in 3d
Computer Graphic - Transformations in 3d2013901097
Β 
Part 3- Manipulation and Representation of Curves.pptx
Part 3- Manipulation and Representation of Curves.pptxPart 3- Manipulation and Representation of Curves.pptx
Part 3- Manipulation and Representation of Curves.pptxKhalil Alhatab
Β 
Part 2- Transformation.pptx
Part 2- Transformation.pptxPart 2- Transformation.pptx
Part 2- Transformation.pptxKhalil Alhatab
Β 
Module 4.pptx
Module 4.pptxModule 4.pptx
Module 4.pptxSonuMittal14
Β 
Two dimentional transform
Two dimentional transformTwo dimentional transform
Two dimentional transformPatel Punit
Β 
seminar on 2D transformation
seminar on 2D transformationseminar on 2D transformation
seminar on 2D transformation9784
Β 

Similar to 2D Transformation in Computer Graphics (20)

2D Transformation
2D Transformation2D Transformation
2D Transformation
Β 
Computer Graphics - transformations in 2d
Computer Graphics - transformations in 2dComputer Graphics - transformations in 2d
Computer Graphics - transformations in 2d
Β 
transformation IT.ppt
transformation IT.ppttransformation IT.ppt
transformation IT.ppt
Β 
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
Β 
2 d transformation
2 d transformation2 d transformation
2 d transformation
Β 
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
Β 
Matrix 2 d
Matrix 2 dMatrix 2 d
Matrix 2 d
Β 
2-D Transformations.pdf
2-D Transformations.pdf2-D Transformations.pdf
2-D Transformations.pdf
Β 
2D Rotation- Transformation in Computer Graphics
2D Rotation- Transformation in Computer Graphics2D Rotation- Transformation in Computer Graphics
2D Rotation- Transformation in Computer Graphics
Β 
GeometricTransformations.ppt
GeometricTransformations.pptGeometricTransformations.ppt
GeometricTransformations.ppt
Β 
Unit-3 overview of transformations
Unit-3 overview of transformationsUnit-3 overview of transformations
Unit-3 overview of transformations
Β 
06.Transformation.ppt
06.Transformation.ppt06.Transformation.ppt
06.Transformation.ppt
Β 
Computer Graphic - Transformations in 3d
Computer Graphic - Transformations in 3dComputer Graphic - Transformations in 3d
Computer Graphic - Transformations in 3d
Β 
Computer Graphics - transformations in 3d
Computer Graphics - transformations in 3dComputer Graphics - transformations in 3d
Computer Graphics - transformations in 3d
Β 
Part 3- Manipulation and Representation of Curves.pptx
Part 3- Manipulation and Representation of Curves.pptxPart 3- Manipulation and Representation of Curves.pptx
Part 3- Manipulation and Representation of Curves.pptx
Β 
Part 2- Transformation.pptx
Part 2- Transformation.pptxPart 2- Transformation.pptx
Part 2- Transformation.pptx
Β 
Module 4.pptx
Module 4.pptxModule 4.pptx
Module 4.pptx
Β 
2D-transformation-1.pdf
2D-transformation-1.pdf2D-transformation-1.pdf
2D-transformation-1.pdf
Β 
Two dimentional transform
Two dimentional transformTwo dimentional transform
Two dimentional transform
Β 
seminar on 2D transformation
seminar on 2D transformationseminar on 2D transformation
seminar on 2D transformation
Β 

More from A. S. M. Shafi

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

Projection
ProjectionProjection
Projection
Β 
Line drawing algorithm
Line drawing algorithmLine drawing algorithm
Line drawing algorithm
Β 
Fragmentation
FragmentationFragmentation
Fragmentation
Β 
File organization
File organizationFile organization
File organization
Β 
Bankers algorithm
Bankers algorithmBankers algorithm
Bankers algorithm
Β 
RR and priority scheduling
RR and priority schedulingRR and priority scheduling
RR and priority scheduling
Β 
Fcfs and sjf
Fcfs and sjfFcfs and sjf
Fcfs and sjf
Β 
Applications of stack
Applications of stackApplications of stack
Applications of stack
Β 
1D Array
1D Array1D Array
1D Array
Β 
2D array
2D array2D array
2D array
Β 
Stack push pop
Stack push popStack push pop
Stack push pop
Β 
Queue
QueueQueue
Queue
Β 
Searching
SearchingSearching
Searching
Β 
Sorting
SortingSorting
Sorting
Β 
Linked list
Linked listLinked list
Linked list
Β 
Sum of subset problem
Sum of subset problemSum of subset problem
Sum of subset problem
Β 
Quick sort
Quick sortQuick sort
Quick sort
Β 
N queens problem
N queens problemN queens problem
N queens problem
Β 
MST
MSTMST
MST
Β 
Merge sort
Merge sortMerge sort
Merge sort
Β 

Recently uploaded

Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
Β 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
Β 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
Β 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
Β 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
Β 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
Β 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
Β 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoΓ£o Esperancinha
Β 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
Β 
Gurgaon ✑️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✑️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✑️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✑️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
Β 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIkoyaldeepu123
Β 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
Β 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
Β 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
Β 
Call Us ≽ 8377877756 β‰Ό Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 β‰Ό Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 β‰Ό Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 β‰Ό Call Girls In Shastri Nagar (Delhi)dollysharma2066
Β 

Recently uploaded (20)

Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
Β 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
Β 
young call girls in Rajiv ChowkπŸ” 9953056974 πŸ” Delhi escort Service
young call girls in Rajiv ChowkπŸ” 9953056974 πŸ” Delhi escort Serviceyoung call girls in Rajiv ChowkπŸ” 9953056974 πŸ” Delhi escort Service
young call girls in Rajiv ChowkπŸ” 9953056974 πŸ” Delhi escort Service
Β 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
Β 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
Β 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
Β 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
Β 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
Β 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Β 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
Β 
Gurgaon ✑️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✑️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✑️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✑️9711147426✨Call In girls Gurgaon Sector 51 escort service
Β 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AI
Β 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Β 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
Β 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Β 
young call girls in Green ParkπŸ” 9953056974 πŸ” escort Service
young call girls in Green ParkπŸ” 9953056974 πŸ” escort Serviceyoung call girls in Green ParkπŸ” 9953056974 πŸ” escort Service
young call girls in Green ParkπŸ” 9953056974 πŸ” escort Service
Β 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
Β 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
Β 
Call Us ≽ 8377877756 β‰Ό Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 β‰Ό Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 β‰Ό Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 β‰Ό Call Girls In Shastri Nagar (Delhi)
Β 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
Β 

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).