Professional Documents
Culture Documents
311321
1
CHAPTER SIX
Two-Dimensional
Clipping
2
Clipping
•For the image below consider which points should
be kept and which ones should be clipped
P4
Window P2
wymax P6
P3
P1
P7 P5
P9
P8
wymin
P10
wxmin wxmax
Point Clipping
•Easy - a point (x,y) is not clipped if:
• wxmin ≤ x ≤ wxmax AND wymin ≤ y ≤ wymax
•otherwise it is clipped
P4 Clipped
Clipped
Window P2
wymax
Clipped
P5
P1
P7 Points Within the Window
are Not Clipped
P9 P8
wymin
Clipped P10
wxmin wxmax
Two-Dimensional Point Clipping
xw min x xw max
yw min y yw max (6 - 12)
5
Point Clipping
• Exercise: P1 = (10, 20), P2 = (30, 50), P3 = (60, 90), and
P4 = (130, 150). Suppose that the coordinates of the two
opposite corners of the clip window are
(xwmin, ywmin) = (30, 30) and (xwmax, ywmax) = (130, 110).
Which of the above points will be clipped?
6
Two-Dimensional Line Clipping
Figure 6-11 illustrates possible positions for straight-line segments
in relationship to a standard clipping window.
A line-clipping algorithm processes each line in a scene through a
series of tests and intersection calculations to determine whether
the entire line or any part of it is to be saved for display.
7
Line Clipping
8
Sutherland: Line Clipping
- One of the oldest and most popular line-clipping
procedures.
- The method speeds up the processing of line
segments by performing initial tests that reduce the
number of intersections that must be calculated.
- Efficient method of accepting or rejecting lines that
don’t intersect the window edges.
9
Sutherland: Line Clipping
Lines that cross a boundary of the window, are clipped
by computing the coordinates of the new boundary
endpoint of the line where it crosses the edge of the window.
10
Sutherland: World Division
11
Sutherland: World Division
•World space is divided into regions based
on the window boundaries
– Each region has a unique four bit region code
– Region codes indicate the position of the
regions with respect to the window
Window
wymax P6 [0000]
P3 [0001]
P5 [0000] P12 [0010]
P7 [0001]
P9 [0000] P8 [0010]
wymin
P10 [0100]
P13 [0101] P14 [0110]
wxmin wxmax
Sutherland: Lines In The Window
Lines completely contained within the window
boundaries have region code [0000] for both
end-points so are not clipped
P11 [1010]
P4 [1000]
Window
wymax P6 [0000]
P3 [0001]
P5 [0000] P12 [0010]
P7 [0001]
P9 [0000] P8 [0010]
wymin
P10 [0100]
P13 [0101] P14 [0110]
wxmin wxmax
Sutherland: Lines Outside The Window
Any lines with a common set bit in the region
codes of both end-points can be clipped
– The AND operation can efficiently check this
P11 [1010]
P4 [1000]
Window
wymax P6 [0000]
P3 [0001]
P5 [0000] P12 [0010]
P7 [0001]
P9 [0000] P8 [0010]
wymin
P10 [0100]
P13 [0101] P14 [0110]
wxmin wxmax
Sutherland: Other Lines
•Lines that cannot be identified as
completely inside or outside the window may
or may not cross the window interior
•These lines are processed as follows:
– Compare an end-point outside the window to a
boundary (choose any order in which to
consider boundaries e.g. left, right, bottom, top)
and determine how much can be discarded
– If the remainder of the line is entirely inside or
outside the window, retain it or clip it
respectively
Sutherland: Other Lines (cont…)
boundary P [0100] 10
22
Sutherland Example
23
Sutherland Example
• Bit 1: x – xwmin= 72–68 = 4 0 Bit 1: x – xwmin= 90-68=22 0
• Bit 2: xwmax - x = 92-72 = 0 0 Bit 2: xwmax - x = 92-90=2 0
• Bit 3: y – ywmin= 65–59 = 6 0 Bit 3: y – ywmin= 68 –59=6 0
• Bit 4: ywmax - y = 71-65 = 6 0 Bit 4: ywmax - y = 71-68= 3 0
• the region code of (72,65) is 0000
• the region code of (90,68) is 0000
• The line (72-65)- (90,68) is completely inside
24
Sutherland Example
25
Sutherland Example
26
Calculating Line Intersections
•Intersection points with the window
boundaries are calculated using the line-
equation parameters
– Consider a line with the end-points (x1, y1) and
(x2, y2)
– The y-coordinate of an intersection with a
vertical window boundary can be calculated
using:
y = y1 + m (xboundary - x1)
where xboundary can be set to either wxmin or
wxmax
Calculating Line Intersections (cont…)
29
Figure 6-14 illustrates a line from P1 to P2.
The region codes for P1 is 0100 and for P2 is 1001.
Left Boundary: P1 is inside the left boundary and P2
outside the left boundary. Thus, the line crosses the left
boundary. We calculate the intersection position P´2 and
we clip off the line section P´2 to P2.
30
Bottom Boundary: P1 is outside the boundary and P2
inside the boundary. We find the intersection at P´1 and we
eliminate the line P1 to P´1 and proceed to the next edge.
Top Boundary: P´1 is below the boundary and P´2 is above
the boundary. Thus we find the intersection P´´2 and
eliminate the section P´2P´´2.
31
POLYGON FILL-AREA CLIPPING
32
A line clipper would produce a disjoint set of line with no
information about how to form the closed boundaries.
33
To clip the polygon, we need to keep the fill area as an
entity as it is processed through the clipping stages as
shown in the following Figure:
34
Polygon Clipping
• Find the vertices of the
new polygon(s) inside the
window.
• Sutherland-Hodgman
Polygon Clipping:
Check each edge of the polygon
against all window boundaries.
Modify the vertices based on
transitions. Transfer the new edges
to the next clipping boundary.
One way to clip a convex polygon is to create a new vertex
list at each clipping boundary, and then pass this new
vertex list to the next boundary clipper.
{1, 2, 3} { 1 , 2 , 2 , 3 , 3 , 1 }
'' '' ''
General Strategy:
Then the first clipper continues with the next pair of endpoints.
37
There are four possible cases that need to be considered when
processing a polygon edge against one of the clipping boundaries.
38
Shutherland-Hodgman Polygon Clipping
V1
• Traverse edges for borders; 4 cases:
V1'
– V1 outside, V2 inside: take V1' and V2
V2
V2
– V1 inside, V2 outside: take V1 and V2'
V1
V2
– V1 outside, V2 outside: take none V2'
V1
V2
Shutherland-Hodgman Polygon Clipping
• Left border:
v1 v1 v2 both inside v1 v2
v2 v2 v3 both inside v2 v3
..... “ “ ........
v1,v2,v3,v4v5,v6,v1
v6 • Bottom Border:
v1 v2 both inside v1 v2
v2 v3 v2 i, v3 o v2 v3'
v5' v3 v4 both outside none
v3' v4 v5 both outside none
v5 v6 v5 o, v6 i v5' v6
v5 v3 v6 v1 both inside v6 v1
v4 v1,v2,v3',v5',v6,v1
Shutherland-Hodgman Polygon Clipping
• v1,v2,v3',v5',v6,v1
• Right border:
v1 v2 v1 i, v2 o v1 v2'
v2 v3‘ v2 o, v3'i v2'' v3'
v1
v2' v3' v5‘ both inside v3' v5'
v2
v1' v5' v6 both inside v5' v6
v2''' v6 v1 both inside v6 v1
v1,v2',v2'',v3',v5',v6,v1
v6
• Top Border:
v2'' v1 v2' both outside none
v2' v2'' v2' o, v2'' i v2''' v2''
v5' v2'' v3' both inside v2'' v3'
v3' v3' v5' both inside v3' v5'
v5' v6 both inside v5' v6
v5 v3 v6 v1 v6 i, v1 o v6 v1'
v2''',v2'',v3',v5',v6,v1'
v4
Shutherland-Hodgman
Polygon Clipping
v1
v2'
v2
v1' v1' v2'''
v2'''
v6 v6
v2'' v2''
v5' v5'
v3' v3'
v5 v3
v4
43
44