You are on page 1of 89

Intersection

Introduction
Intersection example 1
Given a set of N axis-parallel rectangles in the plane, report all
intersecting pairs. (Intersect share at least one point.)
r
7
r
2
r
8
r
6
r
5
r
4
r
3
r
1
Answer: (r
1
, r
3
) (r
1
, r
8
) (r
3
, r
4
) (r
3
, r
5
) (r
4
, r
5
) (r
7
, r
8
)
Intersection example 2
Given two convex polygons, construct their intersection.
(Polygon boundary and interior, intersection all points that
are members of both polygons.)
A
B A B
Intersection
Introduction
General intersection problems

Test or decision problem
Given two geometric objects, determine if they intersect.

Pairwise counting or reporting problem
Given a data set of N geometric objects, count or report their
intersections.

Construction problem
Given a data set of N geometric objects, construct a new object
which is their intersection.
Intersection
Introduction
Applications
Domain: Graphics
Problem: Hidden-line and hidden surface removal
Approach: Intersection of two polygons
Type: Construction





Domain: Pattern recognition
Problem: Finding a linear classifier between two sets of points
Approach: Intersection of convex hulls
Type: Test





Domain: VLSI design
Problem: Component overlap detection
Approach: Intersection of rectangles
Type: Pairwise





Intersection
Introduction
Problem definition
Given N line segments in the plane, report all their points of
intersection (pairwise).

LINE SEGMENT INTERSECTION (LSI).
INSTANCE: Set S = {s
1
, s
2
, ..., s
N
} of line segments in the plane.
For 1 s i s N, s
i
= (e
i1
, e
i2
) (endpoints of the segments),
and for 1 s j s 2, e
ij
= (x
ij
, y
ij
) (coordinates of the endpoints).
QUESTION: Report all points of intersection of segments in S.

Note that this problem is single-shot, not repetitive mode.

Assumptions
1. No segments of S are vertical.
2. No three segments meet at a point.
Intersection
Intersection of line segments
Intersection
Intersection of line segments, brute force algorithm
Algorithm
For every pair of segments in S, test the two segments for
intersection.

(Segment intersection test can be done in constant time.
The test involves the parametric equations of the lines defined
by the segments and the dot product operation.
See Laszlo pp. 90-93 for details.)

Analysis
Preprocessing: None
Query: O(N
2
); there are N(N - 1) / 2 e O(N
2
) pairs,
each requiring a constant time test.
Storage: O(N); for S.

Can we do better?
Intersection
Intersection of line segments, Shamos-Hoey algorithm
Segment ordering, 1
We need some way to order segments in the plane.
Two segments are comparable at abscissa x iff - a vertical line
through x that intersects both of them.

Define the relation above at x as follows:
segment s
1
is above segment s
2
at x, written s
1
>
x
s
2
,
if s
1
and s
2
are comparable at x and the y-coordinate of the
intersection of s
1
with the vertical line through x is greater
than the y-coordinate of the intersection of s
2
with that line.
u
v
s
4
s
2
s
1
s
3
In the example, s
2
>
u
s
4
, s
1
>
v
s
2
, s
2
>
v
s
4
, and s
1
>
v
s
4
.
Segment s
3
is not comparable with any other segment.
Segment ordering, 2
Preparata defines relation >
x
for non-intersecting segments
(see p. 281), and then applies it to segments that may intersect
(see p. 282). Luckily, this does not affect the algorithm.

As the vertical line sweeps, the ordering changes in three ways:
1. The left endpoint of a segment s is encountered.
Segment s must be added to the ordering.
2. The right endpoint of a segment s is encountered.
Segment s must be removed from the ordering.
3. An intersection point of two segments s
1
and s
2
is encountered.
Segments s
1
and s
2
, exchange places in the ordering.
Intersection
Intersection of line segments, Shamos-Hoey algorithm
Crucial observation: For two segments s
1
and s
2
to intersect,
there must be some x for which s
1
and s
2
are consecutive
in the >
x
ordering.

This suggests that the sequence of intersections of the segments
with the vertical line contains the information needed to find
the intersections between the segments.

That suggests a plane sweep algorithm.
Plane sweep algorithms often use two data structures:
1. Sweep-line status
2. Event-point schedule
s
1
s
2
Algorithm idea
x
Intersection
Intersection of line segments, Shamos-Hoey algorithm
Sweep-line status
The sweep-line status is a list of the currently comparable
segments, ordered by the relation >
x
.

The sweep-line status data structure L is used to store the
ordering of the currently comparable segments. Because the set
of currently comparable segments changes, the data structure for
L must support these operations:
1. INSERT(s, L). Insert segment s into the total order in L.
2. DELETE(s, L). Delete segment s from L.
3. ABOVE(s, L). Return the name of the segment
immediately above s in the ordering in L.
4. BELOW(s, L). Return the name of the segment
immediately below s in the ordering in L.

The dictionary data structure (see Preparata pp. 11-13) can
perform all of these operations in O(log N) time (or better).
Intersection
Intersection of line segments, Shamos-Hoey algorithm
Event-point schedule
As the sweep-line is swept from left to right, the set of the currently
comparable segments and/or their ordering by the relation >
x
changes at a finite set of x values; those are known as events.

The events for this problem are segment endpoints and segment
intersections. The event-point schedule data structure E is used to
store events prior to their processing. For E the following
operations are needed:
1. MIN(E). Determine the smallest element in E (based on x),
return it, and delete it.
2. INSERT(x, E). Insert abscissa x, representing an event, into E.
3. MEMBER(x, E). Determine if abscissa x is a member of E.

The priority queue data structure (see Preparata pp. 11-13) can
perform all of these operations in O(log N) time.
Intersection
Intersection of line segments, Shamos-Hoey algorithm
Algorithm

1 procedure LineSegmentIntersection(S)
2 begin
3 Sort the 2N endpoints of S lexicographcially by x and y and load them into E;
4 A = C; /* A is an internal working queue. */
5 while (E = C) do
6 begin
7 p = MIN(E);
8 if (p is a left endpoint) then
9 begin
10 s = segment of which p is endpoint;
11 INSERT(s, L);
12 s
1
= ABOVE(s, L);
13 s
2
= BELOW(s, L):
14 if (s
1
intersects s) then add (s
1
, s) to A;
15 if (s
2
intersects s) then add (s
2
, s) to A;
16 end
17 else if (p is a right endpoint) then
18 begin
19 s = segment of which p is endpoint;
20 s
1
= ABOVE(s, L);
21 s
2
= BELOW(s, L):
22 if (s
1
intersects s
2
to the right of p) then add (s
1
, s
2
) to A;
23 DELETE(s, L);
24 end
25 else /* p is an intersection */
26 begin
27 s
1
, s
2
= segments that intersect at p, with s
1
above s
2
to the left of p.
28 s
3
= ABOVE(s
1
, L);
29 s
4
= BELOW(s
2
, L):
30 if (s
3
intersects s
2
) then add (s
3
, s
2
) to A;
31 if (s
1
intersects s
4
) then add (s
1
, s
4
) to A;
32 Interchange s
1
and s
2
in L;
33 end

Algorithm continued on next page.
Intersection
Intersection of line segments, Shamos-Hoey algorithm
Algorithm, 2


34 /* The detected intersections must now be processed */
35 while (A = C) do
36 begin
37 (s
1
, s
2
) = get and remove first element of A;
38 x = x-coordinate of intersection point of s
1
and s
2
;
39 if (MEMBER(x, E) = FALSE) then
40 begin
41 report (s
1
, s
2
);
42 INSERT(x, E);
43 end
44 end
45 end
46 end

The while (A = C) do block (lines 35-44) is within the while (E = C) do
begin-end block (lines 5-45).
Intersection
Intersection of line segments, Shamos-Hoey algorithm
Problems with the Shamos-Hoey algorithm, as given in Preparata
Cases excluded by assumption:
1. Vertical segments.
2. Three (or more) segments intersecting at a single point.

Cases not handled:
1. Multiple intersections at same abscissa (fails at line 39).
2. Intersection and endpoint at same abscissa (fails at line 39).
3. Segments that intersect at endpoints (special case of 2,
pointed out by Franceschini).
4. Segments that intersect at >1 point (i.e. collinear overlap).
5. Event type (left endpoint, right endpoint, intersection) is
tested by the algorithm (lines 8 and 17) but never stored in E.
1 2 3 4
Intersection
Intersection of line segments, Shamos-Hoey algorithm
Analysis
Preprocessing: O(N log N); sort of endpoints.
Query: O((N + K) log N); each of 2N endpoints and K intersections
are inserted into E, an O(log N) operation.
Storage: O(N + K); at most 2N endpoints and K intersections are
stored in E.

Comments
Here query refers to the process of finding intersections;
this is a single-shot problem.
Query time of O((N + K) log N) is suboptimum.
An optimum O(N log N + K) algorithm exists, but is quite difficult.
Laszlo (1996) still presents the Shamos-Hoey algorithm (1976)
20 years later.
Intersection
Intersection of line segments, Shamos-Hoey algorithm
Intersection
Interval trees
Notation
The notation used here for interval trees is not consistent with either
Preparata (pp. 359-363) or Ullman (pp. 385-393), which are
unfortunately not consistent with each other.
This notation is consistent with notation used earlier
for similar concepts regarding segment trees.

Definition, 1
An interval tree is a rooted binary tree that stores data intervals on
the real line whose endpoints are integers within a fixed scope.
It is the scope from within the endpoints are chosen that is fixed,
not the data interval endpoints themselves.

The tree structure in which the intervals are stored is defined for
a scope interval [l, r], where l and r must be consecutive multiples
of the same power of 2.
For a given [l, r] there is exactly one interval tree structure.
The data intervals are stored within the fixed tree.
We will assume WLOG that the data interval endpoints have
been normalized to [1, N] and the tree has been built for scope
interval [0, 2
k
], where N + 1s 2
k
.

T(l, r) = Interval tree over scope interval [l, r].
Each node of T(l, r) is associated with a scope interval _ [l, r].
Intersection
Interval trees
Definition, 2

A node v has these parameters:
B(v) Beginning of scope interval associated with this node.
E(v) End of scope interval associated with this node.
M(v) Midpoint of scope interval, M(v) = (B(v) + E(v)) / 2.
Lchild(v) Left subtree = T(B(v), (B(v) + E(v)) / 2)
Rchild(v) Right subtree = T((B(v) + E(v)) / 2, E(v))
L(v) AVL tree containing data intervals stored at v,
ordered on ascending left endpoint.
R(v) AVL tree containing data intervals stored at v,
ordered on descending right endpoint.
Lptr(v) Pointer to left subchild in secondary search tree.
Rptr(v) Pointer to right subchild in secondary search tree.
Status(v) e { active, inactive } = active iff
(L(v) = C or there are active nodes
in both subtrees (Lchild(v) and Rchild(v))

[B(v), E(v)] is the scope interval associated with node v.
We will refer to a data interval as [b, e]. Data intervals will be
stored at the highest node where B(v) < b s M(v) s e < E(v).

Operations preview.

The interval tree supports interval insert, delete, and query
operations, all in O(log N) time, as will be shown.
Query is defined as reporting overlaps between a query interval
and the data intervals stored in the tree.
Intersection
Interval trees
Example
The structure of the interval tree T(0,16) is shown;
0 = 0 2
4
, 16 = 1 2
4
.
Each node is labeled with B(v), E(v) of its scope interval.
Data intervals [0,4], [7,12], [9,10], [9,11], [1,1], [6,7], [13,15],
and [1,6] are shown below the node where they would be stored.

Note that T(0,16) is shown here down to a level that accomodates
0 length intervals (e.g. [1,1]); if such degenerate cases will not occur,
the lowest level is usually not represented. To simplify the figures,
that level (and interval [1,1]) will be omitted hereinafter.
0,16
8,16
8,12 12,16
8,10 10,12 12,14 14,16
0,8
0,4 4,8
0,2 2,4 4,6 6,8
[9,10]
[7,12]
[0,4]
[9,11]
[1,1]
[6,7]
[13,15]
[1,6]
Intersection
Interval trees
Data trees
Each node v has attached two AVL trees, L(v) and R(v), that hold
the intervals stored at this node, ordered by ascending left endpoint
and descending right endpoint respectively.

L(v) and R(v) are shown for node 0,8 only; every node would have
similar trees.
0,16
8,16
8,12 12,16
0,8
0,4 4,8
[9,10]
[7,12]
[9,11]
[6,7] [13,15]
[0,4]
[1,6]
L
[1,6]
[0,4]
R
L(v) and R(v) are threaded to allow ordered scans of the data intervals
contained therein without requiring a binary search.
descending right ascending left
Intersection
Interval trees
Secondary search tree
The active nodes of an interval tree are connected by pointers,
forming a secondary binary search tree within the interval tree.
The secondary search tree allows the interval tree to be searched
without requring numerous accesses to empty nodes.
Lptr(v) and Rptr(v) hold the secondary search tree pointers.
Active nodes are in the secondary search tree.
0,16
8,16
8,12 12,16
0,8
0,4 4,8
[9,10]
[7,12]
[9,11]
[6,7] [13,15]
In this example, data intervals [0,4] and [1,6] are not present.
Nodes 0,16, 4,8, 8,12, and 12,16 are active because there are
data intervals stored at those nodes.
Node 8,16 is active because both of its child nodes are active.
Nodes 0,8 and 0,4 are inactive because there are no intervals
stored at those nodes and neither has two active child nodes.

Because a binary tree has one more leaf node than internal nodes,
it can be shown that the number of empty active nodes is less
than half the number of non-empty active nodes.
Intersection
Interval trees
Insertion
The interval tree T(l,r) supports insertions and deletions of
data intervals [b, e] with endpoints l < b s e < r,
in O(log N) time per operation.

As mentioned, data interval [b, e] inserted into T(l, r)
will be stored at the highest node where b s M(v) s e.

To insert interval [b, e] into interval tree T(l,r):
InsertIntervalTree(b, e, root(T))

procedure InsertIntervalTree(b, e, v)
begin
if (b s M(v) s e) then /* Data interval straddles midpoint */
add [b, e] to L(v) and R(v) /* 2 O(log N) */
adjust the secondary search tree pointers as needed
else
if (e < M(v)) then /* Data interval left of midpoint */
InsertIntervalTree(b, e, Lchild(v))
else /* M(v) < b, Data interval right of midpoint */
InsertIntervalTree(b, e, Rchild(v))
end
end
Intersection
Interval trees
Deletion
Deletion is symmetric with insertion.

To delete interval [b, e] from interval tree T(l,r):
DeleteIntervalTree(b, e, root(T))

procedure DeleteIntervalTree(b, e, v)
begin
if (b s M(v) s e) then
delete [b, e] from L(v) and R(v) /* 2 O(log N) */
adjust the secondary search tree pointers as needed
else
if (e < M(v)) then
DeleteIntervalTree(b, e, Lchild(v))
else /* M(v) < b */
DeleteIntervalTree(b, e, Rchild(v))
end
end
Intersection
Interval trees
Query
To report data intervals that overlap query interval [b, e]:

QueryIntervalTree(b, e, root(T))

procedure QueryIntervalTree(b, e, v)
begin
if (b s M(v) s e) then /* Query interval straddles midpoint, as do all intervals at v */
begin
report all intervals in L(v)
QueryIntervalTree(b, e, Lptr(v))
QueryIntervalTree(b, e, Rptr(v))
end
else
if (e < M(v)) then /* Query interval to left of midpoint */
begin
i = 1
while (the ith interval [l
i
, r
i
] in L(v) has l
i
s e) do
begin
report [l
i
, r
i
]
i++
end
QueryIntervalTree(b, e, Lptr(v))
end
else /* M(v) < b, i.e. query interval to right of midpoint */
begin
i = 1
while (the ith interval [l
i
, r
i
] in R(v) has r
i
> b) do
begin
report [l
i
, r
i
]
i++
end
QueryIntervalTree(b, e, Rptr(v))
end
end
end

Note that Lptr(v) and Rptr(v) are used (not Lchild(v) and Rchild(v))
so as to use the secondary search tree.
Intersection
Interval trees
Analysis preliminaries

It must be shown that the query algorithm has time complexity
e O(log N + K).
reporting overlaps
traversal time

To do so, it will be necessary to consider the interval tree data
structure and the geometric interpretation of the data simultaneously.

Recall that the query traverses the secondary search tree, rather than
the primary interval tree, thereby bypassing inactive nodes.

Scope interval Interval represented by a node; [B(v), E(v)].
Data interval Interval stored at a node; by definition, straddles
the midpoint M(v) of the scope interval.
Query interval Interval against which the data intervals are being
compared for overlap; [b, e].

Intersection
Interval trees
Overlap classes
During a query traversal, the overlap between a query interval
[b, e] and a scope interval [B(v), E(v)] for a node will be one of
five classes:
B(v) E(v) M(v)
b e
B(v) E(v) M(v)
b e
A or
B(v) E(v) M(v)
b e
D
B(v) E(v) M(v)
B
b e
B(v) E(v) M(v) B(v) E(v) M(v)
C
1
or
b e e b
B(v) E(v) M(v) B(v) E(v) M(v)
C
2
or
b e e b
Intersection
Interval trees
Transition rules for overlap classes
As the query traversal proceeds, the overlap class at a node
determines the type(s) of overlap classes that can occur at
the descendants of that node later/lower in the traversal.

Class Class of Left Child Class of Right Child
A A or B* No intersection*
B C
1
or C
2
C
1
or C
2

C
1
D C
1
or C
2

C
2
C
1
or C
2
* No intersection*
D D D

* These entries assume left overlap; they are reversed for
right overlap.
Intersection
Interval trees
Overlap classes for a query traversal
The overlap transition rules mean that tree traversed by a query
will look something like this.
(This is the table from the previous page arranged as a tree.)
A
A
B
C C
C D
C
C D
C
C
C D
Once a class D node is reached, all data intervals in the subtree
overlap the query interval and will be reported.
C = C
1
or C
2
Intersection
Interval trees
Traversal length, 1
The overlap transition rules imply a maximum fan out of the
tree searched in a query traversal.

Number of Number of non-D
Class Child Nodes to Search Child Nodes to Search
A 1 1
B 1 or 2 1 or 2
C
1
or C
2
1 or 2 1
D 2 0

No A, B, or C (C
1
or C
2
) node requires the search of > 2 child nodes.
The secondary search tree has depth log N.
The number of class A, B, or C nodes traversed in a query
is s 2 log N.
The query time complexity, neglecting class D nodes,
is e O(log N).

But what about class D nodes?
Intersection
Interval trees
Traversal length, 2
Close but not quite right answer:
Every data interval at a class D node overlaps the query interval.
The time to access the class D nodes can be charged to reporting,
i.e. is e O(K).

This is not quite right because some active class D nodes might
have empty data interval lists; they are active because both subtrees
are active.

Right answer:

A binary tree has one more leaf the non-leaf nodes.
The subtrees of the class D nodes are binary trees.
More than half of the class D nodes have non-empty interval lists.
The time to access the class D nodes, both empty and non-empty,
can be charged to reporting, i.e. is e O(K).

Overall query time complexity
O(log N + K); O(log N) to traverse the class A, B, C
1
, and C
2
nodes,
and O(K) to traverse the class D nodes and report overlapping
intervals.
Intersection
Interval trees
Storage analysis
Assume N data intervals.
s 2N distinct endpoints after normalization.
2
k-1
s 2N s 2
k

Upper limit 2
k
because for T(l,r) r must be a multiple
of a power of 2.


Lower limit 2
k-1
because otherwise 2
k-1
would be r.

2(2
k-1
)

s 2(2N) s 2(2
k
) Multiply through by 2.
2
k
s 4N s 2
k+1

2N s 2
k
s 4N Collect terms.
2
k
e O(N)
Primary interval tree has O(N) nodes and O(log N) levels.

There are a total of 2N intervals stored in the data trees attached to
the nodes. (A data interval is stored at one node in an interval tree,
in the L and R AVL trees at that node.)
Intersection
Interval trees
Analysis summary
Preprocessing: O(N log N); N data intervals, O(log N) to insert each.
There are actually 3 O(log N) operations per insertions:
(1) traversing the primary search tree
(2) inserting the data interval into L AVL tree
(3) inserting the data interval into R AVL tree
Query: O(log N + K); as shown.
Storage: O(N); as shown.

Comments
Observe that the data trees need to be AVL trees only if O(log N)
insert and delete operations are needed. If the data set is static,
simple lists can be used instead, because the query operation scans
the data lists anyway.

The interval tree is a versatile data structure.
We will use it to solve the next intersection problem.
Intersection
Intersection of rectangles
Problem definition
RECTANGLE INTERSECTION
INSTANCE: Set S = {r
1
, r
2
, ..., r
N
} of rectangles in the plane.
For 1 s i s N, r
i
= ((x
il
, y
il
), (x
il
, y
ir
), (x
ir
, y
il
), (x
ir
, y
ir
)).
QUESTION: Report all pairs of rectangles that intersect.
(Edge and interior intersections should be reported.)

Note that is is a single-shot, rather than repetitive mode, problem.
(x
il
, y
il
)
(x
il
, y
ir
)
(x
ir
, y
il
)
(x
ir
, y
ir
)
Considered to intersect.
r
i
Intersection
Intersection of rectangles
r
7
r
2
r
8
r
6
r
5
r
4
r
3
r
1
Answer: (r
1
, r
3
) (r
1
, r
8
) (r
3
, r
4
) (r
3
, r
5
) (r
4
, r
5
) (r
7
, r
8
) (r
1
, r
2
) (r
3
, r
9
)
r
9
Intersection
Intersection of rectangles
Brute force algorithm
For every pair (r
i
, r
j
) of rectangles e S, i = j
if (r
i
r
j
= C) then
report (r
i
, r
j
)


Analysis
Preprocessing: None.
Query: O(N
2
); N = (N(N - 1))/2 e O(N
2
).
2
Storage: O(N).
( )
Intersection
Intersection of rectangles
Algorithm using interval trees
Plane sweep algorithm, vertical sweep line from left to right.
Event points are left and right edges of rectangles.
At left edge:
1. Compare rectangle y-interval to active set for overlap.
2. Add rectangle y-interval to active set.
At right edge: Remove rectangle y-interval from active set.
Active set maintained in interval tree.
r
7
r
2
r
8
r
6
r
5
r
4
r
3
r
1
Answer: (r
1
, r
3
) (r
1
, r
8
) (r
3
, r
4
) (r
3
, r
5
) (r
4
, r
5
) (r
7
, r
8
) (r
1
, r
2
) (r
3
, r
9
)
r
9
Intersection
Intersection of rectangles
N, N, what is N?
N rectangles in S s 4N distinct coordinates for vertices:
x
il
, x
ir
, y
il
, y
ir
for 1 s i s N.
Assume x- and y-coordinates are normalized together as [1,4N].
Interval tree T(l,r) is built for scope interval [0,2
k
].
4N +1 4N 2
k
0 1
Smallest power of 2 2
k
> 4N + 1
Right end of interval tree scope interval
Largest (normalized) coordinate
Smallest (normalized) coordinate
Left end of interval tree scope interval
Number of nodes and depth of tree dependent on 2
k
, not N?
Can operation time complexity be expressed as function of N?

2
k-1
s 4N + 1 s 2
k

Upper limit 2
k
by choice (smallest power of 2 2
k
> 4N + 1).


Lower limit 2
k-1
because otherwise 2
k-1
would be upper limit.

2(2
k-1
)

s 2(4N + 1) s 2(2
k
) Multiply through by 2.
2
k
s 8N + 2 s 2
k+1

4N + 1 s 2
k
s 8N + 2 Collect terms.
2
k
e O(N)
Primary interval tree has O(N) nodes and O(log N) levels.
Intersection
Intersection of rectangles
Preprocessing
Normalize x- and y-coordinates of rectangles. O(N log N) for sort.
Construct (empty) interval tree T(0,2
k
). O(N)
(The interval tree is the sweep-line status.)
Initialize event queue Q with rectangle vertical edges:
(x
il
, y
il
, y
ir
, left) and (x
ir
, y
il
, y
ir
, right) for 1 s i s N,
in ascending x order, and for edges with the same x,
left edges ahead of right. O(N), read off after sort.

Query
while (Q = C) do
begin
Get next entry (x
il
, y
il
, y
ir
, t) from Q /* t e {left, right} */
if t = left then
begin /* left edge */
QueryIntervalTree(y
il
, y
ir
, root(T))
InsertIntervalTree(y
il
, y
ir
, root(T))
end
else /* right edge */
DeleteIntervalTree(y
il
, y
ir
, root(T))
end


For a left edge, the query precedes the insert to avoid
reporting overlap with self.
For multiple edges with the same x-coordinate, left edges are
sorted ahead of right so as to find edge-only intersections.
Intersection
Intersection of rectangles
Analysis
Preprocessing: O(N log N); as shown.
Query: O(N log N + K); O(N) edges, O(log N) for each.
Storage: O(N); interval tree O(N) as shown,
event queue also O(N).


Comments
Here Query refers to the process of finding the intersections;
this is a single-shot problem.

O(N log N + K) is lower bound for rectangle intersection problem.
Can be shown by lower bounds proof.

Weve gone to a lot of trouble to improve the time from O(N
2
)
to O(N log N), i.e., interval tree.
Difference between O(N
2
) and O(N log N) is significant for VLSI
applications; e.g. if N = 10
6
, N
2
= 10
12
and N log N = 2 10
7
.
Problem description
Here we consider a category of related intersection construction
problems: Given two (or more) geometric objects, construct
a new object which is their intersection.

The objects dealt with will be polygons, polyhedra, half-planes,
half-spaces, and related types.
The objects will generally be specified by their vertices and
orientations to identify the interior of the object.
(The latter may be given by convention.)
Intersection
Intersection of convex polygons
Applications.

Graphics, constructive solid modeling, linear programming.
Intersection of arbitrary polygons
The intersection of two arbitrary polygons can have quadratic
complexity. The intersection shown below consists of 25 squares.
Intersection
Intersection of convex polygons
Problem definition
For convex (rather than arbitrary) polygons, problem is linear.
CONVEX POLYGON INTERSECTION.
INSTANCE: Convex polygons P and Q, with vertex sets
P = {p
1
, p
2
, ..., p
N
} and Q = {q
1
, q
2
, ..., q
M
} respectively.
QUESTION: Construct polygon R which is their intersection.

The intersection of two convex polygons will have linear
O(N + M) complexity (both the object and the construction process).
By convention, P, Q, and R will be oriented counterclockwise,
so that the interiors of the polygons lie to the left of their edges
(as in Preparata and Laszlo, opposite of ORourke).
Intersection
Intersection of convex polygons
P Q R
p
1
p
2
p
3
p
4
p
5
p
6
p
7
p
8
p
N
q
2
q
M
q
1
q
3
q
4
q
5
q
6
q
7
ORourke-Chien-Olson-Naddor algorithm
This same algorithm described in three sources:
1. ORourke, section 7.4, pp. 243-252, with C code.
2. Preparata, pp. 273-277.
3. Laszlo, section 6.5, pp. 154-162, with C++ code.

Presentation is a synthesis of all three.
Notation of sources inconsistent, Preparata used primarily.
Exposition of sources inconsistent, Laszlo used primarily.

The algorithm is based on three undergraduates homework
assignment solutions in 1982.
Simpler than previously existing linear O(N + M) algorithm,
e.g., Shamos 1978 algorithm.
Intersection
Intersection of convex polygons
Intersection structure
The objective is to form the intersection polygon R of two convex
polygons P and Q. For the moment, assume that the edges
of P and Q intersect non-degenerately; when two edges intersect,
they do so at a single point.

Given this assumption, the boundary of R = P Q consists of
alternating chains of vertices from P and Q. Consecutive chains
are joined at intersection points, where an edge of P intersects
an edge of Q.
Intersection
Intersection of convex polygons
P Q
Chain from Q
Intersection point
Chain from P
In fact, the algorithm will handle degenerate intersections.
Sickles, 1
Regions that are within one polygon, but not both, are called sickles.
Sickles are bounded by two chains (inner and outer) of vertices,
one from each polygon, and terminated by intersection points
at either end.
The boundary of P Q is formed from the inner chains
of the sickles.
Intersection
Intersection of convex polygons
Inner chain
Initial intersection point Outer chain
Terminal intersection point
Sickles, 2
A vertex (of P or Q) belongs to a sickle either if:
1. It lies between the initial and terminal intersection points
on either chain.
2. It is the destination of the edge of the internal chain
containing the terminal intersection point of the sickle.
Note that some vertices may belong to > 1 sickles.
Intersection
Intersection of convex polygons
Also belongs to next sickle
Initial intersection point
Terminal intersection point
Algorithm overview, 1
Define current edges of P and Q:
edge(p
i-1
p
i
) and edge(q
j-1
q
j
), with destinations p
i
and q
j
, respectively.
p
0
= p
N
and q
0
= q
M
, by definition.

IntersectConvexPolygons(P, Q) /* Informal */
begin
i = j = 1 /* Arbitrarily start with vertex 1 of each polygon. */
repeat
if ((w = edge(p
i-1
p
i
) edge(q
j-1
q
j
)) = C) then
add w to R
Select current edge to advance based on configuration.
if (selected edge is on inner chain) then
begin
add selected edge destination to R
increment index of selected edge
end
until iterations > 3(N + M) /* Preparata erroneously says 2 */
if (R = C) then /* Boundaries of P and Q dont intersect */
resolve special cases P _ Q, Q _ P, P Q = C
end
Intersection
Intersection of convex polygons
Algorithm overview, 2
The algorithm has two phases, both handled by same advance rules:
1. Get current edges edge(p
i-1
p
i
) and edge(q
j-1
q
j
) into same sickle.
2. Advance current edges edge(p
i-1
p
i
) and edge(q
j-1
q
j
) together
through each sickle, adding inner chain vertices to R;
and advance them both into the next sickle.
Before either leaves the current sickle for the next sickle
the terminal intersection point will be found.
Intersection
Intersection of convex polygons
Aiming at
Advance rules are used to select the current edge to advance.
The advance rules depend on the notion of aiming at.
The bold arrows aim at edge(q
j-1
q
j
).
Intersection
Intersection of convex polygons
If they are not collinear,
edge(p
i-1
p
i
) aims at edge(q
j-1
q
j
) if either of these conditions hold:
1. edge(p
i-1
p
i
) edge(q
j-1
q
j
) > 0 and
p
i
does not lie to the right of edge(q
j-1
q
j
).
2. edge(p
i-1
p
i
) edge(q
j-1
q
j
) < 0 and
p
i
does not lie to the left of edge(q
j-1
q
j
).

If they are collinear,
edge(p
i-1
p
i
) aims at edge(q
j-1
q
j
) if p
i
does not lie beyond q
j
.
q
i-1
q
i
Advance rules, overall intent
Advance rules are used to select the current edge to advance.

ORourke:
If edge(p
i-1
p
i
) aims at the line containing edge(q
j-1
q
j
)
but does not cross it, we want to advance edge(p
i-1
p
i
) to
close in on a possible intersection point with edge(q
j-1
q
j
).

Laszlo:
The advance rules are designed so that the intersection point
which should be found next is not skipped over. They distinguish
between the current edge which may contain the next intersection
point and the current edge which cannot possibly contain the next
intersection point; the latter edge is advanced.

Preparata:
The idea is to not advance on the boundary (either of P or of Q)
whose current edge may contain a yet to be found intersection
point.
Intersection
Intersection of convex polygons
Advance rules, Preparata and Laszlo: Case (1)
Intersection
Intersection of convex polygons
Laszlo:
Edge(p
i-1
p
i
) and edge(q
j-1
q
j
) aim at each other:
Advance whichever edge is to the right of the other.
(assuming CCW orientation for P and Q).
Assume edge(q
j-1
q
j
) is to the right; then the next intersection point
cannot lie on edge(q
j-1
q
j
) because q
j
is outside the intersection
polygon R.

Preparata:
The choice is arbitrary, and we elect to advance on edge(q
j-1
q
j
).
p
i
q
j
Advance
q
j
p
i
Advance
Preparata Laszlo
Advance rules, Preparata and Laszlo: Case (2)
Intersection
Intersection of convex polygons
Laszlo:
Edge(p
i-1
p
i
) aims at edge(q
j-1
q
j
) but not vice versa:
Add p
i
to R if p
i
is not right of edge(q
j-1
q
j
), then advance p
i
.
Edge(p
i-1
p
i
) cannot contain the next intersection point.
In the figure, p
i
is not right of edge(q
j-1
q
j
), and is added to R.

Preparata:
Advance on edge(p
i-1
p
i
), since the current edge(q
j-1
q
j
) of Q
may contain a yet to be found intersection point.
p
i
q
j
Advance
Preparata Laszlo
p
i
q
j
Advance
Advance rules, Preparata and Laszlo: Case (3)
Intersection
Intersection of convex polygons
Laszlo:
Edge(q
j-1
q
j
) aims at edge(p
i-1
p
i
) but not vice versa:
Add q
j
to R if q
j
is not right of edge(p
i-1
p
i
), then advance q
j
.
Edge(q
j-1
q
j
) cannot contain the next intersection point.
In the figure, q
j
is right of edge(p
i-1
p
i
), and is not added to R.

Preparata:
Advance on edge(q
j-1
q
j
), since the current edge(p
i-1
p
i
) of P
may contain a yet to be found intersection point.
p
i
q
j
Advance
Preparata Laszlo
Advance
p
i
q
j
Advance rules, Preparata and Laszlo: Case (4)
Intersection
Intersection of convex polygons
Laszlo:
Edge(p
i-1
p
i
) and edge(q
j-1
q
j
) do not aim at each other:
Advance whichever edge is to the right of the other.

Preparata:
All intersection points on the current edge(p
i-1
p
i
) of P have already
been found, while the current edge(q
j-1
q
j
) of Q may still contain an
undiscovered intersection point.
p
i
q
j
Advance
Preparata Laszlo
Advance
p
i
q
j
Advance rules, ORourke, 1
The Preparata and Laszlo cases rename the edges so that edge(p
i-1
p
i
)
on polygon P is always to the left/inside, so as to highlight the
four different geometric configurations.

ORourke more exhaustively enumerates the possibilities, where
either of the two edges (edge(p
i-1
p
i
) on P or edge(q
j-1
q
j
) on Q)
can be to the left/inside; resulting in eight rules (ORourke, p. 246).

Each of the four Preparata and Laszlo cases corresponds to two of
the ORourke rules, covering all eight rules.

Unfortunately, when ORourke condenses the eight rules into four,
he combines rules that are from different P&L cases.
Though the resulting four condensed rules are logically correct,
they cannot be easily compared to the four intuitive geometric cases.
Intersection
Intersection of convex polygons
Advance rules, ORourke, 2

A and B are the current edges of P and Q, or vice versa.
a and b are the destination endpoints of A and B, respectively.
H(A) and H(B) are the halfplanes to the left of A and B, respectively.
(This notation is introduced to make ORourke easier to read.)

Rule A B a e H(B) b e H(A) Advance P&L case
------------------------------------------------------------------------------
1 > 0 T T A (2)
2 > 0 T F A or B (1)
3 > 0 F T A (4)
4 > 0 F F B (3)
------------------------------------------------------------------------------
5 < 0 T T B (2)
6 < 0 T F B (4)
7 < 0 F T A or B (1)
8 < 0 F F A (3)
------------------------------------------------------------------------------

Note that the two rules corresponding to a single P&L case
advance opposite edges. This is correct, because the difference
between the two corresponding rules is which edge (A or B) is to the
left/inside.
Intersection
Intersection of convex polygons
Advance rules, ORourke, 3
ORourke condenses the eight rules into four condensed rules,
taking advantage of dont care cases,
in the process mixing the Preparata and Laszlo cases.

Rules A B Halfplane Advance P&L cases
------------------------------------------------------------------------------
1 & 3 > 0 b e H(A) A (2) & (4)
2 & 4 > 0 b e H(A) B (1) & (3)
5 & 6 < 0 a e H(B) B (2) & (4)
7 & 8 < 0 a e H(B) B (1) & (3)
------------------------------------------------------------------------------


Algorithm details
See ORourke (section 7.4, pp. 243-252, C code)
or Laszlo (section 6.5, pp. 154-162, C++ code).
Intersection
Intersection of convex polygons
Intersection
Intersection of convex polygons
7
1
4 5
8
2 3
6
9
Intersection
Intersection of convex polygons
P Q
17 16
13 14 15
12 11 10
Proof of correctness, 1
The proof of correctness is simplified by a notational shorthand:

Polygon Current edge Shorthand edge name
P edge(p
i-1
p
i
) p
Q edge(q
j-1
q
j
) q
Intersection
Intersection of convex polygons
Recall that the algorithm has two phases:
1. Get current edges p and q into same sickle.
2. Advance current edges p and q together through each sickle,
adding inner chain vertices to R, and into the next.

The proof highlights what is most remarkable about the
algorithm: the same advance rules or cases work for both phases.

Correctness follows from two assertions:
1. If current edges p and q belong to the same sickle, then the
next intersection point, at which the sickle terminates,
will be found next.
2. If the boundaries of P and Q intersect, current edges p and q
will cross at some intersection point after no more than
2(N + M) iterations (advances).

Assertion 1 applies to phase 2, and assertion 2 to phase 1.
Intersection
Intersection of convex polygons
Proof of correctness, 2
Proof of assertion 1:
Suppose p and q belong to the same sickle and q is advanced to the
next intersection point, before p. It must be shown that q will then
remain stationary while p is advanced to the intersection point to
complete the sickle. Two cases can occur:
Case 1 (p outside q).
q will remain fixed while p is
advanced by > 0 applications
each of advance case (4),
then (1), then (2).
Case 2 (q outside p).
q will remain fixed while p is
advanced by > 0 applications
of advance case (2).
q
p
4
4
4
4
1
1
2
2
q
p
2
2
2
2
In the symmetric situation, where p reaches the next intersection
point first, q is advanced to that intersection point by the same
reasoning, with advance case (2) replaced by advance case (3).
Intersection
Intersection of convex polygons
Proof of correctness, 3
Proof of assertion 2:
Assume that the boundaries of P and Q intersect.
After (N + M) interations, either p or q must have completely
traversed the boundary of its polygon; assume p has.
During that traversal, p must have been positioned so that it
contained an intersection point where q crosses p from outside
to inside R.
This must occur because the intersection points occur in pairs
and they alternate in direction of crossing.

Partition the boundary of Q into two chains, C
r
and C
s
.
C
r
terminates in edge q
r
, the edge of Q that crosses p going into R.
C
s
terminates in edge q
s
, whose destination vertex lies to the
left of and is farthest from the line determined by p.
p
q
r
q
s
C
s
C
r
P
Q
R
Intersection
Intersection of convex polygons
Proof of correctness, 4
When p is positioned as defined, q may be either in C
r
or C
s
.
These two cases are considered separately.

Case 1 (q eC
r
).
p will remain fixed while q is advanced by > 0 applications each of
advance cases (3), then (4), then (1), then (3), when the intersection
point is found.
p
q
r
q
s
C
s
C
r
P
Q
R
3
3
3
4
4
4
1
3
Intersection
Intersection of convex polygons
Proof of correctness, 5
Case 2 (q eC
s
).
q will remain fixed while p is advanced by > 0 applications each of
advance case (2), then (4), then (1), then (2), when p will be inside
q. Then both p and q may be advanced, but q cannot be advanced
beyond its next intersection point until its previous intersection
points is first reached by p (if it hasnt done so already).

Thus p and q end up in the same sickle, whereafter assertion 1
assures correctness.
p
q
r
q
s
C
s
C
r
P
Q
R
Analysis
s 2(N + M) iterations (advances) suffice to find the first intersection
point and get p and q into the same sickle.
Preparata erroneously says s (N + M).
Thereafter, s (N +M) additional iterations will produce R.
The algorithm requires O(N +M), i.e. linear time.
Intersection
Intersection of convex polygons
Problem definition
CONVEX POLYHEDRA INTERSECTION.
INSTANCE. Convex polyhedra P
0
and P
1
in E
3
.
QUESTION. Construct polyhedron P
0
P
1
.

P
0
and P
1
are given as boundary representations (vertex and edge),
as will the result P
0
P
1
.
Intersection
Intersection of convex polyhedra
Source
Hertel, S., Mntyl, M., Mehlhorn, K., and Neivergelt, J. (1984).
Space Sweep Solves Intersection of Convex Polyhedra,
Acta Informatica, Vol. 21, 1984, pp. 501-519.
(Available in UCF library on microfilm, call number QA76.A265.)

Alternate references
Preparata, Chapter 7 Notes and Comments, p. 321.
(Brief description.)

Hertel, S. (1984). Sweep-Algorithmen fr Polygone und Polyeder,
Univ. des Saarlandes, Saarbrcken Germany, 1984.
(Dissertation.)
Intersection
Intersection of convex polyhedra
Preliminaries
The edge set E of the convex polyhedron P
0
P
1
consists of:
1. set E
1
of segments on the surface of both polyhedra P
0
P
1

2. set E
2
of segments that are edges (or part of edges) of only
one of the polyhedra.
E = E
1
E
2
and E
1
E
2
= C.
E is the edge set of the intersection.
Intersection
Intersection of convex polyhedra
E
2
E
1
P
0
P
1
Definitions
Assume all faces of the polyhedra are triangulated from their
respective point of minimal x-coordinate by improper edges.
A proper edge is an edge that was part of the initial polyhedra.
An improper edge is one added for triangulation purposes.
A face is a bounding polygon of one of the polyhedra without
considering the improper edges. A bounding triangle is one of
the component triangles of a (triangulated) face with considering
the improper edges.

Intermediate problem
Problem ICP'. Given two convex polyhedra P
0
and P
1

with a total of N vertices, compute a set of intersection points
of proper edges of P
0
with bounding triangles of P
1
.
This set must contain at least one point of each connected
component of E
1
_ P
0
P
1
.

Lemma. A solution to problem ICP' allows the computation of
(a) P
0
P
1
(b) P
0
P
1
or (c) P
0
\ P
1
in O(N) time.

\ is set difference, i.e., e P
0
and e P
1

Intersection
Intersection of convex polyhedra
Overall algorithm overview

Two convex polyhedra P
0
and P
1
.


Space sweep algorithm O(N log N)


A solution to problem ICP' (i.e. set S that includes at least one point
of each connected component of E
1
_ P
0
P
1
.


Graph exploration algorithm O(N)


Any of: (a) P
0
P
1
(b) P
0
P
1
or (c) P
0
\ P
1
.
Intersection
Intersection of convex polyhedra
Prongs, crowns, and edge classifications
The set of edges of one polyhedron intersected by the sweep plane
forms a cycle (a circular sequence, not a graph cycle)
whose neighbor edges bound the same bounding triangle
of the polyhedron.

Let P
i
, i = 0,1 be one of the polyhedra. Let e
j
, 0 s j < N
i
, be the
cyclically ordered sequence of edges intersected by the sweep
plane. A prong is the portion of a bounding triangle bounded
by two consecutive edges e
j
and e
(j+1) mod Ni
, the sweep plane,
and possibly by a third edge of the bounding triangle.

The cyclically ordered set of prongs for P
i
forms the crown C
i
.
Intersection
Intersection of convex polyhedra
Edge classifications: b = base, f = forward, p = prong.
Sweep plane Sweep direction
b
b
b
b b
b
f
f
f
f
f
f
f
f
p
p
p
p
p
Cap not part of crown
Radial representation of a crown
Sweep paradigm uses two data structures:
1. Event queue; Vertices of the two polyhedra.
Ordered by ascending x-coordinate.
2. Sweep plane status; Crowns C
0
and C
1
.
Radial representation, stored in binary tree ordered on o.
Provides needed O(log N) access.
Intersection
Intersection of convex polyhedra
f
f
f
f
f
f
f
p
p
p
p
p
p
b
b
b
b
b
b
o
1
o
6,7
o
2
o
3
o
4
o
5
o
1 o
2
o
3,4
o
5
o
6
o
7
z-axis
x-axis
y-axis
Space sweep algorithm overview
Two crowns C
0
and C
1
are maintained, one for each
polyhedron P
0
and P
1
.
The events are the N = N
0
+ N
1
vertices of both polyhedra.
For each event (vertex), update the crown to which the vertex
belongs and find the intersections of the new crown with the
opposite crown.

Observe that only edges and faces that start at the event vertex
need to be tested for intersection; nothing else has changed.

For event vertex p e P
i
:
1. Update crown C
i
with p.
2. Intersect all proper edges of P
i
starting at p with
opposite crown C
1-i
.
3. Intersect a forward edge of opposite crown C
1-i
with all faces F
that start at p.

This procedure suffices to find at least one point of each component
of E
1
(i.e. a solution to problem ICP').
Intersection
Intersection of convex polyhedra
Event algorithm

1 procedure TRANSITION(p, i) /* p is vertex, i is polyhedron */
2 begin
3 update crown C
i
of polyhedron P
i

4 if (exactly one edge e of P
i
starts at p) then
5 begin
6 intersect e with crown C
1-i
of P
1-i

7 add all intersection points found to S
8 end
9 else
10 begin
11 for every face F of P
i
starting at p
12 begin
13 intersect the starting proper edges of F
with crown C
1-i

14 add all intersection points found to S
15 if (no intersection points found for F) then
16 begin
17 choose an arbitrary proper forward edge f
of crown C
1-i

18 intersect f with F
19 add any intersection found to S
20 end
21 end
22 end
23 end
Intersection
Intersection of convex polyhedra
Transition algorithm example, line 4
exactly one edge e of P
i
starts at p
Intersection
Intersection of convex polyhedra
Sweep plane (seen edge on)
p
Face F of P
i
Proper edge
Improper edge
e
Edge e is the only edge added to C
i
by this transition.
Only e needs to be tested for intersection points with C
1-i
.
x
z
y
Transition algorithm example, line 11
for every face F of P
i
starting at p
There may be several faces starting at p, each possibly consisting
of several prongs.
Intersection
Intersection of convex polyhedra
Sweep plane (seen edge on)
p
Face F
1
of P
i
Proper edge
Improper edge
Two faces comprised of a total of 5 prongs start at p.
x
z
y
Face F
2
of P
i
f
1
f
1
f
2
f
3
f
4
f
5
f
6
Transition algorithm example, line 13
intersect the starting proper edges of F with crown C
1-i

f
1
, f
3
, and f
6
are the starting proper edges for p.
Recall that p is from polyhedron P
i
, so C
1-i
is the opposite crown.
Intersection
Intersection of convex polyhedra
Sweep plane (seen edge on)
p
Face F
1
of P
i
Proper edge
Improper edge
x
z
y
Face F
2
of P
i
f
1
f
1
f
2
f
3
f
4
f
5
f
6
Transition algorithm example, line 15
no intersections found
Even if no edge of P
i
starting at p intersects C
1-i
, it is still possible
that C
1-i
may intersect a face starting at p; see the figure.
Intersection
Intersection of convex polyhedra
Face F

of P
i
e
f
g
C
1-i
Proper edges of F starting at p
p
e, f, and g are forward edges of C
1-i
.
The algorithm lines 15-20 take care of this case.
Intersection
Proof of correctness overview, 1
Clearly, the TRANSITION algorithm finds intersection points.
It must be shown that the algorithm will find at least one such
point in each connected component of E
1
.

Let K be any component of E
1
; the proof will show that a vertex
of K is found by TRANSITION.

Let v be the vertex of K with minimal x-coordinate.
v is the intersection point of an edge e e polyhedron P
i

and a face F e polyhedron P
1-i
.
TRANSITION will either find v or it will not;
if it does, K is done, because a vertex of E
1
is found.
Intersection
Intersection of convex polyhedra
Proof of correctness overview, 2
If v is not found by TRANSITION, then e must start before
F in sweep order (i.e., before p, the transition vertex).
At the event when the sweep encounters the start
vertex p of F, e is a forward edge of crown C
i
of P
i
.
Intersection
Intersection of convex polyhedra
x
z
y
v eP
i
p eP
1-i
e
F e P
1-i
G e C
i
Conceptually trace the portion of K contained in F and C
i
.
Two cases may arise:
1. Not all of K is in F and C
i
.
2. All of K is in F and C
i
.
Proof of correctness, Case 1
Case 1: Not all of K is in F and C
i
.
While tracing K, we reach either a bounding edge e of F (subcase a)
or a prong edge e of C
i
(subcase b). Because v has the minimal
x-coordinate of K, we do not leave C
i
via a base edge.
Intersection
Intersection of convex polyhedra
x
z
y
v eP
i
p eP
1-i
e
F e P
1-i
G e C
i
e
e
F G
b
o
u
n
d
i
n
g

e
d
g
e

p
r
o
n
g

e
d
g
e

Proof of correctness, Case 1, subcase a
Intersection
Intersection of convex polyhedra
Subcase a: Tracing K reaches bounding edge e of F.
Bounding edge e of F, to which K is traced, intersects a prong G
of C
i
(because e e C
i
intersects F eC
1-i
).
Then either e G, which is a vertex of K, was found while
processing p, or it will be found when the starting point of e is
processed (because G is still a prong of C
i
at that time).
x
z
y
v eP
i
p eP
1-i
e
F e P
1-i
G e C
i
e
F G
e G
e
Proof of correctness, Case 1, subcase b
Intersection
Intersection of convex polyhedra
Subcase b: Tracing K reaches prong edge e of C
i
.
Because of the triangulation chosen, e being a prong edge implies
that it is a proper edge.
F will still be part of C
1-i
when the starting point of e is the event.
Then e F, a vertex of K, will be found at that event.
x
z
y
v eP
i
p eP
1-i
e
F e P
1-i
G e C
i
e
e F
Proof of correctness, Case 2
Case 2: All of K is in F and C
i
.

Intersection
Intersection of convex polyhedra
Forward edge e starts before F and e does not intersect a bounding
edge of F, so e intersects the interior of F.
The intersection of F and the two prongs of C
i
neighboring e are
completely contained in F and the forward edges of those prongs
again intersect the interior of F because K is within F and G.
This argument propagates around C
i
; thus K is a closed curve in F
through all prongs of C
i
and intersecting all forward edges of C
i
.
Thus a vertex of K will be found in lines 15-20 of TRANSITION.
Face F

of P
1-i
e
C
i
p
Intersection
v
earlier C
i-1

Graph exploration algorithm overview
The graph exploration algorithm constructs a boundary
representation of P
0
P
1
from S, a answer to problem ICP.
It proceeds as follows:

(0) Result set S from problem ICP includes at least one point
of each connected component of E
1
_ P
0
P
1
.
(1) For a point x e S, find all edges in E
1
and candidate edges
for E
2
incident to x. O(N)
(2) Explore/expand the connected component graph by
extending the edges found in step (1) by applying the
procedures of step (1) to the endpoints of the new edges.
Intersection
Intersection of convex polyhedra
Graph exploration cases
We will start with some point in S and from it extend S
to complete E; let that starting point be x.

Let x e S be a point that is the intersection of a proper edge e
separating two bounding triangles F and F of P
0
with a bounding
triangle of P
1
. Such a point x exists if P
i
P
i-1
= C.

Step (1) will construct all edges of E
1
incident to x.

There are three cases for the position of x:
1. x is no polyhedron vertex, and lies in the interior of bounding
triangle F of P
1
.
2. x is the intersection of two edges, but not a polyhedron vertex.
3. x is a vertex of P
0
and/or P
1
.
Intersection
Intersection of convex polyhedra
Graph exploration cases, case 1
Description:
x is not a polyhedron vertex, and lies in the interior of a bounding
triangle F of P
1
.

Processing:
1. Intersect F with all bounding triangles of P
0
incident to x,
and add the endpoints of the segments of intersection
to the list of points to expand.
Intersection
Intersection of convex polyhedra
P
0
P
1
F
F
F
e
x
Graph exploration cases, case 2
Description:
x is the intersection of two edges, but not a polyhedron vertex.

Processing:
1. Intersect F with all bounding triangles of P
0
incident to x.
2. Resolve coplanarities of F and F with F and F
by computing the intersection polygon of the coplanar faces
treating it as a single face.
Intersection
Intersection of convex polyhedra
P
0
P
1
F
F
F
e
x
F
f
Graph exploration cases, case 3
Description:
x is a vertex of P
0
and/or P
1
.

Processing:
1. Subcase 1: x is in interior of bounding triangle of P
1
.
Intersect F with all bounding triangles of P
0
incident to x.
2. Subcase 2: x is on an edge of P
1
.
As with Subcase 1, handling coplanarities.
3. Subcase 3: x is on a vertex of P
1
.
Find plane D intersecting all edge of P
0
incident to x.
Compute (P
0
D) (P
1
D), both convex polygons.
Infer structure of E
1
around x from resulting polygon.
Intersection
Intersection of convex polyhedra
P
1
f
P
0
F
F
e
x
F
F
Analysis
1. Space sweep O(N log N)
Sort of events O(N log N)
Total time updating crowns O(N log N)
O(N) events, O(log N) each
Total time finding intersections O(N log N)
O(N) events, O(log N) each
2. Graph exploration O(N)
Overall worst case time complexity O(N log N)
Intersection
Intersection of convex polyhedra

You might also like