Clipping
1. Line Clipping (Cyrus &
Beck Algorithm)
2. Polygon Clipping
2022/2023 - 2
Cyrus & Beck Clipping Algorithm
• Treat line in parametric form.
• Note line will cross all clip boundaries
somewhere :
1
Cyrus & Beck Clipping Algorithm
• Treat line in parametric form.
• Note line will cross all clip boundaries somewhere :
 Find all intersections, test afterwards to determine if
they are on the clip rectangle.
 Define a point on the clipping plane and its normal.
 Notice the dot product between a vector from this point
and the intersection is zero.
2
Flowchart
Cyrus &
Beck
Clipping
Algorithm
3
Cyrus & Beck Clipping Algorithm
4
Cyrus & Beck Clipping Algorithm
5
Vector Directions
6
Edge Ej
Nj
P0
P1
PEJ
0
]
)
(
[ >
−
• EJ
j P
t
P
N
0
]
)
(
[ =
−
• EJ
j P
t
P
N
0
]
)
(
[ <
−
• EJ
j P
t
P
N
t
P
P
P
t
P )
(
)
( 0
1
0 −
+
=
Cyrus & Beck Clipping Algorithm
7
Cyrus & Beck Clipping Algorithm
8
D
N
P
P
N
t
P
P
D
t
P
P
N
P
P
N
P
t
P
P
P
N
P
t
P
N
t
P
P
P
t
P
j
EJ
j
j
EJ
j
EJ
j
EJ
j
•
−
−
•
=
−
=
=
−
•
+
−
•
=
−
−
+
•
=
−
•
−
+
=
]
[
for t
solve
),
(
Let
0
]
[
]
[
0
]
)
(
[
0
]
)
(
[
)
(
)
(
0
0
1
0
1
0
0
1
0
0
1
0
Note
Sign of denominator is
important.
Must ≠ 0 ( ignore parallel lines ).
Parametric form implies
direction.
Denominator < 0 → point
entering clip region.
Denominator > 0 → point leaving
clip region.
Denominator < 0 → point entering clip region, classify as
PE
Denominator > 0 → point leaving clip region, classify as PL
Edge Ej
Nj
D
N
P
P
N
t
j
EJ
j
•
−
−
•
=
]
[ 0
θ
D
Cyrus & Beck Clipping Algorithm
9
Cyrus & Beck Clipping Algorithm
10
Sort PE’s and PL’s according to t.
PE
PL
PL
PE
t
t
Draw from a PE → PL pair.
PL < PE → no intersection
Cyrus & Beck Clipping Algorithm
11
Note: PEi = f (boundary point)
Lat = Latura (at edge)
Cyrus & Beck Clipping Algorithm
12
Example Cyrus & Beck Clipping
13
nL = i = [+1 0]
nR= -i= [-1 0]
nT = - ĵ = [0 -1]
nB= +ĵ=[0 +1]
Example Cyrus & Beck Clipping
14
w1 = [-1 1] – [0 0] = [-1 1]
D = [ 9 3] – [-1 1] = [10 2]
w1 ⋅ nL = [1 1]⋅[+1 0] = -1
D ⋅ nL = [10 2]⋅[+1 0] = 10
t = (w1 ⋅ nL / D⋅ nL) = -(-1/10) = 1/10
Example Cyrus & Beck Clipping
15
Cases
16
Cases
17
Cases
18
Directrix or
direction of line
Distance to
boundary point from
the end points
Weighting factor
(1)
(2)
(1) (2)
(3)
equation (3) & its
notes, used to
determine whether the
line(s) intersects or not
with the window.
Polygon Clipping
• Clip polygons by clipping successively against 4 sides.
19
Polygon Clipping
• Clip polygons by clipping successively against all 4 sides
• Can implement as pipelined algorithm (ie special hardware can do
the work)
• Recursively test each edge.
 Form new edge with next vertex
 Call with new edge
20
Area Clipping
• Similar with lines,
areas must be clipped
to a window boundary
• Consideration must be
taken as to which
portions of the area
must be clipped
21
Area Clipping
22
Area Clipping
23
Sutherland-Hodgeman Polygon
Clipping
24
Sutherland-Hodgeman Polygon
Clipping
• Loop round vertices, test each against all 4 clipping
planes in sequence
• Call algorithm again with new edge formed by next
vertex -re-entrant
• No storage requirement between stages
 Easy to implement in hardware
25
Sutherland-Hodgeman Polygon
Clipping
26
Output
Vertex
First
Output
Four cases of polygon clipping:
Inside Outside Inside Outside Inside Outside Inside Outside
Case 3
No
output.
Case 1 Case 2.
Output
Intersection
Case 4
Second
Output
Sutherland-Hodgeman Polygon
Clipping
27
Sutherland-Hodgeman Polygon
Clipping
28
Sutherland-Hodgeman Polygon
Clipping
29
Sutherland-Hodgeman Polygon
Clipping
• Example
30
Start at the left boundary
1,2 (out,out) → clip
2,3 (in,out) → save 1’, 3
3,4 (in,in) → save 4
4,5 (in,in) → save 5
5,6 (in,out) → save 5’
Saved points → 1’,3,4,5,5’
6,1 (out,out) → clip
Using these points we repeat the
process for the next boundary.
Weiler-Atherton Polygon Clipping
• Convex polygons are correctly clipped by the Sutherland-
Hodgeman algorithm, but concave polygons may be
displayed with extra areas (area inside the red circle), as
demonstrated in the following figure.
31
Weiler-Atherton Polygon Clipping
• This occurs when the clipped polygon should have two or more
separate sections. But since there is only one output vertex list, the
last vertex in the list is always joined to the first vertex.
• There are several things we could do to correctly display concave
polygons.
• For one, we could split the concave polygon into two or more convex
polygons and process each convex polygon separately
• Another possibility is to modify the Sutherland-Hodgeman approach
to check the final vertex list for multiple vertex points along any Clip
window boundary and correctly join pairs of vertices.
• Finally, we could use a more general polygon clipper, such as either
the Weiler-Atherton algorithm or the Weiler algorithm.
32
Weiler-Atherton Polygon Clipping
•In Weiler-Atherton Polygon Clipping, the vertex-
processing procedures for window boundaries are
modified so that concave polygons are displayed correctly.
•This clipping procedure was developed as a method for
identifying visible surfaces, and so it can be applied with
arbitrary polygon-clipping regions.
33
Weiler-Atherton Polygon Clipping
• The basic idea in this algorithm is that instead of always
proceeding around the polygon edges as vertices are
processed, we sometimes want to follow the window
boundaries.
• Which path we follow depends on the polygon-processing
direction (clockwise or counterclockwise) and whether the
pair of polygon vertices currently being processed
represents an outside-to-inside pair or an inside-to-
outside pair.
34
Weiler-Atherton Polygon Clipping
For clockwise processing of polygon vertices, we use the
following rules:
1. For an outside-to-inside pair of vertices, follow the
polygon boundary
2. For an inside-to-outside pair of vertices, follow the
window boundary in a clockwise direction.
35
Weiler-Atherton Polygon Clipping
• Example
In the following figure, the processing direction in the
Weiler-Atherton algorithm and the resulting clipped
polygon is shown for a rectangular clipping window.
36
Text Clipping
37
Text Clipping
38
Curve Clipping
39
Viewing & Clipping - Summary
• Window and View Port
• Clipping cuts out what we do not “see”
• Also reduces unnecessary computation
• Can be done at various levels
40

Materi_05_CG_2223_2_.pdf

  • 1.
    Clipping 1. Line Clipping(Cyrus & Beck Algorithm) 2. Polygon Clipping 2022/2023 - 2
  • 2.
    Cyrus & BeckClipping Algorithm • Treat line in parametric form. • Note line will cross all clip boundaries somewhere : 1
  • 3.
    Cyrus & BeckClipping Algorithm • Treat line in parametric form. • Note line will cross all clip boundaries somewhere :  Find all intersections, test afterwards to determine if they are on the clip rectangle.  Define a point on the clipping plane and its normal.  Notice the dot product between a vector from this point and the intersection is zero. 2
  • 4.
  • 5.
    Cyrus & BeckClipping Algorithm 4
  • 6.
    Cyrus & BeckClipping Algorithm 5
  • 7.
  • 8.
    Edge Ej Nj P0 P1 PEJ 0 ] ) ( [ > − •EJ j P t P N 0 ] ) ( [ = − • EJ j P t P N 0 ] ) ( [ < − • EJ j P t P N t P P P t P ) ( ) ( 0 1 0 − + = Cyrus & Beck Clipping Algorithm 7
  • 9.
    Cyrus & BeckClipping Algorithm 8 D N P P N t P P D t P P N P P N P t P P P N P t P N t P P P t P j EJ j j EJ j EJ j EJ j • − − • = − = = − • + − • = − − + • = − • − + = ] [ for t solve ), ( Let 0 ] [ ] [ 0 ] ) ( [ 0 ] ) ( [ ) ( ) ( 0 0 1 0 1 0 0 1 0 0 1 0 Note Sign of denominator is important. Must ≠ 0 ( ignore parallel lines ). Parametric form implies direction. Denominator < 0 → point entering clip region. Denominator > 0 → point leaving clip region.
  • 10.
    Denominator < 0→ point entering clip region, classify as PE Denominator > 0 → point leaving clip region, classify as PL Edge Ej Nj D N P P N t j EJ j • − − • = ] [ 0 θ D Cyrus & Beck Clipping Algorithm 9
  • 11.
    Cyrus & BeckClipping Algorithm 10 Sort PE’s and PL’s according to t. PE PL PL PE t t Draw from a PE → PL pair. PL < PE → no intersection
  • 12.
    Cyrus & BeckClipping Algorithm 11 Note: PEi = f (boundary point) Lat = Latura (at edge)
  • 13.
    Cyrus & BeckClipping Algorithm 12
  • 14.
    Example Cyrus &Beck Clipping 13 nL = i = [+1 0] nR= -i= [-1 0] nT = - ĵ = [0 -1] nB= +ĵ=[0 +1]
  • 15.
    Example Cyrus &Beck Clipping 14 w1 = [-1 1] – [0 0] = [-1 1] D = [ 9 3] – [-1 1] = [10 2] w1 ⋅ nL = [1 1]⋅[+1 0] = -1 D ⋅ nL = [10 2]⋅[+1 0] = 10 t = (w1 ⋅ nL / D⋅ nL) = -(-1/10) = 1/10
  • 16.
    Example Cyrus &Beck Clipping 15
  • 17.
  • 18.
  • 19.
    Cases 18 Directrix or direction ofline Distance to boundary point from the end points Weighting factor (1) (2) (1) (2) (3) equation (3) & its notes, used to determine whether the line(s) intersects or not with the window.
  • 20.
    Polygon Clipping • Clippolygons by clipping successively against 4 sides. 19
  • 21.
    Polygon Clipping • Clippolygons by clipping successively against all 4 sides • Can implement as pipelined algorithm (ie special hardware can do the work) • Recursively test each edge.  Form new edge with next vertex  Call with new edge 20
  • 22.
    Area Clipping • Similarwith lines, areas must be clipped to a window boundary • Consideration must be taken as to which portions of the area must be clipped 21
  • 23.
  • 24.
  • 25.
  • 26.
    Sutherland-Hodgeman Polygon Clipping • Loopround vertices, test each against all 4 clipping planes in sequence • Call algorithm again with new edge formed by next vertex -re-entrant • No storage requirement between stages  Easy to implement in hardware 25
  • 27.
  • 28.
    Output Vertex First Output Four cases ofpolygon clipping: Inside Outside Inside Outside Inside Outside Inside Outside Case 3 No output. Case 1 Case 2. Output Intersection Case 4 Second Output Sutherland-Hodgeman Polygon Clipping 27
  • 29.
  • 30.
  • 31.
    Sutherland-Hodgeman Polygon Clipping • Example 30 Startat the left boundary 1,2 (out,out) → clip 2,3 (in,out) → save 1’, 3 3,4 (in,in) → save 4 4,5 (in,in) → save 5 5,6 (in,out) → save 5’ Saved points → 1’,3,4,5,5’ 6,1 (out,out) → clip Using these points we repeat the process for the next boundary.
  • 32.
    Weiler-Atherton Polygon Clipping •Convex polygons are correctly clipped by the Sutherland- Hodgeman algorithm, but concave polygons may be displayed with extra areas (area inside the red circle), as demonstrated in the following figure. 31
  • 33.
    Weiler-Atherton Polygon Clipping •This occurs when the clipped polygon should have two or more separate sections. But since there is only one output vertex list, the last vertex in the list is always joined to the first vertex. • There are several things we could do to correctly display concave polygons. • For one, we could split the concave polygon into two or more convex polygons and process each convex polygon separately • Another possibility is to modify the Sutherland-Hodgeman approach to check the final vertex list for multiple vertex points along any Clip window boundary and correctly join pairs of vertices. • Finally, we could use a more general polygon clipper, such as either the Weiler-Atherton algorithm or the Weiler algorithm. 32
  • 34.
    Weiler-Atherton Polygon Clipping •InWeiler-Atherton Polygon Clipping, the vertex- processing procedures for window boundaries are modified so that concave polygons are displayed correctly. •This clipping procedure was developed as a method for identifying visible surfaces, and so it can be applied with arbitrary polygon-clipping regions. 33
  • 35.
    Weiler-Atherton Polygon Clipping •The basic idea in this algorithm is that instead of always proceeding around the polygon edges as vertices are processed, we sometimes want to follow the window boundaries. • Which path we follow depends on the polygon-processing direction (clockwise or counterclockwise) and whether the pair of polygon vertices currently being processed represents an outside-to-inside pair or an inside-to- outside pair. 34
  • 36.
    Weiler-Atherton Polygon Clipping Forclockwise processing of polygon vertices, we use the following rules: 1. For an outside-to-inside pair of vertices, follow the polygon boundary 2. For an inside-to-outside pair of vertices, follow the window boundary in a clockwise direction. 35
  • 37.
    Weiler-Atherton Polygon Clipping •Example In the following figure, the processing direction in the Weiler-Atherton algorithm and the resulting clipped polygon is shown for a rectangular clipping window. 36
  • 38.
  • 39.
  • 40.
  • 41.
    Viewing & Clipping- Summary • Window and View Port • Clipping cuts out what we do not “see” • Also reduces unnecessary computation • Can be done at various levels 40