Lecture 11
Lecture 11
is in category 1(Visible)
is in category 2(Not Visible)
is in category 3(Clipping candidate)
Continue…
interior = ∩
ymin
ymin
0101 0100 0110
xmin xmax
Continue…
• If both endpoint codes are 0000, the line segment is visible (inside).
• The logical AND of the two endpoint codes -
• not completely 0000 , the line segment is not visible (outside).
• completely 0000, the line segment maybe inside (and outside).
0001 A B’
D’
A ’
C’ 0010
ymin
0100 C
xmin xmax
Continue…
• Replace endpoint (x1,y1) with the intersection point(xi,yi), effectively
eliminating the portion of the original line that is on the outside of the
selected window boundary.
• The new endpoint is then assigned an updated region code and the clipped
line re-categoriged and handled in the same way.
• This iterative process terminates when we finally reach a clipped line that
belongs to either category 1(visible) or category 2(not visible).
Continue…
• Use simple tests to classify easy cases first:
P7
P1
P4 P8
P3
P2
P6
P10
P5 P9
14
Continue…
• Classify some lines quickly by AND of bit-codes representing regions of two
endpoints (must be 0).
1001 P7 0001 0101
Bit 4
P1
P4 P8
1000 P3 0000 0100
P2
P6
P10
Bit 3
1010 P5 0010 P9 0110
Bit 1 Bit 2
15
Continue…
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P5 0010 P9 0110
Bit 1 Bit 2
17
Continue…
• Compute intersections with window boundary for lines that can’t be classified
quickly:
1001 P7 0001 0101
Bit 4
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P5 0010 P9 0110
Bit 1 Bit 2
18
Continue…
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P5 0010 P9 0110
Bit 1 Bit 2
19
Continue…
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
20
Continue…
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
21
Continue…
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
cgvr.korea.ac.kr 22
Continue…
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
23
Continue…
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
24
Continue…
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
25
Continue…
P4 P’8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P’5 0010 P 0110
9
Bit 1 Bit 2
26
Continue…
P4 P’8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P’5 0010 P 0110
9
Bit 1 Bit 2
27
Continue…
P4 P’8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P’5 0010 P 0110
9
Bit 1 Bit 2
28
Continue…
P4 P’8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
29
Continue…
P4 P’8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P’5 0010 P’90110
Bit 1 Bit 2
30
Continue…
P4 P’8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P’5 0010 P’90110
Bit 1 Bit 2
31
Continue…
P4 P’8
1000 P3 0000 0100
P6
Bit 3
1010 P’5 0010 0110
Bit 1 Bit 2
32
Midpoint Subdivision
• An alternative way to process a line in category 3 is based on binary search.
• The line is divided at its midpoint into two shorter line segments.
• The clipping categories of the two new line segments are determined by their region
codes.
• Each segment in category 3 is divided again into shorter segments and categorized.
• This bisection & categorization process continues until each line segment that spans
across a window boundary reaches a threshold for line size and all other segments are
either in category 1 or in category 2.
33
Midpoint Subdivision Algorithm
• Step-1: Calculate the position of both endpoints of the line.
• Step-2: Perform OR operation on both of these endpoints.
• Step-3: If the OR operation gives 0000:
then-
Line is guaranteed to be visible;
else-
Perform AND operation on both endpoints.
If AND ≠ 0000-
the line is invisible;
else
the line is clipped case;
• Step-4: For the line to be clipped. Find midpoint.
Xm=(x1+x2)/2
Ym=(y1+y2)/2
• Step-5: Check each midpoint, whether it nearest to the boundary of a window or not.
• Step-6: If the line is totally visible or totally rejected not found:
Repeat step 1 to 5.
• Step-7: Stop algorithm.
34
Example - 01
35
Continue…
36
Thank you