You are on page 1of 7
CZ, 8 orgie ™ 2-D Transformation 8.1 INTRODUCTION It is essential for a graphics system to allow the user to change the way objects appear. In the real world we frequently rearrange objects or look at them from different angles. The effecs that we desire include changing the size of the object, its position on the screen, or its orientatin, The implementation of such a change is called transformation. The term ‘transform’ means‘ change’. This change can either be of shape, Size or position of the object. To perform transformation on any object, object matrix *X’ is multiplied by the transformation matrix. Transformed object) _ [Original object] , [Transformation matrix - matrix : or ~ By} = The various transformations possible on an object are as follows: * Rotation Reflection [ © Scaling : e Translation Shearing etc. matrix Each of the above transformation is carried out by using a different transformation mattis The fundamental objective of 2-D transformation is to simulate the movement am manipulation of objects in the plane. Points and lines which join them, along with appropri drawing algorithm are used to represent objects. The ability to transform these points and lin? is achieved by translation, rotating, scaling and reflection. Two points of view are used for describing the object movement. The first is thatthe object itself is moved relative toa stations co-ordinate system or background. The mathematical statement of this view point is describ’ by geometric transformations applied to each point of the object. The second point of view hold that the object is held stationary, while the co-ordinate system is moved relative to the objet This effect is described by co-ordinate transformation. 142 0 2-DTransformation 0 is transformation is described in two categories: Geometric transformation Co-ordinate transformation transformations are used directly by application programs and within many graphic ines. PRESENTATION OF POINTS OR OBJECTS IN MATRIX FORM -ordinate system, any point is\represented in terms of x and y co-ordinates. The point in be converted into matrix in the following two ways: yw-major matrix & ye jumn-major matrix (iL, above two matrices are frequently called position vectors. A series of points, each of is a position vector relative to some co-ordinate system, is stored in a computer as a or array of numbers, The position of these points is controlled by manipulating the which defines the points. Lines are drawn between the points to generate lines, curves 8. ippose, we represent a rectangle in matrix form. Let (xj, y,) and (x2, ¥2) be the opposite ofa rectangle. Then, the four vertices of rectangle will be : (x, ¥,), (&¥1)> (292s (&y,¥a)s order to represent this rectangle in matrix formas p% Ya) © (Ya) A Eaeezt By | on c Xe Ye D. HI Rou) Boo y) EOMETRIC TRANSFORMATIONS nges in orientation, size and shape are accomplished with geometric transformations Iter the co-ordinate descriptions of objects. The basic geometric transformations are tion, rotation and scaling. Other transformations that are often applied to objects include ‘ion and shear. w Translation ‘anslation consists of a shift of the object parallel to itself in any direction in the (x) Any such shift can be accomplished by a shift in x-direction plus a shiftin y-direction. If ‘ount of x-shift is called 1, and the amount of y-shift ¢,, the translation of the point (, ») 1 point (x’, y’) is expressed by the formulas. TT ae 144 G Computer Graphics 0 ea *) = [*]4/% 2 &y) y yt ls To translate an object with multiple points, we just translate each point individually and connect them together. ‘y) Translation is a rigid-body transformation that moves objects without deformation. That is, every point on the object is translated Fig. 8.4 by the same amount. Translation is the only transformation that is not in relation to a reference point. Its effect is independent of the original position of the object. “> Lx 8.3.2. Rotation ‘A two-dimensional rotation is applied to an object by repositioning it along a circular path in the xy plane. Points can be rotated through an angle @ about the origin. The sign of angle determines the direction of . rotation. Positive values for the rotation angle defines Poy) counterclockwise rotations and negative values rotate objects in clockwise directions. {Suppose rotation by @ transforms the point P(z, y) into P@, y). Because the rotation is about the origin, the distances from r the origin to P and to P’is r are equal. | x | y= LZ» and x= reos 6cos ¢-rsing sine AT y= rsin@cos$+rsingcos@ ~*~ 7 Put the values ofxandy,weget =. Fig. 8.3. x =xcosO—ysin® sade y’ =xsin@+y cos 0. In matrix form (Row-major order) [X] = (X] [7] or [¢ y= Ex {71 Put the value of x’ and y’, we get [xcos@—ysin@ sin@+ycos6]=[x 9] [7] cos sin® -sin® cos® Po) Hence n= [ |T| = cos? 6+ sin? @ NOTE: Determinant of a pure rotation matrix is always + 1. Tn column-major order Computer Graphics 0 ‘| VE 4 ‘To translate an object with multiple points, we just translate each point individually and connect them together. Cy) Translation is a rigid-body transformation that moves objects without deformation. That is. every point on the object is translated Fig. 8.4 by the same amount. Translation is the only transformation that is not in relation to a referey, point. Its effect is independent of the original position of the object. aX Ad Fig. 8.2. 8.3.2. Rotation A two-dimensional rotation is applied to an object by repositioning it along a circularsit in the xy plane. Points can be rotated through an angle @ about the origin. The sign of angle determines the direction of rotation. Positive values for the rotation angle defines counterclockwise rotations and negative values rotate objects in clockwise directions. ‘Suppose rotation by @ transforms the point P(x, y) into P(x’, ¥). Because the rotation is about the origin, the distances from the origin to P and to P’ is r are equal. cos @ ‘ sin cos (8 + 6) =r cos @ cos 6-1 sin sin® : y =rsin(@+6)=rsin@cos@+rsingcos@ 2 * 7 Put the values of x. ana y, We get cos @—y sin @ ? =xsin @+y cos 6. In matrix form (Row-major order) (X) = (X] (7) or (X ¥1= fe 1 (7) Put the value of x’ and y’, we get [xcos@-ysin@ sin@+ycos@|=(x y] (7) _[ cos sino Hence al ee {7 | = cos? 6+ sin? @=1. Determinant of a pure rotation matrix is always + 1, In column-major order RIK £2" 7 s © 2-DTransformation 145] x’) _ (cos® -sino)/2\. yy} (sine cosa, || yi Suppose we want to rotate P’ back to point P i.e., to perform the inverse transformation or rotation, the required angle is 6. then, (n= ee ane -sin® cos _ | cos (=8) sin oy (7?\ = ie (0) el ‘cos -sin® sin® cos6 8 sin@][cos® sind py = | 88 noe ye") fe cos®||sin® cos _| ©08’@+sin?®@ — ~cos@sin6+ sin @cos8 cos@sin0+sinGcos6 sin?+ cos” @ 10 -[ ean Thus, the transformation matrix for rotation in © Anticlockwvise direction will be cos) sind ee paid © Clockwise direction will be» cos) -sin6 Es a 8.3.3. Scaling Scaling is a transformation that changes the size or shape of an object. Scaling with respect to origin can be carried out by multiplying the co-ordinate values (x, ) of each vertex of a polygon, or each endpoint of a Tine by scaling factors S, and S, respectively to produce the coordinates (x’, »’). : eae = The mathematical expression for pure scaling is a x) _(S, 0)(x x 0 Sy ily or symbolically [X’] = [7] [X] After applyiiig scaling factor or matrix an any object, coordinate is either increased or decreased depending on the value of scaling factors S, and S,. If it is greater than one, then enlargement of the object will occur and if it is less than one compression will occur, In general, for uniform scaling if S, = S, > 1, then a uniform compression ocew object becomes larger. If S, = S, <1, then a uniform compression occurs ie., the object s9) © Computer Graphics and Multimedia Application = cos (x+6) = 10s 8 cos a—rsin@ sino Since x =reosa y =rsina, y!=rsin @+a) =rsin @ cosa. + rsina cos® Therefore x!=x-cos @-y sin 6 y! =rsin a.cos 6+ rsin@ cosa yl =xsin@+y cose cos -sine] Ro-|sre cos | Fig, 4.3: Translation by factors(t,, ty) Example 2: Rotate an object defined by A 0. 9), B(L, Q), CL, 1) and D (0, 1) by 45° abe origin, Solution: Here, we are writing the co-ordinate matrix of object as row wise; Here Ryse apc = Object matrix R The object matrix is 7 Afo 0 0 I 1 Dio cos 45° sin 45° 0 Ryse =|-sin45° cos 45° 0 0 oi 1 to v2 V2 R 1 lo eg? o o1 4 = Geometrical Transformation es iy 1. ¢ oon | 2 2 pl. ita Rssanco 1 1 11*|"¥a Ye ? Se | ofvort ‘oO o\r i 1 = . nf = a 0 s\ iid 2 2/ - -e The rotation co-ordinates are Al =(0,0) 4.2.3. Scaling Transformation Scaling is the process of changing the size and proportion of the image. Alternative, itis ing the dimensions of an object. There are two the process of expanding or compressi and S,, where S, is scale factor for the factors used in scaling transformation i, Sx co-ordinate and Sy is scale factor for the y-co-ordinate IfS, =S,, then scaling transformation is said to be homogeneous and if S,=Sy >I, itis <1 it is reduction. Points after rotation can be obtained by magnification and for Sx = Sy the following equation: Pl =Sg,s, (P)

You might also like