Presentation is loading. Please wait.

Presentation is loading. Please wait.

Transformations contd.

Similar presentations


Presentation on theme: "Transformations contd."— Presentation transcript:

1 Transformations contd.

2 Reflections y x =  x x x =  x y =  y y =  y Initial
Reflection about y x =  x Initial Object x Reflection about origin x =  x y =  y Reflection about x y =  y

3 Matrix Representations
Reflection about x Reflection about y Reflection about the Origin

4 Reflections Reflection about x axis: Reflection about y axis:
Reflection about origin: It is rotation matrix R(θ) With θ = 180o

5 Reflection Reflection can be generalized to any reflection point in xy-plane. This reflection is the same as a 180o rotation in the xy plane using the reflection point as the pivot point. If we choose the reflection point as the diagonal line x=y, the reflection matrix is y y=x x

6 Reflection We can derive this matrix by concatenating a sequence of rotation and coordinate-axis reflection matrices. One possible sequence is: a) clockwise rotation of 45o (b) reflection about x-axis (c) counterclockwise rotation by 45o. To obtain a transformation matrix for reflection about the diagonal y = -x, we could concatenate matrices for the transformation sequence: a) clockwise rotation of 45o (b) reflection about y-axis (c) counterclockwise rotation by 45o. The resulting transformation is: Reflections about any line y=mx + c in the xy plane can be accomplished with a combination of translate-rotate-reflect transformations.

7 Shear A shearing affects an object in a particular direction (in 2D, it’s either in the x or in the y direction) A shear transformation in the x-direction (along x) shifts the points in the x-direction proportional to the y-coordinate. The y-coordinate of each point is unaffected.

8 Matrix Representations
Shear along x Shear along x (homogeneous coordinate) Shear along y Shear along y (homogeneous coordinate)

9 Shearing A shear in the x direction would be as follows:
x’ = x + h. y & y’ = y h is shear parameter The quantity h specifies what fraction of the y-coordinate should be added to the x-coordinate, and may be positive or negative -ve values for h shifts coordinate positions to the left

10 Shearing g =0, h=0.5 g=0.5, h=0.5 Shear by {g,h} Original points
Transformed points g=0.5, h=0.5 Shear by {g,h} Original points Transformed points

11 We generate x-direction shears relative to other reference lines with
With coordinate positions transformed as x’ = x + h(y- yref), y’ = y We generate y-direction shears relative to other reference lines (eg. x = xref) with x’ = x & y’ = h(x- xref) + y,

12 2D Viewing and Information Visualization

13 2D Viewing Pipeline From Computer Graphics by Hearn & Baker
Modeling coordinates Construct World Coordinate Scene Using Model-Coordinate Transformations World coordinates Convert World Coordinates to Viewing Coordinates Viewing coordinates Transform Viewing Coordinates to Normalized Coordinates Normalized coordinates Map Normalized Coordinates to Device Coordinates Device coordinates From Computer Graphics by Hearn & Baker

14

15

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

17

18

19 2D rendering pipeline

20 CLIPPING

21

22 Point Clipping For a point (x,y) to be inside the clip rectangle:

23 Point Clipping For a point (x,y) to be inside the clip rectangle:

24 Cases for clipping lines
Line Clipping Cases for clipping lines

25 Cases for clipping lines
Line Clipping Cases for clipping lines

26 Cases for clipping lines
Line Clipping Cases for clipping lines

27 Cases for clipping lines
Line Clipping Cases for clipping lines

28 Cases for clipping lines
Line Clipping Cases for clipping lines

29 Cases for clipping lines
Line Clipping Cases for clipping lines

30 Cohen-Sutherland Clipping
Basic Idea Encode the line endpoints Successively divide the line segments so that they are completely contained in the window or completely lies outside window Division occurs at the boundary of window Cohen-Sutherland Clipping Algorithm. To clip a line, we need to consider only its endpoints, not its infinitely many interior points. If both endpoints of a line lie inside the clip rectangle, the entire line lies inside the clip rectangle and can be trivially accepted. If one endpoint lies inside and one outside, the line intersects the clip rectangle and we must compute the intersection point. If both endpoints are outside the clip rectangle, the line may or may not intersect with the clip rectangle, and we need to perform further calculations to determine whether there are any intersections. To do this, Cohen-Sutherland Clipping Algorithm first encode the line endpoints. Encoding is done by four criteria. So, four bit is need to each endpoint. Is the point Above the window? (Top) Is the point Under the window? (Bottom) Is the point on the Left side of the window? (Left) Is the point on the Right side of the window? (Right) 1 for True, 0 for False. After encoding, we may accept if the line is fully inside the window, Or discard if the line is fully outside the window. 1001 1000 1010 left 0001 0000 0010 right 0101 0100 0110 bottom top

31 Four Cases outcode1 = outcode2 = 0000 --> Accept all
outcode1 OR outcode2 = > Accept all outcode1 & outcode2 != > Discard outcode1 != 0000 , outcode2 = 0000 (Vice versa) > Shorten outcode1 & outcode2 = > Discard or Shorten H D There can be four cases. First, see the line AB. Both endpoints can be encoded as So, it means that the line is fully inside the window, So Accept all. Second, see the line EF (0010 , 1010) Result of logical and operation is not 0000 (0010), and it means the it is fully outside the window, So Discard. Third, see the line CD(0000, 1010). This is the case of one endpoint inside the window and the other is not. In this case the line may be shorten. Forth, see the line GH and IJ (0001, 1000). We can not make a decision only with outcodes. Because it may be fully outside the window like line GH And it may have some intersections like line IJ. So in this case, the line may be discarded or shorten,. J F B G A C I E

32 Cohen-Sutherland Algorithm
A line segment can be trivially accepted if the outcodes of both the endpoints are zero. A line segment can be trivially rejected if the logical AND of the outcodes of the endpoints is not zero. A key property of the outcode is that bits that are set in nonzero outcode correspond to edges crossed.

33 Cohen-Sutherland Algorithm
The Cohen-Sutherland Line-Clipping Algorithm performs initial tests on a line to determine whether intersection calculations can be avoided. First, end-point pairs are checked for Trivial Acceptance. If the line cannot be trivially accepted, region checks are done for Trivial Rejection. If the line segment can be neither trivially accepted or rejected, it is divided into two segments at a clip edge, so that one segment can be trivially rejected. These three steps are performed iteratively until what remains can be trivially accepted or rejected.

34 Cohen-Sutherland Algorithm
An Example

35 Cohen-Sutherland Algorithm
An Example

36 Cohen-Sutherland Algorithm
An Example

37 Cohen-Sutherland Algorithm
An Example

38 For a line {(x1, y1), (x2, y2)} The y coordinate of the intersection point with the vertical boundary is y=y1+m(x-x1) Where x=xwmin or xwmax m=(y2-y1)/(x2-x1) Intersection with horizontal boundary x= x1+(y-y1)/m With y=ywmin or ywmax

39 Parametric Line-Clipping
(1) This is fundamentally different (from Cohen-Sutherland algorithm) and generally more efficient algorithm was originally published by Cyrus and Beck. (2) Liang and Barsky later independently developed a more efficient algorithm that is especially fast in the special cases of upright 2D and 3D clipping regions.They also introduced more efficient trivial rejection tests for general clip regions.

40 yo

41

42

43

44

45

46

47

48

49

50 Liang-Barsky Clipping
The Liang-Barsky two-dimensional line clipping algorithm uses the parametric form of a line and the clipping window to determine the clipping coordinates of lines intersecting the clipping volume. This algorithm is significantly more efficient than Cohen-Sutherland clipping.

51 Liang-Barsky Clipping
To summarize, the Liang-Barsky clipping algorithm consists of the following steps: 1. Define all line segments in parametric form. 2. Set the minimum and maximum values for u (umin = 0 and umax = 1). 3. Calculate all the u values located between umin and umax. 4. Determine whether the arbitrary values of each parametric line lie within the clipping window. a. If the line intersects, shorten the line segment via a floating-point division. b. If the line doesn’t intersect the clipping window, discard it. 5. Display all clipped line segments.

52 Polygon clipping

53 Original Polygon Clip Left Clip Right Clip Bottom Clip Top No Points Saved (c) Save P (a) Save I (b) Save I, P (d)

54 Sutherland-Hodgeman Polygon Clipping

55 Window Window (a) (b)

56 Before Clipping After Clipping

57 Clipping Polygons Extending two-dimensional line clipping to polygons involves the clipping of polygons against a clipping rectangle or against other polygons, as is the case with hidden surface removal. Polygon clipping algorithms are derived from simple line clipping algorithms. We can thus clip a polygon against the edges of a clipping rectangle. There is, however, a problem with this approach clipping concave polygons can result in several additional polygons as shown in Figure

58 Clipping Polygons

59 Clipping Polygons The illustrated problem is not encountered when working with convex polygons. The only solution to this problem is to consider the clipped region as a single polygon or to tessellate (divide) the polygon into a number of convex polygons

60 Clipping Polygons

61 Sutherland-Hodgman Polygon Clipping
Input each edge (vertex pair) successively. Output is a new list of vertices. Each edge goes through 4 clippers. The rule for each edge for each clipper is: If first input vertex is outside, and second is inside, output the intersection and the second vertex If first both input vertices are inside, then just output second vertex If first input vertex is inside, and second is outside, output is the intersection If both vertices are outside, output is nothing

62 Sutherland-Hodgman Polygon Clipping: Four possible scenarios at each clipper
outside inside outside inside outside inside outside inside v2 v2 v2 v2 v1’ v1’ v1 v1 v1 v1 Outside to inside: Output: v1’ and v2 Inside to inside: Output: v2 Inside to outside: Output: v1’ Outside to outside: Output: nothing

63 Sutherland-Hodgeman Algorithm: Combination of the 4 Passes

64

65

66 Sutherland-Hodgeman Algorithm:

67 Polygon Clipping Example

68

69 Text Clipping (1)

70 Text Clipping (2)

71 Text Clipping (3)

72


Download ppt "Transformations contd."

Similar presentations


Ads by Google