1/3/2023
1
EI-OE-401 Open Elective IV
(Computer Graphics and CAD/CAM)
Module - 2
Polygon Clipping
Prof. Pardeep Kumar
Department of Instrumentation,
Kurukshetra University, Kurukshetra-136119
pardeepk@kuk.ac.in
• Points and lines, Line drawing algorithms, midpoint circle and ellipse
algorithms. Filled area primitives: scan line polygon fill algorithm, boundary-
fill and flood fill algorithms.
• Translation, scaling, rotation, reflection and shear transformations, matrix
representations and homogeneous coordinates, composite transforms,
transformation between coordinate systems. 2-D Viewing: The viewing
pipeline, viewing coordinate reference frame, window to viewport coordinate
transformation, viewing functions, Cohen-Sutherland and Cyrus beck line
clipping algorithms
• Reference Books:
Computer Graphics by Hearn & Donald, PHI
Computer Graphic by Plastock, McGraw Hill
Principle of Interactive graphics by Newman.W Spraul R.F., McGraw Hill
Procedural Elements of computer graphics by Rogers D.F., McGraw Hill
Module – II Syllabus
2
January 3, 2023 DOI, Kurukshetra University
There will be
continuous
evaluation in the
form of
Assignments,
quizzes etc.
After
completion
there will be a
class test
1/3/2023
2
• Polygon clipping
– Sutherland-Hodgman,
– Weiler-Atherton
• Polygon filling
– Scan filling polygons
– Flood filling polygons
• Introduction and discussion of Assignment work #2
Outline
3
January 3, 2023 DOI, Kurukshetra University
Polygons
Clipping
January 3, 2023 DOI, Kurukshetra University 4
1/3/2023
3
• Ordered set of vertices (points)
– Usually counter-clockwise
• Two consecutive vertices define an
edge
• Left side of edge is inside
• Right side is outside
• Last vertex implicitly connected to first
• In 3D vertices are co-planar
Polygon
5
January 3, 2023 DOI, Kurukshetra University
• Convex
–All interior angles are less than 180 degrees
• Concave
–Interior angles can be greater than 180 degrees
• Degenerate polygons
–If all vertices are collinear
Polygon Classification
6
January 3, 2023 DOI, Kurukshetra University
1/3/2023
4
Clipping polygons is more complex than clipping the
individual lines
– Input: polygon
– Output: original polygon, new polygon, or nothing
When can we trivially accept/reject a polygon as opposed
to the line segments that make up the polygon?
Clipping Polygons
7
January 3, 2023 DOI, Kurukshetra University
• Clipping a polygon fill area needs more than line-clipping of the
polygon edges
– would produce an unconnected set of lines
• Must generate one or more closed polylines, which can be filled
with the assigned colour or pattern
Clipping Polygons
8
January 3, 2023 DOI, Kurukshetra University
1/3/2023
5
What happens to a triangle during clipping?
Possible outcomes:
How many sides can a clipped triangle have?
Clipping Polygons
9
January 3, 2023 DOI, Kurukshetra University
triangle triangle triangle quad triangle 5-gon
How many sides?
10
January 3, 2023 DOI, Kurukshetra University
Seven… Five…
1/3/2023
6
Polygon clipping
11
January 3, 2023 DOI, Kurukshetra University
• Clipping is symmetric
Polygon clipping is complex
12
January 3, 2023 DOI, Kurukshetra University
• Even when the
polygons are convex
• A really tough case:
concave polygon multiple polygons
1/3/2023
7
Polygon clipping is nasty
13
January 3, 2023 DOI, Kurukshetra University
• When the polygons are concave
• Basic Algorithm
– N*m intersections
– Then must link all segment
– Not efficient and not even easy
• Lots of different cases
• Issues
– Edges of polygon need
to be tested against
clipping rectangle
– May need to add new
edges
– Edges discarded or divided
– Multiple polygons can result
from a single polygon
Polygon Clipping
14
January 3, 2023 DOI, Kurukshetra University
1/3/2023
8
Sutherland-Hodgeman
Clipping
January 3, 2023 DOI, Kurukshetra University 15
• Find the vertices of the new
polygon(s) inside the window.
• Sutherland-Hodgeman 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
Polygon Clipping
16
January 3, 2023 DOI, Kurukshetra University
1/3/2023
9
Sutherland-Hodgeman Clipping
17
January 3, 2023 DOI, Kurukshetra University
Basic idea:
– Consider each edge of the viewport individually
– Clip the polygon against the viewport edge’s equation
– After doing all edges, the polygon is fully clipped
Input/output for algorithm:
– Input: list of polygon vertices in order
– Output: list of clipped poygon vertices consisting of old vertices (maybe)
and new vertices (maybe)
Note: this is exactly what we expect from the clipping operation
against each edge.
Sutherland-Hodgeman Clipping
18
January 3, 2023 DOI, Kurukshetra University
Divide and Conquer
• Idea:
‒ Clip single polygon using
single infinite clip edge
‒ Repeat 4 times
Note the generality:
‒ 2D convex n-gons can clip
arbitrary n-gons
‒ 3D convex polyhedra can clip
arbitrary polyhedra
1/3/2023
10
• Input:
– v1, v2, … vn the vertices defining the polygon
– Single infinite clip edge w/ inside/outside info
• Output:
– v’1, v’2, … v’m, vertices of the clipped polygon
• Do this 4 (or ne) times
• Traverse vertices (edges)
• Add vertices one-at-a-time to output polygon
– Use inside/outside info
– Edge intersections
Sutherland-Hodgman Algorithm
19
January 3, 2023 DOI, Kurukshetra University
Sutherland-Hodgman basic routine:
– Go around polygon one vertex at a time
– Current vertex has position p
– Previous vertex had position s, and it has been added to the output if appropriate
Edge from s to p takes one of four cases:
(Orange line can be a line or a plane)
Sutherland-Hodgeman Clipping
20
January 3, 2023 DOI, Kurukshetra University
inside outside
s
p
p output
inside outside
s
p
no output
inside outside
s
p
i output
inside outside
s
p
i output
p output
1/3/2023
11
• Can be done incrementally
• If first point inside add. If outside, don’t add
• Move around polygon from vi to vn and back to vi
• Check vi,vi+1 w.r.t. the clip edge
• Need vi,vi+1‘s inside/outside status
• Add vertex one at a time. There are 4 cases:
Sutherland-Hodgeman Clipping
21
January 3, 2023 DOI, Kurukshetra University
4 cases
22
January 3, 2023 DOI, Kurukshetra University
1/3/2023
12
Four cases:
1. s inside plane and p inside plane
– Add p to output
– Note: s has already been added
2. s inside plane and p outside plane
– Find intersection point i
– Add i to output
3. s outside plane and p outside plane
– Add nothing
4. s outside plane and p inside plane
– Find intersection point i
– Add i to output, followed by p
Sutherland-Hodgeman Clipping
23
January 3, 2023 DOI, Kurukshetra University
inside outside
s
p
p output
inside outside
s
p
i output
inside outside
s
p
no output
inside outside
s
p
i output
p output
• A very general test to determine if a point p is “inside” a plane P,
defined by q and n:
(p - q) • n < 0: p inside P
(p - q) • n = 0: p on P
(p - q) • n > 0: p outside P
Remember: p • n = |p| |n| cos (q)
q = angle between p and n
Sutherland-Hodgeman Clipping
24
January 3, 2023 DOI, Kurukshetra University
P
n
p
q
P
n
p
q
P
n
p
q
1/3/2023
13
for each polygon P P’ = P
for each clipping edge (there are 4)
{ Clip polygon P’ to clipping edge
for each edge in polygon P’
Check clipping cases (there are 4)
Case 1 : Output vi+1
Case 2 : Output intersection point
Case 3 : No output
Case 4 : Output intersection point & vi+1
}
Sutherland-Hodgman Algorithm
25
January 3, 2023 DOI, Kurukshetra University
Implementation
26
January 3, 2023 DOI, Kurukshetra University
1/3/2023
14
Sutherland-Hodgeman Clipping
27
January 3, 2023 DOI, Kurukshetra University
Sutherland-Hodgeman Clipping
28
January 3, 2023 DOI, Kurukshetra University
1/3/2023
15
• The algorithm correctly clips convex polygons, but may display extraneous
lines for concave polygons
• When we have concave polygon then the above algorithm might produce
polygons with coincident edges (Connected edges)
• This is fine for rendering but maybe not for other applications (e.g shadows)
• The Weiler-Atherton algorithm produces separate polygons for each visible
fragment
Issues with Sutherland-Hodgman Algorithm
29
January 3, 2023 DOI, Kurukshetra University
Weiler-Atherton
Algorithm
January 3, 2023 DOI, Kurukshetra University 30
1/3/2023
16
• Problem in Sutherland-Hodges.
Weiler-Artherton has a solution
• Clipping other shapes: Circle,
Ellipse, curves
• Clipping a shape against other
shapes
• Clipping the exteriors.
Other Issues in clipping
31
January 3, 2023 DOI, Kurukshetra University
• General clipping algorithm for concave polygons with
holes
– Produces multiple polygons (with holes)
– Make linked list data structure
– Traverse to make new polygon(s)
Weiler-Atherton Algorithm
32
January 3, 2023 DOI, Kurukshetra University
1/3/2023
17
• Given polygons A and B as linked list of vertices (counter-
clockwise order)
• Find all edge intersections & place in list
• Insert as “intersection” nodes
• Nodes point to A & B
• Determine in/out status of vertices
Weiler-Atherton Algorithm
33
January 3, 2023 DOI, Kurukshetra University
• If “intersecting” edges are parallel, ignore
• Intersection point is a vertex
– Vertex of A lies on a vertex or edge of B
– Edge of A runs through a vertex of B
• Replace vertex with an intersection node
Intersection Special Cases
34
January 3, 2023 DOI, Kurukshetra University
1/3/2023
18
If polygons don’t intersect
– Union
• If one inside the other, return polygon that surrounds the other
• Else, return both polygons
– Intersection
• If one inside the other, return polygon inside the other
• Else, return no polygons
Boolean Special Cases
35
January 3, 2023 DOI, Kurukshetra University
• Find a vertex of A outside of B
• Traverse linked list
• At each intersection point switch to other polygon
• Do until return to starting vertex
• All visited vertices and nodes define union’ed polygon
Weiler-Atherton Algorithm: Union
36
January 3, 2023 DOI, Kurukshetra University
1/3/2023
19
• Start at intersection point
– If connected to an “inside” vertex, go there
– Else step to an intersection point
– If neither, stop
• Traverse linked list
• At each intersection point switch to other polygon and remove
intersection point from list
• Do until return to starting intersection point
• If intersection list not empty, pick another one
• All visited vertices and nodes define and’ed polygon
Weiler-Atherton Algorithm: Intersection
37
January 3, 2023 DOI, Kurukshetra University
Weiler-Atherton Algorithm
38
January 3, 2023 DOI, Kurukshetra University
1
2
3
5
4
6
8
7
9
0
a
b
c
d
a b
c
d
0
1
2
3
4
5
6
7
8
9
A
B
i j
k
l
clip region
polygon
loop of polygon
vertices
loop of region
vertices
1/3/2023
20
• Find the intersection vertices and connect them in the two lists
Weiler-Atherton Algorithm
39
January 3, 2023 DOI, Kurukshetra University
1
2
3
5
4
6
8
7
9
0
a
b
c
d
a b
c
d
0
1
2
3
4
5
6
7
8
9
A
B
i j
k
l
clip region
polygon
i
l
k
j
Add vertex i:
• Find the intersection vertices and connect them in the two lists
Weiler-Atherton Algorithm
40
January 3, 2023 DOI, Kurukshetra University
a b
c
d
0
1
2
3
4
5
6
7
8
9
A
B
i j
k
l
clip region
polygon
1
2
3
5
4
6
8
7
9
0
a
b
c
d
i
l
k
j
Add vertex l:
1/3/2023
21
• Find the intersection vertices and connect them in the two lists
Weiler-Atherton Algorithm
41
January 3, 2023 DOI, Kurukshetra University
a b
c
d
0
1
2
3
4
5
6
7
8
9
A
B
i j
k
l
clip region
polygon
1
2
3
5
4
6
8
7
9
0
a
b
c
d
i
l
k
j
Add vertex k:
• Computed loop
Weiler-Atherton Algorithm
42
January 3, 2023 DOI, Kurukshetra University
a b
c
d
0
1
2
3
4
5
6
7
8
9
A
B
i j
k
l
clip region
polygon
1
2
3
5
4
6
8
7
9
0
a
b
c
d
i
l
k
j
Add vertex j:
1/3/2023
22
• Classify each intersection vertex as Entering or Leaving
Weiler-Atherton Algorithm
43
January 3, 2023 DOI, Kurukshetra University
a b
c
d
0
1
2
3
4
5
6
7
8
9
A
B
i j
k
l
clip region
polygon
1
2
3
5
4
6
8
7
9
0
a
b
c
d
i
l
k
j
Entering
Leaving
• Start at an entering vertex
• If you encounter a leaving vertex
swap to right hand (clip polygon)
loop
• If you encounter an entering
vertex swap to left hand
(polygon) loop
• A loop is finished when you arrive
back at start
• Repeat whilst there are entering
vertices
Capture clipped polygons
44
January 3, 2023 DOI, Kurukshetra University
1
2
3
5
4
6
8
7
9
0
a
b
c
d
i
l
k
j
Entering
Leaving
Loop 1:
L, 4, 5, K
Loop 2:
J, 9, 0, i
1/3/2023
23
January 3, 2023
DOI, Kurukshetra University 45
Any Question?
Thanks!

Notes_456_PolygonClipping2_10 (1).pdf

  • 1.
    1/3/2023 1 EI-OE-401 Open ElectiveIV (Computer Graphics and CAD/CAM) Module - 2 Polygon Clipping Prof. Pardeep Kumar Department of Instrumentation, Kurukshetra University, Kurukshetra-136119 pardeepk@kuk.ac.in • Points and lines, Line drawing algorithms, midpoint circle and ellipse algorithms. Filled area primitives: scan line polygon fill algorithm, boundary- fill and flood fill algorithms. • Translation, scaling, rotation, reflection and shear transformations, matrix representations and homogeneous coordinates, composite transforms, transformation between coordinate systems. 2-D Viewing: The viewing pipeline, viewing coordinate reference frame, window to viewport coordinate transformation, viewing functions, Cohen-Sutherland and Cyrus beck line clipping algorithms • Reference Books: Computer Graphics by Hearn & Donald, PHI Computer Graphic by Plastock, McGraw Hill Principle of Interactive graphics by Newman.W Spraul R.F., McGraw Hill Procedural Elements of computer graphics by Rogers D.F., McGraw Hill Module – II Syllabus 2 January 3, 2023 DOI, Kurukshetra University There will be continuous evaluation in the form of Assignments, quizzes etc. After completion there will be a class test
  • 2.
    1/3/2023 2 • Polygon clipping –Sutherland-Hodgman, – Weiler-Atherton • Polygon filling – Scan filling polygons – Flood filling polygons • Introduction and discussion of Assignment work #2 Outline 3 January 3, 2023 DOI, Kurukshetra University Polygons Clipping January 3, 2023 DOI, Kurukshetra University 4
  • 3.
    1/3/2023 3 • Ordered setof vertices (points) – Usually counter-clockwise • Two consecutive vertices define an edge • Left side of edge is inside • Right side is outside • Last vertex implicitly connected to first • In 3D vertices are co-planar Polygon 5 January 3, 2023 DOI, Kurukshetra University • Convex –All interior angles are less than 180 degrees • Concave –Interior angles can be greater than 180 degrees • Degenerate polygons –If all vertices are collinear Polygon Classification 6 January 3, 2023 DOI, Kurukshetra University
  • 4.
    1/3/2023 4 Clipping polygons ismore complex than clipping the individual lines – Input: polygon – Output: original polygon, new polygon, or nothing When can we trivially accept/reject a polygon as opposed to the line segments that make up the polygon? Clipping Polygons 7 January 3, 2023 DOI, Kurukshetra University • Clipping a polygon fill area needs more than line-clipping of the polygon edges – would produce an unconnected set of lines • Must generate one or more closed polylines, which can be filled with the assigned colour or pattern Clipping Polygons 8 January 3, 2023 DOI, Kurukshetra University
  • 5.
    1/3/2023 5 What happens toa triangle during clipping? Possible outcomes: How many sides can a clipped triangle have? Clipping Polygons 9 January 3, 2023 DOI, Kurukshetra University triangle triangle triangle quad triangle 5-gon How many sides? 10 January 3, 2023 DOI, Kurukshetra University Seven… Five…
  • 6.
    1/3/2023 6 Polygon clipping 11 January 3,2023 DOI, Kurukshetra University • Clipping is symmetric Polygon clipping is complex 12 January 3, 2023 DOI, Kurukshetra University • Even when the polygons are convex • A really tough case: concave polygon multiple polygons
  • 7.
    1/3/2023 7 Polygon clipping isnasty 13 January 3, 2023 DOI, Kurukshetra University • When the polygons are concave • Basic Algorithm – N*m intersections – Then must link all segment – Not efficient and not even easy • Lots of different cases • Issues – Edges of polygon need to be tested against clipping rectangle – May need to add new edges – Edges discarded or divided – Multiple polygons can result from a single polygon Polygon Clipping 14 January 3, 2023 DOI, Kurukshetra University
  • 8.
    1/3/2023 8 Sutherland-Hodgeman Clipping January 3, 2023DOI, Kurukshetra University 15 • Find the vertices of the new polygon(s) inside the window. • Sutherland-Hodgeman 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 Polygon Clipping 16 January 3, 2023 DOI, Kurukshetra University
  • 9.
    1/3/2023 9 Sutherland-Hodgeman Clipping 17 January 3,2023 DOI, Kurukshetra University Basic idea: – Consider each edge of the viewport individually – Clip the polygon against the viewport edge’s equation – After doing all edges, the polygon is fully clipped Input/output for algorithm: – Input: list of polygon vertices in order – Output: list of clipped poygon vertices consisting of old vertices (maybe) and new vertices (maybe) Note: this is exactly what we expect from the clipping operation against each edge. Sutherland-Hodgeman Clipping 18 January 3, 2023 DOI, Kurukshetra University Divide and Conquer • Idea: ‒ Clip single polygon using single infinite clip edge ‒ Repeat 4 times Note the generality: ‒ 2D convex n-gons can clip arbitrary n-gons ‒ 3D convex polyhedra can clip arbitrary polyhedra
  • 10.
    1/3/2023 10 • Input: – v1,v2, … vn the vertices defining the polygon – Single infinite clip edge w/ inside/outside info • Output: – v’1, v’2, … v’m, vertices of the clipped polygon • Do this 4 (or ne) times • Traverse vertices (edges) • Add vertices one-at-a-time to output polygon – Use inside/outside info – Edge intersections Sutherland-Hodgman Algorithm 19 January 3, 2023 DOI, Kurukshetra University Sutherland-Hodgman basic routine: – Go around polygon one vertex at a time – Current vertex has position p – Previous vertex had position s, and it has been added to the output if appropriate Edge from s to p takes one of four cases: (Orange line can be a line or a plane) Sutherland-Hodgeman Clipping 20 January 3, 2023 DOI, Kurukshetra University inside outside s p p output inside outside s p no output inside outside s p i output inside outside s p i output p output
  • 11.
    1/3/2023 11 • Can bedone incrementally • If first point inside add. If outside, don’t add • Move around polygon from vi to vn and back to vi • Check vi,vi+1 w.r.t. the clip edge • Need vi,vi+1‘s inside/outside status • Add vertex one at a time. There are 4 cases: Sutherland-Hodgeman Clipping 21 January 3, 2023 DOI, Kurukshetra University 4 cases 22 January 3, 2023 DOI, Kurukshetra University
  • 12.
    1/3/2023 12 Four cases: 1. sinside plane and p inside plane – Add p to output – Note: s has already been added 2. s inside plane and p outside plane – Find intersection point i – Add i to output 3. s outside plane and p outside plane – Add nothing 4. s outside plane and p inside plane – Find intersection point i – Add i to output, followed by p Sutherland-Hodgeman Clipping 23 January 3, 2023 DOI, Kurukshetra University inside outside s p p output inside outside s p i output inside outside s p no output inside outside s p i output p output • A very general test to determine if a point p is “inside” a plane P, defined by q and n: (p - q) • n < 0: p inside P (p - q) • n = 0: p on P (p - q) • n > 0: p outside P Remember: p • n = |p| |n| cos (q) q = angle between p and n Sutherland-Hodgeman Clipping 24 January 3, 2023 DOI, Kurukshetra University P n p q P n p q P n p q
  • 13.
    1/3/2023 13 for each polygonP P’ = P for each clipping edge (there are 4) { Clip polygon P’ to clipping edge for each edge in polygon P’ Check clipping cases (there are 4) Case 1 : Output vi+1 Case 2 : Output intersection point Case 3 : No output Case 4 : Output intersection point & vi+1 } Sutherland-Hodgman Algorithm 25 January 3, 2023 DOI, Kurukshetra University Implementation 26 January 3, 2023 DOI, Kurukshetra University
  • 14.
    1/3/2023 14 Sutherland-Hodgeman Clipping 27 January 3,2023 DOI, Kurukshetra University Sutherland-Hodgeman Clipping 28 January 3, 2023 DOI, Kurukshetra University
  • 15.
    1/3/2023 15 • The algorithmcorrectly clips convex polygons, but may display extraneous lines for concave polygons • When we have concave polygon then the above algorithm might produce polygons with coincident edges (Connected edges) • This is fine for rendering but maybe not for other applications (e.g shadows) • The Weiler-Atherton algorithm produces separate polygons for each visible fragment Issues with Sutherland-Hodgman Algorithm 29 January 3, 2023 DOI, Kurukshetra University Weiler-Atherton Algorithm January 3, 2023 DOI, Kurukshetra University 30
  • 16.
    1/3/2023 16 • Problem inSutherland-Hodges. Weiler-Artherton has a solution • Clipping other shapes: Circle, Ellipse, curves • Clipping a shape against other shapes • Clipping the exteriors. Other Issues in clipping 31 January 3, 2023 DOI, Kurukshetra University • General clipping algorithm for concave polygons with holes – Produces multiple polygons (with holes) – Make linked list data structure – Traverse to make new polygon(s) Weiler-Atherton Algorithm 32 January 3, 2023 DOI, Kurukshetra University
  • 17.
    1/3/2023 17 • Given polygonsA and B as linked list of vertices (counter- clockwise order) • Find all edge intersections & place in list • Insert as “intersection” nodes • Nodes point to A & B • Determine in/out status of vertices Weiler-Atherton Algorithm 33 January 3, 2023 DOI, Kurukshetra University • If “intersecting” edges are parallel, ignore • Intersection point is a vertex – Vertex of A lies on a vertex or edge of B – Edge of A runs through a vertex of B • Replace vertex with an intersection node Intersection Special Cases 34 January 3, 2023 DOI, Kurukshetra University
  • 18.
    1/3/2023 18 If polygons don’tintersect – Union • If one inside the other, return polygon that surrounds the other • Else, return both polygons – Intersection • If one inside the other, return polygon inside the other • Else, return no polygons Boolean Special Cases 35 January 3, 2023 DOI, Kurukshetra University • Find a vertex of A outside of B • Traverse linked list • At each intersection point switch to other polygon • Do until return to starting vertex • All visited vertices and nodes define union’ed polygon Weiler-Atherton Algorithm: Union 36 January 3, 2023 DOI, Kurukshetra University
  • 19.
    1/3/2023 19 • Start atintersection point – If connected to an “inside” vertex, go there – Else step to an intersection point – If neither, stop • Traverse linked list • At each intersection point switch to other polygon and remove intersection point from list • Do until return to starting intersection point • If intersection list not empty, pick another one • All visited vertices and nodes define and’ed polygon Weiler-Atherton Algorithm: Intersection 37 January 3, 2023 DOI, Kurukshetra University Weiler-Atherton Algorithm 38 January 3, 2023 DOI, Kurukshetra University 1 2 3 5 4 6 8 7 9 0 a b c d a b c d 0 1 2 3 4 5 6 7 8 9 A B i j k l clip region polygon loop of polygon vertices loop of region vertices
  • 20.
    1/3/2023 20 • Find theintersection vertices and connect them in the two lists Weiler-Atherton Algorithm 39 January 3, 2023 DOI, Kurukshetra University 1 2 3 5 4 6 8 7 9 0 a b c d a b c d 0 1 2 3 4 5 6 7 8 9 A B i j k l clip region polygon i l k j Add vertex i: • Find the intersection vertices and connect them in the two lists Weiler-Atherton Algorithm 40 January 3, 2023 DOI, Kurukshetra University a b c d 0 1 2 3 4 5 6 7 8 9 A B i j k l clip region polygon 1 2 3 5 4 6 8 7 9 0 a b c d i l k j Add vertex l:
  • 21.
    1/3/2023 21 • Find theintersection vertices and connect them in the two lists Weiler-Atherton Algorithm 41 January 3, 2023 DOI, Kurukshetra University a b c d 0 1 2 3 4 5 6 7 8 9 A B i j k l clip region polygon 1 2 3 5 4 6 8 7 9 0 a b c d i l k j Add vertex k: • Computed loop Weiler-Atherton Algorithm 42 January 3, 2023 DOI, Kurukshetra University a b c d 0 1 2 3 4 5 6 7 8 9 A B i j k l clip region polygon 1 2 3 5 4 6 8 7 9 0 a b c d i l k j Add vertex j:
  • 22.
    1/3/2023 22 • Classify eachintersection vertex as Entering or Leaving Weiler-Atherton Algorithm 43 January 3, 2023 DOI, Kurukshetra University a b c d 0 1 2 3 4 5 6 7 8 9 A B i j k l clip region polygon 1 2 3 5 4 6 8 7 9 0 a b c d i l k j Entering Leaving • Start at an entering vertex • If you encounter a leaving vertex swap to right hand (clip polygon) loop • If you encounter an entering vertex swap to left hand (polygon) loop • A loop is finished when you arrive back at start • Repeat whilst there are entering vertices Capture clipped polygons 44 January 3, 2023 DOI, Kurukshetra University 1 2 3 5 4 6 8 7 9 0 a b c d i l k j Entering Leaving Loop 1: L, 4, 5, K Loop 2: J, 9, 0, i
  • 23.
    1/3/2023 23 January 3, 2023 DOI,Kurukshetra University 45 Any Question? Thanks!