2 D Geometrical Transforms and Viewing Part 1 Eng 19
2 D Geometrical Transforms and Viewing Part 1 Eng 19
co
1 | Page
www.gradeup.co
2-D Geometric Transformation and Viewing Part-1
Content:
1. Transformations
2. Translation
3. Rotation
4. Scaling
5. Shearing
TRANSFORMATIONS
BASIC TRANSFORMATIONS
TRANSLATION
2 | Page
www.gradeup.co
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 = t xI + tyJ,
where tx and ty is the translation factor in x and y directions, such that
P’ = P + V …………..(1)
𝑥 ′ = 𝑥 + 𝑡𝑥 𝑎𝑛𝑑
𝑇𝑣 = { ……………(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.
as:
3 | Page
www.gradeup.co
[A’B’C’D’] = [ABCD].Tv
ROTATION
4 | Page
www.gradeup.co
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:
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θ
5 | Page
www.gradeup.co
Case 1: Rotation about the origin
Given a 2-D point P(x, y), which we want to rotate, with respect to the origin O.
the vector OP has a length ‘r’ and making a positive (anticlockwise) angle ɸ with
respect to x-axis.
Let P’(x’y’) be the result of rotation of point P by an angle ɸ about the origin,
which is shown in below figure.
Similarly,
= xsinθ + ycosθ
Thus,
6 | Page
www.gradeup.co
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’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, Ph, 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.
7 | Page
www.gradeup.co
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:
The following below figure shows the original, triangle [ABC] and figure shows
triangle after the rotation.
8 | Page
www.gradeup.co
SCALING
Let P(x, y) by any point of a given object and sx and sy by scalling 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.
9 | Page
www.gradeup.co
ii. Similarly, assume sy > 1 and consider (x, y) → (x, 2.y), i.e. Magnification in y –
direction with scale factor sy = 2.
iii. Consider (x, y) → (x.sx, y) where 0 < sx = y2 < 1 i.e., Compression in x-direction
with scale factor sx = ½.
10 | P a g e
www.gradeup.co
Example: Find the new coordinates of a triangle A(0, 0), B(1, 1), C(5, 2) after it
has been (a) magnified to twice its size and (b) reduced to half its size.
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:
11 | P a g e
www.gradeup.co
(b) Similarly, here, s = ½ and the new coordinates are A’’=(0, 0), B’’ = (1/2, 1/2),
C’’ = (5/2,1). The following figure (b) shows the effect of scaling with s k = sy =
2 and (c) with sx = sy = s = 1/2.
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.
12 | P a g e
www.gradeup.co
X-SHEAR ABOUT THE ORIGIN
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
y’ = y = Shx(a) ….……(11a)
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
13 | P a g e
www.gradeup.co
That is, P’h = PhSHx(a) ………..(14)
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.
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
y’ = y + bx = Shy(b) ………..(15)
where ‘b’ is a constant (known as shear parameter) that measures the degree
of shearing. In matrix form, we have
14 | P a g e
www.gradeup.co
That is, P’h = Ph.Shy(b) ………..(18)
The points P(x, y) and P’(x’, y’) have the following relationship:
x’ = x + ay
y’ = y + bx = Shxy(a, b) ………..(19)
where ‘ay’ and ‘bx’ are shear factors in x and y directions, respectively. The xy-
shear is also called simultaneous shearing for short.
15 | P a g e
www.gradeup.co
Example: A square ABCD is given with vertices A(0, 0), B(1, 0), C(1, 1), and
D(0, 1). Illustrated the effect of a) x-shear b) y-shear and c) xy-shear on the
given square, when a = 2 an b = 3
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)
16 | P a g e
www.gradeup.co
c) Finally the effect of shearing in both directions can be found as: [A’B’C’D] =
[ABCD].Shxy(a, b)
Figure (a) shows the original square, figure (b)-(d) shows shearing in the x, y
and both directions respectively.
17 | P a g e
www.gradeup.co
18 | P a g e