10 an cg polygonclipping
TRANSCRIPT
-
7/29/2019 10 an CG PolygonClipping
1/26
Computer GraphicsPolygon Clipping
By
Asmita Nag
-
7/29/2019 10 an CG PolygonClipping
2/26
What is Polygon Clipping Its the process of finding the exact part of a polygon
lying inside the view volume
To maintain consistency, clipping of a polygon shouldresult in a polygon, not a sequence of partially
unconnected lines
-
7/29/2019 10 an CG PolygonClipping
3/26
Before Clipping After ClippingBefore Clipping After Clipping
It is not merely Line Clipping...
-
7/29/2019 10 an CG PolygonClipping
4/26
Modify line clipping procedures.
After applying line clipper the polygon is displayed
as a series of unconnected line segments.
Before Clipping After Clipping
It is not merely Line Clipping...
-
7/29/2019 10 an CG PolygonClipping
5/26
For polygon clipping generate algorithm for approp
riate area fill
Before Clipping After Clipping
It is not merely Line Clipping...
-
7/29/2019 10 an CG PolygonClipping
6/26
Example
Examples...
-
7/29/2019 10 an CG PolygonClipping
7/26
Example
Examples...
-
7/29/2019 10 an CG PolygonClipping
8/26
Example
Examples...
-
7/29/2019 10 an CG PolygonClipping
9/26
Clip the polygon by processing the polygon boundary as a whole against each window.
Process all polygon vertices against each clip recta
ngle boundary in turn.First clip the polygon against the left boundary to pr
oduce a new sequence of vertices.
The new sequence of vertices is then successive passed to right, bottom and top boundary clipper.
At each step a new sequence of output vertices is generated and passed to the next boundary clipper
Sutherland Hodgeman Method
-
7/29/2019 10 an CG PolygonClipping
10/26
Original
Polygon
Clip
Bottom
Clip
Top
Clip
Left
Clip
Right
Polygon Clipping
-
7/29/2019 10 an CG PolygonClipping
11/26
Initial Condition
Sutherland-Hodgeman Algo.
Clip Against Right Clipping Boundarylip Against Top Clipping Boundaryhe Clipped Polygonlip Against Bottom Clipping Boundarylip Against Left Clipping Boundary
-
7/29/2019 10 an CG PolygonClipping
12/26
Case 1
Inside Outside
Polygon
being
clipped
Clip
boundary
s
p:output
4 Cases of Polygon Clipping
Case 2
Inside Outside
s
p
i:output
Case 3
Inside Outside
s
p
(no output)
Case 4
Inside Outside
s
i:first output
p:second output
-
7/29/2019 10 an CG PolygonClipping
13/26
Algorithm
Input vertex P
Firs t Point YesNo
F=P
Does SP intersect
E?No
Yes
Compute
Intersection PointI
Output
vertex I
S=P
Is S on left
side of E?
Exit
NO
Yes
Output
vertex S
Close Polygon entry
Does SF
intersect E?
Compute
Intersect ion I
Yes
Output
vertex I
Exit
No
-
7/29/2019 10 an CG PolygonClipping
14/26
Sutherland-HodgmanPolygon Clipping
Input each edge (vertex pair) successively.
Output is a new list of vertices.
Each edge goes through 4 clippers.
The rule for each edge for each clipper is:
If first input vertex is outside, and second is inside,output the intersection and the second vertex
If both input vertices are inside, then just outputsecond vertex
If first input vertex is inside, and second is outside,output is the intersection
If both vertices are outside, output is nothing
-
7/29/2019 10 an CG PolygonClipping
15/26
Sutherland-Hodgman Polygon Clipping
v2
v1
v3
Right
Clipper
Bottom
Clipper
Top
Clipper
Left
Clipper
v1v2
v2v3
v3v1
v1
v2
v2
v2
v3v1
v2v2
v2v3
v3v1
v1v2
v2
v3
v1
v2 v2v2
v2v3
v3v1
v1v2
v3
Figure 6-27, page 332
v2
v1v2
v2 v2v2
v2v1
v1v2
v2v2
v1
v2
v2
v2
Edges Output Edges Output Edges Output Edges Output
Final
-
7/29/2019 10 an CG PolygonClipping
16/26
Problems with Sutherland-Hodgman
What if you clip these?
-
7/29/2019 10 an CG PolygonClipping
17/26
Weiler-Atherton Algorithm
When we have non-convex polygons then the
algorithm above might produce polygons with
coincident edges
This is sometimes OK for rendering but is not
for other applications (e.g. shadows)
The Weiler-Atherton algorithm produces
separate polygons for each visible fragment
-
7/29/2019 10 an CG PolygonClipping
18/26
Weiler-Atherton Algorithm
1
2
3
5
4
6
8
7
9
0
a
b
c
d
a b
cd
0
1
2
34
56
78
9
A
B
i j
k
l
clip region
polygon
loop of polygon
vertices
loop of region
vertices
-
7/29/2019 10 an CG PolygonClipping
19/26
Find the intersection vertices and connect them
in the two lists
1
2
3
5
4
6
8
7
9
0
a
b
c
d
a b
cd
0
1
2
34
56
78
9
A
B
i j
k
l
clip region
polygon
i
l
k
j
Add vertex i:
-
7/29/2019 10 an CG PolygonClipping
20/26
1
2
3
5
4
6
8
7
9
0
a
b
c
d
a b
cd
0
1
2
34
56
78
9
A
B
i j
k
l
clip region
polygon
i
l
k
j
Add vertex l:
Find the intersection vertices and connect
them in the two lists
-
7/29/2019 10 an CG PolygonClipping
21/26
1
2
3
5
4
6
8
7
9
0
a
b
c
d
a b
cd
0
1
2
34
56
78
9
A
B
i j
k
l
clip region
polygon
i
l
k
j
Add vertex k:
Find the intersection vertices and connect
them in the two lists
-
7/29/2019 10 an CG PolygonClipping
22/26
1
2
3
5
4
6
8
7
9
0
a
b
c
d
a b
cd
0
1
2
34
56
78
9
A
B
i j
k
l
clip region
polygon
i
l
k
j
Completed Loop
Add vertex j:
-
7/29/2019 10 an CG PolygonClipping
23/26
1
2
3
5
4
6
8
7
9
0
a
b
c
d
a b
cd
0
1
2
34
56
78
9
A
B
i j
k
l
clip region
polygon
i
l
k
j
Entering
Leaving
Classify each intersection vertex as Entering
orLeaving
-
7/29/2019 10 an CG PolygonClipping
24/26
1
2
3
5
4
6
8
7
9
0
a
b
c
d
i
l
k
j
EnteringLeaving
Capture clipped polygons
Start at an entering vertex
If you encounter a leaving
vertex swap to right hand (
clip polygon) loop If you encounter an enterin
g vertex swap to left hand (
polygon) loop
A loop is finished when you arrive back at start
Repeat whilst there are ent
ering vertices
-
7/29/2019 10 an CG PolygonClipping
25/26
1
2
3
5
4
6
8
7
9
0
a
b
c
d
i
l
k
j
EnteringLeaving
Capture clipped polygons
Loop 1:
L, 4, 5, K
Loop 2:
J, 9, 0, I
-
7/29/2019 10 an CG PolygonClipping
26/26