Intersections Two Convex Polygons R. Inkulu http://www.iitg.ac.in

Intersections
Two Convex Polygons
R. Inkulu
http://www.iitg.ac.in/rinkulu/
(Intersections: Convex Polygons)
1 / 15
Problem Description
Given two convex polygons P1 and P2 of sizes n1 and n2 respectively,
compute P = P1 ∩ P2 .
(Intersections: Convex Polygons)
2 / 15
Outline
1
Prepara-Hoey’s Algorithm
2
O’Rourke’s Algorithm
(Intersections: Convex Polygons)
3 / 15
Plane-Sweep Algorithm
0000000
1111111
1111111
0000000
0000000
1111111
0000000
1111111
0000000
1111111
0000000
1111111
0000000
1111111
0000000
1111111
0000000
1111111
0000000
1111111
0000000
1111111
0000000
1111111
0000000
1111111
0000000
1111111
0000000
1111111
0000000
1111111
0000000
1111111
0000000
1111111
0000000
1111111
0000000
1111111
• Sort upper and lower hull vertices of P1 based on their x-coordi (resp.
P2 ) and save in list L1 (resp. L2 )
• Merge L1 and L2 to obtain L; with each vertex save info such as which
polygon it belongs to etc.,
• Computer P while traversing L:
compute the intersection of two quadrilaterals in each slab, and
remove a vertex from P whenever three vertices are collinear.
(Intersections: Convex Polygons)
4 / 15
Analysis
• O(n1 + n2 ) time.
• O(n1 + n2 ) space.
(Intersections: Convex Polygons)
5 / 15
Outline
1
Prepara-Hoey’s Algorithm
2
O’Rourke’s Algorithm
(Intersections: Convex Polygons)
6 / 15
Characterizing sickles
000000000000000000000000
111111111111111111111111
111111111111111111111111
000000000000000000000000
000000000000000000000000
111111111111111111111111
000000000000000000000000
111111111111111111111111
000000000000000000000000
111111111111111111111111
000000000000000000000000
111111111111111111111111
000000000000000000000000
111111111111111111111111
000000000000000000000000
111111111111111111111111
000000000000000000000000
111111111111111111111111
000000000000000000000000
111111111111111111111111
000000000000000000000000
111111111111111111111111
000000000000000000000000
111111111111111111111111
000000000000000000000000
111111111111111111111111
000000000000000000000000
111111111111111111111111
000000000000000000000000 sickles
111111111111111111111111
000000000000000000000000
111111111111111111111111
000000000000000000000000
111111111111111111111111
000000000000000000000000
111111111111111111111111
000000000000000000000000
111111111111111111111111
000000000000000000000000
111111111111111111111111
000000000000000000000000
111111111111111111111111
000000000000000000000000
111111111111111111111111
000000000000000000000000
111111111111111111111111
• Two successive intersection points on P together form a sickle.
• Removing all the sickles yield the required.
• Intersection points’ always occur in pairs.
(Intersections: Convex Polygons)
7 / 15
Removing sickels
1,13,28
2,15,30
0’,12,27
11,26
14,29
16
3,17
10,25
0’’,18
9,24
4,19
5,20
6,21
8,23
7,22
• While traversing boundaries of P1 and P2 simultaneously in CCW order,
remove sickles, while maintaining P.
• How many pointer advances are required in total?
(Intersections: Convex Polygons)
8 / 15
Making a pointer reach an intersection point v
ri
v
w
Let the pointers together advance for n1 + n2 steps:
• boundary of one polygon is guaranteed to be completely traversed (from
the listed cases).
• ensures one of the pointers’ reachng some intersection point (whenever
P 6= φ).
(Intersections: Convex Polygons)
9 / 15
Placing both the pointers at the same intersection point
cases (b), (d)
ri
v
ri
case (c)
br
case (a)
v
rm
br
w
rt
case (d)
bj
w
bs
case (b)
bs
(a) bptr is on (bs − br ]; move
bptr till v
(b) bptr is on (br − bs ];
move rptr till w
all these cases are listed exhaustively later.
• The pointer advance schedule requires to be designed to place both the
pointers at the same intersection point without causing any deadlocks.
(Intersections: Convex Polygons)
10 / 15
Identifying sickles in succession
13,28
12,27
15,30
11,26
14,29
16
17
10,25
18
9,24
19
5,20
6,21
8,23
7,22
• Once both the pointers pass through the same intersection point, all the
sickles will be constructed in succession (due to cases mentioned above)
by a single traversal of P1 and P2 .
(Intersections: Convex Polygons)
11 / 15
Pointer advancing approach
P
advance either
00000
11111
11111
00000
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
advance
00000
11111
(a)
(b)
11111
00000
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
00000
11111
advance
00000
11111
00000
11111
(c)
0000
1111
0000
1111
0000
1111
0000
1111
0000
1111
0000
1111
0000
1111
0000
1111
0000
1111
0000
1111
0000
1111
0000
1111
0000
1111
0000
1111
0000
1111
0000
1111
0000
1111
0000
1111
0000
1111
advance
(d)
bptr and rptr are moving in CCW direction; polygonal chains are shown as lines; solid arrows
represent the current edge to which bptr and rptr refer to.
• Do not advance on a boundary whose current edge may contain a yet to
be found intersection.
(Intersections: Convex Polygons)
12 / 15
Algorithm
• Find all the intersection points (and sickles) of P1 and P2 while
advancing pointers over P1 and P2 together for 2(n1 + n2 ).
(implicitly) first brings both the pointers to the same intersection point.
• If no intersection has been found, determine whether P1 ⊂ P2 or
P2 ⊂ P1 or P1 ∩ P2 = φ.
(Intersections: Convex Polygons)
13 / 15
Running Example
1,13,28
2,15,30
0’,12,27
11,26
14,29
16
3,17
10,25
0’’,18
9,24
4,19
5,20
6,21
8,23
7,22
(Intersections: Convex Polygons)
14 / 15
Analysis
• 4(n1 + n2 ) time.
placing rptr/bptr at an intersection point v: n1 + n2
finding all the sickles (including bringing the other point to v): n1 + n2
two polygon inclusion tests: 2(n1 + n2 )
• O(n1 + n2 ) space.
(Intersections: Convex Polygons)
15 / 15