9278 Et 5 ET
9278 Et 5 ET
e-PGPathshala
Subject: Computer Science
Paper: Computer Graphics and Visualization
Module: Basic 2D Transformations
Module No: CS/CGV/5
Quadrant 1 – e-text
Objectives:
Discussion:
Any changes done to the properties of objects are called transformations.
Transformations can be classified as ‘Geometric’, and ‘Attribute’. Geometric Transformations
involve changes to the structural properties of objects, while attribute transformations involve
changes to color, style and so on. For Ex: consider a line, whose geometric properties are
position, size, shape, and orientation while its attributes arecolor, style (dashed, dot-dash
patterns etc.).
x’=x+Tx
y’=y+Ty
P’=P+T
where P’ represents the final position of the point P and T is the translation matrix.
As shown, Let P(x,y) be the point to be rotated about origin (pivot point), by an
angle (rotation angle), so that the point P, after rotation is at P’ (x’,y’) position. Let r be the
radius vector.Here the direction from origin along P is identified as position vector of point P.
Let be the angle between position vectors of the points P and P’. Let Øbe the angle made
by position vector of point P with X-axis. So the angle made by position vector point P’ with
X-axis will be (Ø + ). Our aim is compute the coordinates of P’ in terms of other parameters
P, r, Ø, .
By completing the triangle (by dropping perpendicular on X-axis) for the position
vector of point P, and considering the cosine of angle Ø, we have
x = r cos Ø
y = r sin Ø
By completing the triangle (by dropping perpendicular on X-axis) for the position vector of
point P’, and considering the cosine of angle Ø+, we have
x’ = r cos (Ø + )
y’ = r sin (Ø + )
Substituting the equations for x and y, in the above equations for x’ and y’ , we have
x’ = x cos() - y sin()
y’ = x sin() + y cos()
P’=R ().P
Where R() is the rotation matrix.
Important Note:θ is +ve for CCW (counter Clockwise) rotations and –ve for CW (Clockwise
rotations. If the rotations, are done about any other pivot point other than origin, the
equations would be different, which we will derive later.
_________________
Example: suppose that you have a point P (2,0) to be rotated about origin by 90° CCW, what
is the new position?
Answer: The rotation matrix is given by [ ]=[ ]
Now multiply the point (2,0) with this matrix to obtain the new position,
[ ][ ] = [ ]
Thus the new position is (2,0)
__________________
Scaling (change in size):
Consider a rectangular object (The filled blue square as shown in the middle in the
above figure), which is to be scaled.Increase in size is considered as ‘upscaling’ while
decrease in size is considered as ‘down scaling’. The farthest object is the up scaled object
and the object close to origin is the down scaled version of the original object. If you observe
scaling closely, it involves two transformations (change in size and change in position), as
evident from the figure above, the up scaled object has moved to a new position away from
the origin while the down scaled object has moved close to origin. Scaling is simply
multiplying the object with values one along X-axis and one along Y-axis, i.e.,
x’=x.Sx
y’=y.Sy
P=S(Sx,Sy).P
Scaling can also be understood as holding the object and stretching or squeezing it
along x-direction and y-direction by the scaling factors Sx,Syrespectively. Scaling involves
not only change in size but also change in position. Standard scaling is performed with
respect to origin and the above equations are valid only in this case. If scaling is to be
performed with respect to another fixed position, then the equations would be different. Also
observe, for a rectangular object if scaling is to be performed with respect to its left corner
vertex, then the objects size changes, the positions of other vertices would also change
except the left corner vertex. Similarly if scaling has to be performed with respect to say
midpoint, then the object expands or contracts with respect to its mid-point.
Now putting all the three transformations together we have
P’=P+T
P’=R().P
P’=S(Sx,Sy).P
When transformations are performed, with respect to points other than origin, the
equations would be different than what we have already derived, and they will assume a
form as below i.e., for rotation, and scaling an additional 2x1 matrix whose elements (shown
as ? in the matrices below) will be derived later.
Let the additional matrix for rotation, scaling transformations performed with respect
to any other point in space be denoted as Mr and Ms respectively.So we can rewrite the
notations for the three basic transformations as shown below, intentionally, the notation for
translation is altered to include a 2x2 identity matrix multiplying P.
P’=I.P+T
P’=R().P+Mr
P’=S(Sx,Sy).P+Ms
Intentionally, the notation for translation is altered to include a 2x2 Identity matrix
multiplying P, such that all the three transformations have one common form, i.e.,each
transformation involves a matrix multiplication and a matrix addition.
Homogeneous coordinates:
Let’s have a closer look at the advantages mentioned above. The first one, says that,
when many transformations are to be performed in succession, we can simply multiply them
in that order. This matrix obtained by multiplying many matrices is called a ‘composite
matrix’.Now get the initial coordinates, multiply with composite matrix, and get final
coordinates in just one multiplication step. Thus the other advantages mentioned become
obvious.
Summary:
• Learnt how basic 2D transformations viz., Translation, Rotation, Scaling are
performed
• Also understood how homogeneous coordinates help reduce no. of matrix
operations.