Professional Documents
Culture Documents
Chapter 4
2D Viewing Algorithms
Coordinate Systems
y
(x, y)
v
(u,v)
[4]-2
(0,300)
0
-180 -150 -120 0 120 150 180 -90 -60 -30 30 60 90
-0.5 -1 -1.5
theta
(0,0)
(360,0)
RM
[4]-3
(umax, vmax)
(x, y)
u = c1 x + c 2
v = d1 y + d2
RM
0.1
-0.05
+0.05
100 250
550
Aspect Ratio
Aspect Ratio = Width/Height.
Aspect ratio of a world window = (xmax-xmin) / (ymax-ymin). Aspect ratio of the viewport = (umax-umin) / (vmax-vmin). The transformation from the window to viewport is said to preserve the aspect ratio, if both the above quantities are same. In such a case, we have c1 = d1. When this condition is satisfied, the mapping from the window to the viewport is distortion-free.
RM
[4]-8
0.1
RM
[4]-9
Specifying a World Window: gluOrtho2D(xmin, xmax, ymin, ymax); Specifying a Viewport: glViewport(umin, vmin, wid, hgt); where, wid=umax-umin hgt=vmax-vmin
RM
[4]-10
Line Clipping
A line is required to be clipped against a rectangular clipping window such that the portion of the line that falls outside the window is not displayed. There are many possible arrangements of a segment with respect to the window. We therefore need an organized approach to identify the correct situation and to compute the new end points of each clipped segment. Efficiency is important because a typical picture contains thousands of line segments, each of which must be clipped against a window.
RM [4]-11
Line Clipping
Window
RM
Clipping Window
[4]-12
Cohen-Sutherland Algorithm
A rapid divide-and-conquer approach to the line clipping
Clipping window
Trivial Accept: When both end points are inside the window, and therefore the line is completely visible. Trivial Reject: When both end points are outside the window and on the same side of the window. Then the line is completely outside, and hence can be rejected.
RM
[4]-13
Region Codes
A point is assigned a unique region code depending on the location of the point with respect to the window.
1001
1000
1010
0001
0000
Clipping window
0010
0101
RM
0100
0110
[4]-14
Region Codes
Trivial Accept
0000 0000
(OR: Bitwise)
[4]-15
Region Codes
Trivial Reject
1010
0010
(AND: Bitwise)
[4]-16
Region Codes
Other Cases
1001 1010
0000
0100
RM
[4]-17
Region Codes
Other Cases
i. The point that lies outside the window is considered. (This is the point whose region code is non-zero). ii. For the above point, an edge outside which the point lies is identified. (If a particular bit is non-zero, the corresponding edge of the window is considered). iii. The intersection of the line with the edge is computed. The initial point in (i) is now replaced by the new intersection point. Its region code is computed. iv. The conditions for the trivial accept or trivial reject or other case is again checked for the new line segment.
RM [4]-18
Region Codes
1010
0000
Trivial Accept
0000
RM
[4]-19
A x=xmin
y y1 x x1 y 2 y1 x2 x1
The intersection point A lies on the left edge and therefore its x-coordinate is x = xmin.
y1 ( x min x1 )
( y 2 y1 ) ( x 2 x1 )
[4]-20
A x=xmin
Now P is replaced by the point A (effectively discarding the segment PA), and the whole process of checking is repeated for the segment AQ. Now both A, Q will have region codes 0000, and hence will satisfy the condition trivial accept.
RM [4]-21
RM
[4]-22