Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
13 views

CG Unit2

Uploaded by

zeenat parveen
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

CG Unit2

Uploaded by

zeenat parveen
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Computer Graphics and Animation: Unit 2

2-D Geometric Transformation and Viewing

1. Transformations
2. Translation
3. Rotation
4. Scaling
5. Shearing

TRANSFORMATIONS

BASIC TRANSFORMATIONS

Consider the xy-coordinate system on a plane. An object (say Obj) in a place


can be considered as a set of points. Each object point P has coordinates (x,
y), so the object is the sum total of all its coordinate points (see in figure1). Let
the object be moved to a new position. Many coordinate points P’(x’, y’) of a
new object Obj’ can be obtained from the original points P(x, y) by the application
of a geometric transformation.

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

Example: Translate a square ABCD with the coordinates

A(0, 0), B(5, 0), C(5, 5), D(0, 5) by 2 units in x-direction and 3 units in y-
direction.

Solution: we act as the given square, in matrix form, using homogeneous


coordinate of vertices as:

The translation factors are, tx = 2, ty = 3 The transformation matrix for translation:


New object point coordinates are:[A’B’C’D’] = [ABCD].Tv

Thus, A’(x’1, y’1) = (2, 3)

B’(x’2, y’2) = (7, 3)

C’(x’3, y’3) = (7, 8)

D’(x’4, y’4) = (2, 8)

The graphical representation is given below:

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)

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.
P(x, y) = P(r.cosɸ, r.sinɸ)

P’(x’, y’) = P[r.cos(ɸ+θ), r.sin(ɸ+θ)]

The coordinates of P’ are:

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:

This is P’ = P.Rθ............................................................................................................. (5)

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:

Thus, A’ = (0, 0), B’ = (0, √2), C’ = (3√2/2, 7√2/2)


The following below figure shows the original, triangle [ABC] and figure shows triangle
after the rotation.

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:

x' = x.sx ….(8)

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.

For example, assume s x > 1.

i. Consider (x, y) → (2.x, y) i.e., Magnification in x-direction with scale factor s x = 2.


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.s x, y) where 0 < s x = y2 < 1 i.e., Compression in x-direction
with scale factor s x = ½.

The general scaling is (x, y) → (x.s x, y.sy) i.e., magnifying or compression in


both x and y directions depending on Scale factors s x and s y. We can act this
in matrix form (2-D Euclidean system) as:

In terms of HCS, equation (9) becomes:

That is P’h = Ph.ssx,sy ........................................................................................... (11)


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.
Solution: Magnification and reduction can be attained by a uniform scaling of s units in
both the x and y directions. If, s>1, the scaling produces magnification. If, s<1, the
result is a reduction. The transformation can be written as: (x,y,1) → (s,x,s.y,1). In matrix
form this becomes.

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:

Thus, A’ = (0,0), B’ = (2, 2), C’ = (10, 4)


(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 sk = sy =
2 and (c) with s x = 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.

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

In terms of Homogeneous Coordinates, equation (12) becomes

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

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

In terms of Homogeneous Coordinates, equation (16) becomes.

That is, P’h = Ph.Shy(b) ..................................................... (18)


XY-SHEARS ABOUT THE ORIGIN

Let an object point P(x, y) be moved to P’(x’, y’) as a result of shear


transformation in both x and y directions with shearing factors a and b,
respectively, as shown in below figure.

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.

In matrix form, we have,

In terms of Homogeneous Coordinates, we have

That is, P’h = Ph.Shxy(a, b) ....................................................... (22)


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:

a) The matrix of x-shear is:

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)

Thus, A’ = (0, 0), B’ = (1, 0), C’ = (3, 1) and D’ = (2, 1).

b) Similarly the effect shearing in the y direction can be found as: [A’B’C’D’] =
[ABCD].Shy(b)

Thus, A’ = (0, 0), B’ = (1, 3), C’ (1, 4) and D’ = (0, 1)


c) Finally the effect of shearing in both directions can be found as: [A’B’C’D] =
[ABCD].Shxy(a, b)

thus, A’ = (0, 0), B’ = (1, 3), C’ = (3, 4) and D’ = (2, 1).

Figure (a) shows the original square, figure (b)-(d) shows shearing in the x, y
and bot directions respectively.
COMPOSITE TRANSFORMATIONS

1. Rotation About A Point


2. Reflection About A Line

ROTATION ABOUT A POINT

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:

Rθ,A = T-v, Rθ. Tv


Example: Perform a 450 rotation of a triangle A(0, 0), B(1, 1), C(5, 2) about an arbitrary point
P(-1, -1).

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)

In transformation notation, we have

ML = T-V.R-θ.MX.Rθ.TV where v=0I+cJ

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.

1. Rotate the line L through 450 in clockwise rotation.


2. Perform the required Reflection about the x-axis.
3. Rotate back the line L by – 450 i.e.,

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

Thus, A’ = (-1, 4), B’=(0, 6), C’=(1, 4) and D’=(0, 2).

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

thus, A’=(5, 0), B’=(4, -2), C’(3, 0) and D’=(4, 2)

c) The line y=+2 has an intercept (0, 2) on y-axis and makes an angle of 450 with the x-aixs. So

m=tan450 =1 and c=2. Thus, the reflection matrix


The required coordinates A’, B’, C’, and D’ can be found as: [A’B’C’D’]=[ABCD]. ML

Thus, A’ = (-2, 1), B’ = (-4, 2), C’ = (-2, 3) and D’ = (0, 2)

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

3D rotation is not same as 2D rotation. In 3D rotation, we have to specify the angle of


rotation along with the axis of rotation. We can perform 3D rotation about X, Y, and Z
axes. They are represented in the matrix form as below −

The following figure explains the rotation about various axes −


Scaling

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

Transformation matrix is a basic tool for transformation. A matrix with n x m dimensions


is multiplied with the coordinate of objects. Usually 3 x 3 or 4 x 4 matrices are used for
transformation. For example, consider the following matrix for various operation.

You might also like