CG Unit2
CG Unit2
1. Transformations
2. Translation
3. Rotation
4. Scaling
5. Shearing
TRANSFORMATIONS
BASIC TRANSFORMATIONS
TRANSLATION
It is the process of changing the position of an object. Let an object point P(x, y) = xI
+ yJ be moved to P’(x’, y’) be the given translation vector V = txI + tyJ, where tx and
ty is the translation factor in x and y directions, such that
P’ = P + V ………….(1)
In component form, we have
𝑥′ = 𝑥 + 𝑡𝑥 𝑎𝑛𝑑
𝑇𝑣 = { 𝑦′ = 𝑦 + 𝑡 ……………(2)
𝑦
A(0, 0), B(5, 0), C(5, 5), D(0, 5) by 2 units in x-direction and 3 units in y-
direction.
ROTATION
In 2-D rotation, an object is rotated by an angle θ with respect to the origin. This
angle is supposed to be positive for anticlockwise rotation. There are two cases for 2-D
rotation, case 1- rotation about the origin and case 2 rotation about an arbitrary point. If,
the rotation is made about an arbitrary point, a set of basic transformation, i.e.,
composite transformation is required. For 3-D rotation involving 3-D objects, we need to
specify both the angle of rotation and the axis of rotation, about which rotation ahs to be
made. We will consider case 1 and in the next section we will consider case 2.
Before starting case-1or case-2 you must know the relationship between polar coordinate
system and Cartesian system
Relation between polar coordinate system and Cartesian system: A frequently used non-
Cartesian system is Polar coordinate system. The following below figure shows a polar
coordinate reference frame. In polar coordinate system a coordinate position is specified
by r and θ, where r is a radial distance from the coordinate origin and θ is an angular
displacements from the horizontal (see below figure). Positive angular displacements are
counter clockwise. Angle θ is measured in degrees. One complete counter-clockwise
revolution about the origin is treated as 3600. A relation between Catesian and polar
coordinate system is shown in below figure.
Consider a right angle triangle in above figure. Using the definition of trigonometric
functions, we transform polar coordinates to Cartesian coordinates as:
x = r.cosθ
y = r.sinθ
The inverse transformation from Cartesian to Polar coordinates is: r= √(x2+y2) and θ = tan-1(y/x)
x' = rsin(θ+ɸ) = r(cosθcosɸ - sinθsinɸ)= x. cosθ – y.sinθ (where x = rcosɸ and y = rsinɸ)
Similarly,
y' = rsin(θ+ɸ) = r(sinθcosɸ + cosθ.sinɸ)= xsinθ + ycosθ
Thus,
Thus, we have obtained the new coordinate of point P after the rotation. In matrix
from, the transformation relation between P’ and P is given by:
Where P’ and P acts as object points in 2-D Euclidean system and Rθ is transformation
matrix for anti-clockwise Rotation.
In terms of HCS, equation (5) becomes
That is P’h = Ph.Rθ, ……………….(7)
Where P’h and Ph acts as object points, after and before required transformation, in
Homogeneous Coordinates and R θ is called homogeneous transformation matrix for
anticlockwise Rotation. P’ h, the new coordinates of a transformed object, can be found
by multiplying previous object coordinate matrix, P h, with the transformation matrix for
Rotation Rθ.
Note for clockwise rotation we have to put θ = -θ, thus the rotation matrix Rθ, in
HCS, becomes.
Example: Perform a 450 rotation of a triangle A(0, 0), B(1, 1), C(5, 2) about the origin.
Solution: We can act for the given triangle, in matrix form, using homogeneous
coordinates of the vertices:
So, the new coordinates A, B, C, of the rotation triangle ABC can be found as:
SCALING
It is the process of expanding or compressing the dimensions (i.e., size) of an object.
Important programing of scaling is in the development of viewing transformation, which is
a mapping from a window used to clip the scene to a view port for displaying the
clipped scene on the screen.
Let P(x, y) by any point of a given object and s x and sy by scaling factors in x and y
directions respectively, then the coordinate of the scaled object can be obtained as:
y’ = y. sy
if the scale factor is 0 < s < 1, then it reduces the size of an object and if it is more
than 1, it magnifies the size of the object along an axis.
iii. Consider (x, y) → (x.s x, y) where 0 < s x = y2 < 1 i.e., Compression in x-direction
with scale factor s x = ½.
We can represent the given triangle, shown in below figure, in matrix form, using
homogeneous coordinates of the vertices as:
(a) choosing s = 2
So the new coordinates A’ B’ C’ of the scaled triangle ABC can be found as:
SHEARING
They are used for modifying the shapes of 2-D or 3-D objects. The effect of a
shear transformation looks like “pushing” a geometric object in a direction that is
parallel to a coordinate plane (3D) or a coordinate axis (2D). How far a direction
is pushed is determined by its shearing factor.
One familiar example of shear is that observed when the top of a book is moved
relative to the bottom which is fixed on the table.
In case of 2-D shearing, we have two types namely x-shear and y-shear.
In x-shear, one can push in the x-direction, positive or negative, and keep the
y-direction unchanged, while in y-shear, one can push in the y-direction and keep
the x-direction fixed.
Let an object point P(x, y) be moved to P’(x’, y’) in the x-direction, by the given
scale parameter ‘a’, i.e., P’(x’, y’) be the result of x-shear of point P(x, y) by
scale factor a about the origin, which is shown in below figure.
Thus, the point P(x, y) and P’(x’, y’) have the following relationship:
x' = x + ay
where ‘a’ is a constant (known as shear parameter) that measures the degree
of shearing. If a is negative then the shearing is in the opposite direction.
Note that P(0, H) is taken into P’(aH, H). It follows that the shearing angle A
(the angle through which the vertical adge was sheared) is given by:
Tan(A) = aH/H = a
So the parameter a is just the tan of the shearing angle. In matrix form (2-D
Euclidean system), we have
Where Ph and P’h represents object points, before and after required
transformation, in Homogeneous Coordinates and Sh x(a) is called homogeneous
transformation matrix for x-shear with scale parameter ‘a’ in the x-direction.
Y-SHEAR ABOUT THE ORIGIN
Let an object P(x, y) be moved to P’(x’, y’) in the x-direction, by the given scale
parameter ‘b’. i.e., P’(x’, y’) be the result of y-shear of point P(x, y) by scale
factor ‘b’ about the origin, which is shown in below figure.
Thus, the points P(x, y) and P’(x’, y’) have the following relationship:
x' = x
where ‘b’ is a constant (known as shear parameter) that measures the degree
of shearing. In matrix form, we have
The points P(x, y) and P’(x’, y’) have the following relationship:
x’ = x + ay
where ‘ay’ and ‘bx’ are shear factors in x and y directions, respectively. The xy-
shear is also called simultaneous shearing for short.
Solution: We can represent the given square ABCD, in matrix form, using
homogeneous coordinates of vertices as:
So, the new coordinates A’B’C’D’ of the x-shear object ABCD can be found as:
[A’B’C’D’] = [ABCD]. Shx(a)
b) Similarly the effect shearing in the y direction can be found as: [A’B’C’D’] =
[ABCD].Shy(b)
Figure (a) shows the original square, figure (b)-(d) shows shearing in the x, y
and bot directions respectively.
COMPOSITE TRANSFORMATIONS
Given a 2-D point P(x, y), which we want to rotate, with respect to an arbitrary point A(h, k).
Let P’(x’ y’) be the result of anticlockwise rotation of point P by angle θ about A, which is shown
in below figure.
Since, the rotation matrix R θ is defined only with respect to the origin, we need a set of basic
transformations, which constitutes the composite transformation to compute the rotation about
a given arbitrary point A, denoted by R θ,A. We can determine the transformation R θ,A in three
steps:
1. Translate the point A(h, k) to the origin O, so that the centre of rotation A is at the origin.
2. Perform the required rotation of θ degrees about the origin, and
3. Translate the origin back to the origin position A(h, k).
Using v=hI+kJ as the translation vector, we have the following sequence of three
transformations:
Solution: Given triangle ABC, as shown in below figure, can be represented in homogeneous
coordinates of vertices as:
From equation (23), a rotation matrix RQ, A about a given arbitrary point A(h, k) is:
So the new coordinates [A’ B’ C’] of the rotated triangle [ABC] can be found as:
3 9
Thus, A’ = (-1, √2 -1), B’ = (-1 , 2√2 -1) and C’ = ( √2 − 1, √2 − 1). The following below figure shows a given
triangle, before and after the rotation.
REFLECTION ABOUT A LINE
Reflection is a transformation which generates the mirror image of an object. As discussed in the
previous block, the mirror reflection help in achieving 8-way symmetry for the circle to simplify the
scan conversion process. For reflection we need to know the reference axis or reference plane
depending on whether the object is 2-D or 3-D.
Let the line L be represented by y=mx+c, where ‘m’ is the slope with respect to the x axis, and ‘c’ is the
intercept on y-axis, as shown in below figure. Let P’ (x’, y’) by the mirror reflection about the line L of
point P(x, y).
The transformation about mirror reflection about this line L consists of the following basic
transformations:
1. Translate the intersection point A(0, c) to the origin, this shift the line L to L’.
2. Rotate the shifted line L’ by –θ degree so that the line L’ aligns with the x-axis.
3. Mirror reflection about x-axis
4. Rotate the x-axis back by θ degrees
5. Translate the origin back to the intercept point (0, c)
Let tanθ=m, the standard trigonometry yield sinθ = m/√(m2+1) and cosθ = 1/√(m2+1).
Substituting these values for sinθ and cosθ in the equation (24), we have:
SPECIAL CASES
1. If we put c = 0 and m = tanθ = 0 in the equation (25) than we have the reflection about the line y = 0
i.e., about x-axis. In matrix form:
2. If c = 0 and m = tanθ = ∞ then we have the reflection about the line x = 0 i.e. about y-axis. In matrix
form:
3. To get the mirror reflection about the line y = x, we have to put m = 1 and c = 0. In matrix form:
4. Similarly, to get the mirror reflection about the line y = -x, we have to put m = -1 and c = 0. In matrix
form:
5. The mirror reflection about the Origin (i.e., an axis perpendicular to the xy plane and passing
through the origin).
Example: Find the transformation matrix for the reflection about the line y = x.
Solution: The transformation for mirror reflection about the line y = x, consists of the following three
basic transformations.
ML = R45 . Mx . R-45
0 0
Example: Reflect the diamond-shaped polygon whose vertices are A(-1, 0), B(0, -2), C(1, 0) and D(0, 2) about (a)
the horizontal line y = 2, (b) the vertical line x = 2 and (c) the line y = x + 2.
Solution: We can represent the give polygon by the homogeneous coordinate matrix as
a) The horizontal line y = 2 has an intercept (0, 2) on y axis and makes an angle of 0 degree with the x
axis. So m = 0 and c = 2. Thus, the reflection matrix
so the new coordinates A’B’C’D’ of the reflected polygon ABCD can be found as: [A’B’C’D’] =
[ABCD]. ML
b) The vertical line x = 2 has no intercept on y-axis and makes an angle of 90 degree with the x-axis.
So m=tan900=∞ and c=0. Thus, the reflection matrix
so the new coordinates A’B’C’D’ of the reflected polygon ABCD can be found as: [A’B’C’D’] =
[ABCD]. ML
c) The line y=+2 has an intercept (0, 2) on y-axis and makes an angle of 450 with the x-aixs. So
The effect of the reflected polygon, which is shown in below figure, about the line y = 2, x = 2, and y =
x+2, and y=x+2 is shown in below figure, respectively.
3D Transformation
Rotation
we can change the size of an object using scaling transformation. In the scaling
process, we either expand or compress the dimensions of the object. Scaling can be
achieved by multiplying the original coordinates of the object with the scaling factor to
get the desired result. The following figure shows the effect of 3D scaling −
In 3D scaling operation, three coordinates are used. Let us assume that the original
coordinates are (X, Y, Z), scaling factors are (SX,SY,Sz) respectively, and the produced
coordinates are (X’, Y’, Z’). This can be mathematically represented as shown below –
Shear
A transformation that slants the shape of an object is called the shear transformation.
Like in 2D shear, we can shear an object along the X-axis, Y-axis, or Z-axis in 3D.
As shown in the above figure, there is a coordinate P. We can shear it to get a new
coordinate P', which can be represented in 3D matrix form as below –
Transformation Matrices