1 / 94

2D Transformation of Graphics

2D Transformation of Graphics. Unit 2. What is geometric transformation? Operations that are applied to the geometric description of an object to change its position, orientation, or size are called geometric transformations.

Download Presentation

2D Transformation of Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 2D Transformation of Graphics Unit 2

  2. What is geometric transformation? • Operations that are applied to the geometric description of an object to change its position, orientation, or size are called geometric transformations.

  3. So the geometric-transformation functions that are available in some system are following: • Translation • Rotation • Scaling • Other useful transforms includes: reflection and shear.

  4. Translation • Rotation

  5. Scaling • Uniform Scaling • Un-uniform Scaling

  6. Reflection • Shear

  7. Why do we need geometric transformations in CG( motivation )? • As a viewing aid • As a modeling tool • As an image manipulation tool

  8. Two-Dimensional(2D) Translation We perform a translation on a single coordinate point by adding offsets to its coordinates so as to generate a new coordinate position. Similarly, a translation is applied to an object that is defined with multiple coordinate positions by relocating all the coordinate positions by the same displacement along parallel paths. Suppose tx and ty is the translation distances, (x, y) is the original coordinates, is the new coordinate position.

  9. Express the translation use matrix equation as following: • Translation is a rigid-body transformation that moves objects without deformation. • Ex: Translate a polygon with coordinates A(2, 5), B(7, 10), C(10, 2) by 3 units x direction and 4 units in y direction (Hint : Add 3 to all x values and 4 to all values).

  10. Write a C++ program to translate : • A point • A line • A Rectangle • A Polygon (Triangle)

  11. /* C++ program */ #include<iostream.h> #include<graphics.h> #include<math.h> void main() { clrscr(); int x,y,tx,tx; /* initialise graphics ------------------------ */ detectgraph(&gd,&gm); initgraph(&gd,&gm,“c:\\tc\\bgi");

  12. cout<<“Enter x, y:” cin>>x>>y; cout<<“Enter tx,ty” cin>>tx>>ty; putpixel(x,y,15); delay(100); putpixel(x+tx,y+ty,15); getch(); closegraph();}

  13. Translate a line: line(x1,y1,x2,y2); line(x1+tx,y1+ty,x2+tx,y2+ty);

  14. Translate a rectangle: rectangle(x1,y1,x2,y2); rectangle(x1+tx,y1+ty,x2+tx,y2+ty);

  15. Two-Dimensional Rotation • We generate a rotation transformation of an object by specifying a rotation axis and a rotation angle. All points of the object are then transformed to new positions by rotating the points through the specified angle about the rotation axis. • A 2D rotation of an object is obtained by repositioning the object along a circular path in the xy plane, the rotation axis is perpendicular to the xy plane. • Parameters for 2D rotation is rotation angle and a rotation point( pivot point) . • Rotation angle define a positive values for counterclockwise rotation about the pivot point.

  16. r is the constant distance of the point form the origin, angle is the original angular position of the point from the horizontal, and is the rotation angle. • Substitute expression (1) into (2) (1) (2)

  17. (3) Matrix form P’=P.R

  18. Example 1 • A point (4, 3) is rotated by an angle of 45 degrees. Find the rotation matrix and resultant point. • Rotate a line from A(0,0) to B(200,100) by 45 degrees. • Rotate a polygon with coordinates A(2, 5), B(7, 10), C(10, 2) by an angle of 45 degrees.

  19. Write a C program to Rotate : • A point • A line • A Rectangle • A Polygon (Triangle)

  20. Two-Dimensional(2D) Scaling • To alter the size of an object, we apply a scaling transformation. A simple two-dimensional scaling operation is performed by multiplying object positions (x, y) by scaling factors sx and sy to produce the transformed coordinate . • Scaling factors sx scales an object in the x coordinate.

  21. Properties of the scaling transformation. • Any positive values can be assigned to the scaling factors sx and sy. Values less then 1 reduce the size of object, the object will close up the original at the same time. In contrast , enlarge the size of object. • When sx and sy are assigned to the same values, a uniform scaling is produced which maintains relative object proportions.

  22. Unequal values for sx and sy result in a differential scaling that is often used in design applications. • Negative values can also be specified for the scaling parameters, this not only resizes an object, it reflects the object one or more of the coordinate axes.

  23. Write a C++ program to scale : • A point • A line • A Rectangle • A Polygon (Triangle)

  24. Point: cout<<“Enter x, y:” cin>>x>>y; cout<<“Enter sx,sy” cin>>sx>>sy; Initgraph(&gd,&gm,”..\\bgi”); putpixel(x,y,15); delay(100); putpixel(x*sx,y*sy,15); getch(); closegraph();}

  25. Scale a line: line(x1,y1,x2,y2); line(x1*sx,y1*sy,x2*sx,y2*sy);

  26. Scale a rectangle: rectangle(x1,y1,x2,y2); rectangle(x1*sx,y1*sy,x2*sx,y2*sy);

  27. Q. Scale the polygon with coordinates A(2,5) B(7,10) and C(10,2) by two units in x-direction and two units in y-direction and plot the graph. Q. Scale the polygon with coordinates A(2,5) B(7,10) and C(10,2) by -2 units in x-direction and 3 units in y-direction and plot the graph.

  28. Matrix Representations and Homogeneous Coordinates • It is well known that many application involves sequences of geometric transformations. For example, an animation might require an object to be translated, rotated and scaled at each increment of the motion. If you want to first rotates an object, then scales it, you can combine those two transformation to a composite transformation like the following equation:

  29. However, it will be difficult to deal with the above composite transformation and translation together. Because, translation is not 2 by 2 matrix representation. • So ,here we consider how the matrix representations discussed in the previous sections can be reformulated so that such transformation sequences can be efficiently processed.

  30. In fact, we can expressed three basic two-dimensional transformation( translation, rotation, and scaling) in the general matrix form: • Now this equation can be reformulated to eliminate the matrix addition operation using Homogeneous Coordinates.

  31. What is Homogeneous Coordinates? • A standard technique for expanding each two-dimensional coordinate position representation (x, y) to three-element representation , called Homogeneous Coordinates, where homogeneous h is a nonzero value such that • For geometric transformation, we can chose the homogeneous parameter h to be any nonzero value. Thus there are an infinite number of equivalent homogeneous representations for each coordinate point (x, y) .

  32. A convenient choice is simply to set h=1, so each two-dimensional position is then represented with homogeneous coordinate (x,y,1). • Expressing positions in homogenous coordinates allows us to represent all geometric transformation equations as matrix multiplications, which is the standard method used in graphics systems. Two dimensional coordinate positions are represented with three-elements column vectors, and two-dimensional transformation operations are expressed as 3X3 matrices.

  33. Homogeneous coordinate representation of 2D Translation • This translation operation can be written in the abbreviated form

  34. Homogeneous coordinate representation of 2D Rotation This translation operation can be written in the abbreviated form

  35. Homogeneous coordinate representation of 2D Scaling This scaling operation can be written in the abbreviated form

  36. Two-Dimensional Composite Transformation • Using matrix representations, we can set up a sequence of transformation as a composite transformation matrix, by calculating the product of the individual transformations. • And, since many positions in a scene are typically transformed by the same sequence, its is more efficient to first multiply the transformation matrices to form a single composite matrix. • So the coordinate position is transformed using the composite matrix M, rather than applying the individual transformations M1 and then M2

  37. (xr,yr) (xr,yr) (xr,yr) (xr,yr) General Two-Dimensional Pivot-Point Rotation (Rotation about an arbitrary point) • So we can generate a 2D rotation about any other pivot point (x, y) by performing the following sequence of translate-rotate-translate operations.

  38. (1) Translate the object so that the pivot-point position is moved to the coordinate origin. • (2) Rotate the object about the coordinate origin. • (3) Translate the object so that the pivot point is returned to its original position. • The composite transformation matrix for this sequence is obtained with the concatenation:

  39. Problems: • Perform the rotation of a point A(2,3) about point (1,1) by angle of 45 degrees. • Perform the rotation of a point A(2,3), B(5,5), C(4,3) about point (1,1) by angle of 45 degrees.

  40. X axis • yaxis • Other 2D transformations: • Reflection with respect to the axis y 1 y 1 1’ 2 3 2 3 3’ 2’ x x 2’ 3’ 1’

  41. y x • Reflection with respect to a line y=x

  42. y y x x • Shear • Two common shearing transformations are those that shift coordinate x values and those that shift y values. • An x-direction shear relative to the x axis is produced with the transformation matrix x’ = x + shx · y, y’ = y (1,1) (0,1) (2,1) (3,1) (0,0) (1,0) (0,0) (1,0)

  43. Y-Shear x’ = x , y’ = y + shy*x

  44. Thank You!!

More Related