UNIT 2 2D TRANSFORMATIONS Introduction With the procedures for displaying output primitives and their attributes, we can create variety of pictures and graphs. In many applications, there is also a need for altering or manipulating displays. Design applications and facility layouts are created by arranging the orientations and sizes of the component parts of the scene. And animations are produced by moving the "camera" or the objects in a scene along animation paths. Changes in orientation, size, and shape are accomplished with geometric transformations that alter the coordinate descriptions of objects. The basic geometric transformations are translation, rotation, and scaling. Other transformations that are often applied to objects include reflection and shear. 2D TRANSFORMATIONS AND MATRICES Representation of Points: 2 x 1 matrix: x y General Problem: B = T A T represents a generic operator to be applied to the points in A. T is the geometric transformation matrix. If A & T are known, the transformed points are obtained by calculating B. General Transformation of 2D points Solid body (size and shape does not change) transformations - above equation is valid for all set of points and lines of the object being transformed. 1
Special cases of 2D transforms T= identity matrix, a=d=1, b=c=0 => x'=x, y'=y Scaling A scaling transformation alters the size of an object b=0, c=0 => x' = a.x, y' = d.y; This is scaling by a in x, d in y. If, a=d >1,we have enlargement; If, 0< a=d < 1,we have compression; If a=d, we have uniform scaling, else non uniform scaling or differential scaling. Scale matrix: let Sx =a, Sy =d Sx 0 0 Sy Example of Scaling 2
If Sx and/ or Sy< 0 are negative reflections are obtained through an axis or plane. Only diagonal terms involved in scaling and reflections. Reflection A transformation that produces a mirror image of an object - Shearing - Shear transformation distorts the shape of the object. - This effect causes the object to be pushed to one side as it it was constructed of layers that slide on top of each other. - Off diagonal terms are involved in Shearing. 3
a = d = 1 let, c = 0, b = 2 x' = x y' = 2x+ y y' depends linearly on x; This effect is called shear. Similarly for b=0, c not equal to zero. The shear in this case is proportional to y- coordinate. Rotation A two-dimensional rotation is applied to an object by repositioning it along a circular path in the xy plane. x' = xcos(θ) - ysin(θ) y' = xsin(θ) + ycos(θ) In matrix form, this is : cos(θ) -sin(θ) sin(θ) cos(θ) 4
Positive Rotations can be achieved if rotation is in counter clockwise about the origin Negative rotations can be achieved if rotation is in clockwise about the origin For rotations, det T = 1 and T T = T -1, Rotation matrices are orthogonal. Transformation of a unit square Take a square with coordinates (0,0),(1,0),(1,1),(0,1) Then the matrix will be represented as The transformation on the matrix S with a Transformation matrix T = 5
S = S * T The unit square after applying transformation is shown in fig. as is changed to rhombus structure. Area of the unit square after transformation = ad bc = T This can be extended to any arbitrary area of any polygon. Translation 6
The translations are introduced with 1) Rotations -when object not centered at the origin. 2) Scaling -when objects / lines not centered at the origin. If line intersects the origin, no translation we cannot directly represent translations as matrix multiplication, as we can rotations and scalings. we can represent translations in our general transformation matrix by using homogeneous coordinates. 7
HOMOGENEOUS COORDINATES Each point is now represented by a triple: (x, y, W) ( x/w, y/w) are called the Cartesian coordinates of the homogeneous points. 8
Interpretation of homogeneous coordinates Triples of coordinates typically represent points in 3D space but here we are using them to represent points in 2D space. If we take all triples representing the same point that is all triples of the form (tx,ty,tw) with w 0, we get a line in 3D space. Thus each homogeneous point represents a line in 3D space. If we homogenize the point (divide by w), we get a point of the form(x,y,1). Thus the homogenized points form the plane defined by the equation w=1 in (x,y,w) space. The following fig. shows this relationship. Fig. The XYW homogeneous coordinate space with the w=1 plane and point P(X,Y,W) projected onto the W=1 plane. Two homogeneous coordinates (x1, y1, w1) & (x2,y2, w2) may represent the same point, iff they are multiples of one another: (1,2,3) & (3,6,9). There is no unique homogeneous representation of a point. All triples of the form (tx, ty, tw) form a line in x,y,w space. Cartesian coordinates are just the plane w=1 in this space. W=0, are the points at infinity 9
General purpose 2D transformations in homogeneous coordinate representation Parameters involved in scaling, rotation, reflection and shear are a, b, c, d If B = T.A then Translation parameters: ( p, q ) If B = A. T then Translation parameters: ( m, n ) COMPOSITION OF TRANSFORMATIONS If we want to apply a series of transformations T1, T2, T3 to a set of points, We can do it 2 ways: 1) We can calculate p'=t1*p, p'' = T2*p', p'''=t3*p'' 2) Calculate T= T1*T2*T3, then p'''= T*p. Method 2, saves large number of adds and multiplies. Approximately 1/3 as many operations. Therefore, we concatenate or compose the matrices into one final transformation matrix that we apply to the points. Translation Translate the points by tx1, ty1, then by tx2, ty2: 10
Scaling Scale the point by sx1,sy1 then by sx2,sy2. Rotation Rotate by θ1, then by θ2, 1) stick the (θ1+ θ2) in for θ, or 2) calculate T1 for θ1, then T2 for θ2 & multiply them. Gives same result Rotation about an arbitrary point P in space As we mentioned before, rotations are about the origin. So to rotate about a point P in space, translate so that P coincides with the origin, then rotate, then translate back. Steps are Translate by (-Px, -Py) Rotate Translate by (Px, Py) 11
T = T1(Px,Py) * T2(θ) * T3(-Px, -Py) Scaling about an arbitrary point in Space Again, Translate P to the origin Scale Translate P back T = T1(Px,Py) * T2(sx, sy)* T3(-Px, -Py) Reflection through an arbitrary line Reflections about any line y = mx + b in the xy plane can be accomplished with a combination of translate rotate-reflect transformations. In general, we first translate the Line so that it passes through the origin. Then we can rotate the line onto one of the coordinate axes and reflect about that axis. Finally, we restore the line to its original position with the inverse rotation and translation transformations. Steps: Translate line to the origin Rotation about the origin Reflection matrix Reverse the rotation Translate line back 12
Commutivity of Transformations Matrix multiplication is associative. For any three matrices, A, B, and C, the matrix product A. B. C can be performed by first multiplying A and B or by first multiplying B and C: A. B.C = (A.B).C = A. (B. C) Therefore, we can evaluate matrix products using either a left-to-right or a right to left associative grouping. On the other hand, transformation products may not be commutative: The matrix product A. B is not equal to B. A, in general. This means that if we want to translate and rotate an object, we must be careful about the order in which the composite matrix is evaluated. For some special cases, such as a sequence of transformations all of the same kind, the multiplication of transformation matrices is commutative. The following table shows the cases where T1 * T2 = T2 * T1 T1 translation scale rotation scale(uniform) T2 translation scale rotation rotation 13
Example: Order: R G B Fig.a fig.b In Figure a, the object is first scaled and then translated. In figure b, the object is first translated and then scaled. As seen in figs. both are not identical. Fig.c Fig.d In Figure c, the object is first rotated and then differential scaling is applied. In figure d, the object is first differentially scaled and then rotated. As seen in figs. both are not identical. In general, multiplication of transformation matrices is not commutative. 14
COORDINATE SYSTEMS Screen Coordinates: The coordinate system used to address the screen ( device coordinates) World Coordinates: A user-defined application specific coordinate system having its own units of measure, axis, origin, etc. Window: The rectangular region of the world that is visible. Viewport: The rectangular region of the screen space that is used to display the window. WINDOW TO VIEWPORT TRANSFORMATION The purpose is to find the transformation matrix that maps the window in world coordinates to the viewport in screen coordinates. Viewport: (u, v space) denoted by: u min, v min, u max, v max Window: (x, y space) denoted by: x min, y min, x max, y max 15
The overall transformation: Translate the window to the origin Scale it to the size of the viewport Translate it to the viewport location M WV -> Transformation matrix to convert Window to view port. Summary: The basic geometric transformations are translation, rotation, and scaling. Translation moves an object in a straight-line path from one position to another. Rotation moves an object from one position to another in a circular path around a specified pivot point (rotation point). Scaling changes the dimensions of an object relative to a specified fixed point. We can express two-dimensional geometric transformations as 3 by 3 matrix operators, so that sequences of transformations can be concatenated into a single composite matrix. This is an efficient formulation, since it allows us to reduce computations by applying the composite matrix to the initial coordinate positions of an object to obtain the final transformed positions. 16
To do this, we also need to express two-dimensional coordinate positions as threeelement column or row matrices. We choose a column-matrix representation for coordinate points because this is the standard mathematical convention and because many graphics packages also follow this convention. For twodimensional transformations, coordinate positions are: then represented with three-element homogeneous coordinates with the third (homogeneous) coordinate assigned the value. I. Composite transformations are formed as multiplications of any combination of translation, rotation, and scaling matrices. Other transformations include reflections and shears. Reflections are transformations that rotate an object 180" about a reflection axis. This produces a mirror image of the object with respect to that axis. When the reflection axis is perpendicular to the xy plane, the reflection is obtained as a rotation n the xy plane. When the reflection axis is in the xy plane, the reflection is obtained as a rotation in a plane that is perpendicular to the xy plane. Shear transformations distort the shape of an object by shifting x or y coordinate values by an amount to the coordinate distance from a shear reference line 2 Marks 1. What is Transformation? Transformation is the process of introducing changes in the shape size and orientation of the object using scaling rotation reflection shearing & translation etc. 2. Write short notes on active and passive transformations? In the active transformation the points x and x represent different coordinates of the same coordinate system. Here all the points are acted upon by the same transformation and hence the shape of the object is not distorted. In a passive transformation the points x and x represent same points in the space but in a different coordinate system. Here the change in the coordinates is merely due to the change in the type of the user coordinate system. 3. What is translation? Translation is the process of changing the position of an object in a straight-line path from one coordinate location to another. Every point (x, y) in the object must under go a displacement to (x,y ). the transformation is: x = x + tx ; y = y + ty 4. What is rotation? A 2-D rotation is done by repositioning the coordinates along a circular path, in the x-y plane by making an angle with the axes. The transformation is given by: x' = xcos(θ) - ysin(θ) y' = xsin(θ) + ycos(θ) 17
5. What is scaling? The scaling transformations changes the shape of an object and can be carried out by multiplying each vertex (x,y) by scaling factor Sx,Sy where Sx is the scaling factor of x and Sy is the scaling factor of y. 6. What is shearing? The shearing transformation actually slants the object along the X direction or the Y direction as required.ie; this transformation slants the shape of an object along a required plane. 7. What is reflection? The reflection is actually the transformation that produces a mirror image of an object. For this use some angles and lines of reflection. 8. Distinguish between window port & view port? A portion of a picture that is to be displayed by a window is known as window port. The display area of the part selected or the form in which the selected part is viewed is known as view port. 9. Define clipping? Clipping is the method of cutting a graphics display to neatly fit a predefined graphics region or the view port. 10. What is covering (exterior clipping)? This is just opposite to clipping. This removes the lines coming inside the windows and displays the remaining. Covering is mainly used to make labels on the complex pictures. 11. What is the need of homogeneous coordinates? To perform more than one transformation at a time, use homogeneous coordinates or matrixes. They reduce unwanted calculations intermediate steps saves time and memory and produce a sequence of transformations. 12. Distinguish between uniform scaling and differential scaling? When the scaling factors sx and sy are assigned to the same value, a uniform scaling is produced that maintains relative object proportions. Unequal values for sx and sy result in a differential scaling that is often used in design application. 13. What is fixed point scaling? The location of a scaled object can be controlled by a position called the fixed point that is to remain unchanged after the scaling transformation..14. Determine a sequence of basic transformations that are equivalent to the x-direction shearing matrix. 18
15. Why are matrices used for implementing transformations. Matrices allow arbitrary linear transformations to be represented in a consistent format, suitable for computation. This also allows transformations to be concatenated easily (by multiplying their matrices). Review Questions: 1. Explain reflection and shear? 2. Explain Basic Transformations with procedure 3. Explain LCD and LED. 4. Derive the rotation transformation for rotating a point w.r.t. an arbitrary point. 5. Transform a square with vertices A(2,0), B(6,0), C(6,6) and D(2,6) to half its size and placed at location such that the centre of square moves to (0,0). What will be the effect of shearing this transformed square with x-shearing factor as 2? 6. What is the difference between a window and viewport? Derive the window-toviewport transformation of a point P(4,4) inside a circular window of radius 6 and centre (2,2) transformed onto a circular viewport of radius 3 and centre (-1,-1). 7. The triangle position is A(1,1),B(3,5) and C(2,2), translate the given triangle with respect to its centroid with A in the centroid position and rotate it by an angle 30.after shrinking the object half the size. 8. Describe the matrix formulation of 2-D transformations; translation, rotation and scaling. 9. Device the window-to-view port transformation and Elaborate.. 10. What is shearing transformation? Write down the X-direction shearing matrix for two dimension. Determine a sequence of basic transformations that are equivalent to the X-direction shearing. 19