Download presentation

Presentation is loading. Please wait.

Published byAndy Mabbitt Modified over 7 years ago

1
CGPage: 1 We can define a window as a rectangular region of the world coordinate space, and the viewport as a rectangular region of the device coordinate system. 4.1 Window-to-viewport Mapping (0,1/2) (-1,1) (1,1) (0,0) (1,1) WINDOW VIEWPORT (Normalize) (3/4,1) (1/4,0) (Distortion) (0,1/2) (-1,1) (1,1) WINDOW

2
CGPage: 2 The problem is to "map" coordinates from the window units into the viewport units. Derive the mapping from (x w,y w ), a coordinate in the window, to (x v, y v ), the corresponding point in the viewport: Remove window coordinate system x 1 = y 1 = The problem is to "map" coordinates from the window units into the viewport units. Derive the mapping from (x w,y w ), a coordinate in the window, to (x v, y v ), the corresponding point in the viewport: Remove window coordinate system x 1 = y 1 = (cx w,cy w ) (cx v,cy v ) sx w sy w sy v windowviewport sx v (x w,y w ) (x v,y v ) (cx w,cy w ) sx w sy w window (x 1,y 1 )

3
CGPage: 3 (cx v,cy v ) sy v viewport sx v (x 2,y 2 ) Convert units x 2 = y 2 = Remove to viewport center x v = y v = so x v = y v = (1) What happens if the ratios sx v /sx w and sy v /sy w are not equal? (2) If you want a set of data in the window, how do you decide the size of the window?

4
CGPage: 4 (3) Can the window-to-viewport mappintg represented in matrix form?

5
CGPage: 5 u Homework: Find the transformation matrix that will map points contained in a window whose lower left corner is at (2,2) and upper right corner is at (6,5) onto a viewport that has a lower left corner at (1/2, 1/2) and upper right corner at (1,1).

6
CGPage: 6 (4) Derive the window to viewport mapping for viewports defined on devices which have the origin at the upper left of the screen, with the horizontal coordinate increasing right, and the vertical coordinate increasing down. h (0,0) window x y v (100,100) viewport (80,80) (100,100)

7
CGPage: 7 The process of clipping decides which part, if any, of a primitive lies inside the window. The algorithms used for line clipping can be divided into two parts: (1) Check all the line segments and separate those that intersect the window boundary. (The curve is represented by a sequence of line segment) (2) Clip the line segments obtained from step 1 by calculating their intersections with the window boundaries. Clipping 4.2 2D Clipping

8
CGPage: 8 (1) How can we sure that a line segment is totally inside the window (such as A) ? Both endpoints of the segment fall within the boundaries. (2) How can we sure that a line segment is totally outside the window (such as E,F,G)? Let two endpoints are (x 1,y 1 ),(x 2,y 2 ) If ( max{x 1,x 2 } x max or max{y 1,y 2 } y max ) then the line segment is totally outside the window. We introduce an efficient procedure, the Cohen-Sutherland algorithm, to check the intersection property and further clip the line segment if necessary. X min X max Y min Y max A B C D E F G

9
CGPage: 9 Cohen-Sutherland Algorithm The 2D plane is divided into 9 regions. Each region is designated by a 4-bit (base 2) integer code. Each bit of the code is set to 1 (true) or 0 (false), starting with the left most one. The bits are assigned by the follow rule: bit 1 = 1 if the region is above the window. bit 2 = 1 if the region is below the window. bit 3 = 1 if the region is on the right of the window. bit 4 = 1 if the region is on the left of the window. X min X max Y min Y max (1001) (0001)(0000)(0010) (0100)(0110) (1000)(1010) (0001)

10
CGPage: 10 (1) Given a point (x,y), we would like to assign a "region code" to it by using Cohen-Suterlandalgorithm. In C this can be coded: code = 0 if (x < x min ) code = 1 if (x > x max ) code = 2 if (y < y min ) code += 4 if (y > y max ) code += 8 (2) According to the C code in (1), what code will be assigned if the point is on the boundary of the window? (0000) 0 (3) How about the point on the line X max and not on the boundary of the window? (0100) or (1000) depending on y

11
CGPage: 11 (4) Draw precise picture for the partition of 2D plane according to the C code in (1). (Using solid line and dotted line) Let's consider the line clipping now. At first, the visibility of the line segment is determined as follows: (1) Visible -> Both endoint codes are (0000).

12
CGPage: 12 (2) Invisible -> Bitwise logical AND of the endpoint codes is not (0000). (3) Indeterminate -> Bitwise logical AND of the endpoint codes is (0000), but at least one of the endpoint does not have a (0000) code. On the third situation, the line endpoints are "pushed" towards the boundary line until the first or the second situation occurs. (0001) (0010) (0000) Y max Y min X min X max

13
CGPage: 13 The algorithm steps: 1. Calculate IC1 and IC2, the code of the two endpoints. 2. If (IC1 + IC2.eq. 0) then "Visible". 3. If ( (IC1.AND. IC2).NE. 0) then "Invisible". 4. If ( IC1.EQ. 0) then { Swap(IC1, IC2); Swap(X1,X2); Swap(Y1,Y2); } // At lease one point is outside the // viewport. Insure that point #1 is // one of the outside point. 5. Push endpoint #1 towards X min, X max, Y min, or Y max, depending on which region endpoint #1 occupies (via IC1). bit 1 = 1 toward Y max bit 2 = 1 toward Y min bit 3 = 1 toward X max bit 4 = 1 toward X min If endpoint #1 towards Y max, then { Y max = Y = X 1 + t(Y 2 - Y 1 ), find t and calculate X = X 1 + t(X 2 - X 1 ) } 6. Go To Step #1 above.

14
CGPage: 14 Example: Let Xmin = 2, Xmax = 8, Ymin = 2 and Ymax = 8, check the visibility of the following segments using the Cohen-Sutherland Algorithm and, if necessary, clip them against the appropriate window boundaries. Line AB: A(3,10) B(6,12) Line CD: C(4,1) D(10,6) Example: Let Xmin = 2, Xmax = 8, Ymin = 2 and Ymax = 8, check the visibility of the following segments using the Cohen-Sutherland Algorithm. Line AB: A(3,10) B(6,12) Line CD: C(4,1) D(10,6) X min =2X max =8 Y min =2 Y max =8 A(3,10) B(6,12) C(4,1) D(10,6)

15
CGPage: 15 How will the algorithm handle these examples? (A)(B) (C)(D)

Similar presentations

© 2021 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google