intersection introduction
Download
Skip this Video
Download Presentation
Intersection Introduction

Loading in 2 Seconds...

play fullscreen
1 / 89

Intersection Introduction - PowerPoint PPT Presentation


  • 376 Views
  • Uploaded on

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 6. r 7. r 5. r 4. r 8. r 3. r 2. r 1.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Intersection Introduction' - avedis


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
intersection introduction
IntersectionIntroduction

Intersection example 1

Given a set of N axis-parallel rectangles in the plane, report all

intersecting pairs. (Intersect  share at least one point.)

r6

r7

r5

r4

r8

r3

r2

r1

Answer: (r1, r3) (r1, r8) (r3, r4) (r3, r5) (r4, r5) (r7, r8)

slide2

IntersectionIntroduction

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 introduction3
IntersectionIntroduction

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 theirintersections.

Construction problem

Given a data set of N geometric objects, construct a new object

which is their intersection.

intersection introduction4
IntersectionIntroduction

Applications

Domain: GraphicsProblem: Hidden-line and hidden surface removalApproach: Intersection of two polygonsType: Construction

Domain: Pattern recognitionProblem: Finding a linear classifier between two sets of pointsApproach: Intersection of convex hullsType: Test

Domain: VLSI designProblem: Component overlap detectionApproach: Intersection of rectanglesType: Pairwise

intersection intersection of line segments
IntersectionIntersection of line segments

Problem definition

Given N line segments in the plane, report all their points of

intersection (pairwise).

LINE SEGMENT INTERSECTION (LSI).

INSTANCE: Set S = {s1, s2, ..., sN} of line segments in the plane.

For 1 iN, si = (ei1, ei2) (endpoints of the segments),

and for 1 j 2, eij = (xij, yij) (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 brute force algorithm
IntersectionIntersection 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(N2); there are N(N - 1) / 2 O(N2) pairs,

each requiring a constant time test.

Storage: O(N); for S.

Can we do better?

intersection intersection of line segments shamos hoey algorithm

s2

s1

s3

s4

v

u

IntersectionIntersection 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 s1 is above segment s2 at x, written s1 >xs2,

if s1 and s2 are comparable at x and the y-coordinate of the

intersection of s1 with the vertical line through x is greater

than the y-coordinate of the intersection of s2 with that line.

In the example, s2 >us4, s1 >vs2, s2 >vs4, and s1 >vs4.

Segment s3 is not comparable with any other segment.

intersection intersection of line segments shamos hoey algorithm8
IntersectionIntersection of line segments, Shamos-Hoey algorithm

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 s1and s2 is encountered.

Segments s1and s2, exchange places in the ordering.

intersection intersection of line segments shamos hoey algorithm9
IntersectionIntersection of line segments, Shamos-Hoey algorithm

Algorithm idea

s1

s2

x

Crucial observation: For two segments s1and s2 to intersect,

there must be some x for which s1and s2 are consecutivein 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

intersection intersection of line segments shamos hoey algorithm10
IntersectionIntersection 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 setof currently comparable segments changes, the data structure forL 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) canperform all of these operations in O(log N) time (or better).

intersection intersection of line segments shamos hoey algorithm11
IntersectionIntersection of line segments, Shamos-Hoey algorithm

Event-point schedule

As the sweep-line is swept from left to right, the set of the currentlycomparable segments and/or their ordering by the relation >xchanges 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) canperform all of these operations in O(log N) time.

intersection intersection of line segments shamos hoey algorithm12
IntersectionIntersection 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 = ; /* A is an internal working queue. */ 5 while (E) 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 s1 = ABOVE(s, L); 13 s2 = BELOW(s, L):

14 if (s1 intersects s) then add (s1, s) to A; 15 if (s2 intersects s) then add (s2, 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 s1 = ABOVE(s, L); 21 s2 = BELOW(s, L):

22 if (s1 intersects s2 to the right of p) then add (s1, s2) to A; 23 DELETE(s, L); 24 end 25 else /* p is an intersection */ 26 begin 27 s1, s2 = segments that intersect at p, with s1 above s2 to the left of p. 28 s3 = ABOVE(s1 , L); 29 s4 = BELOW(s2 , L):

30 if (s3 intersects s2) then add (s3, s2) to A;

31 if (s1 intersects s4) then add (s1, s4) to A;

32 Interchange s1 and s2 in L; 33 end

Algorithm continued on next page.

intersection intersection of line segments shamos hoey algorithm13
IntersectionIntersection of line segments, Shamos-Hoey algorithm

Algorithm, 2

34 /* The detected intersections must now be processed */ 35 while (A) do 36 begin

37 (s1, s2) = get and remove first element of A;

38 x = x-coordinate of intersection point of s1 and s2;

39 if (MEMBER(x, E) = FALSE) then 40 begin 41 report (s1, s2); 42 INSERT(x, E); 43 end 44 end

45 end 46 end

The “while (A) do” block (lines 35-44) is within the “while (E) do”begin-end block (lines 5-45).

intersection intersection of line segments shamos hoey algorithm14
IntersectionIntersection 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 algorithm15
IntersectionIntersection 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 arestored 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 interval trees
IntersectionInterval trees

Notation

The notation used here for interval trees is not consistent with eitherPreparata (pp. 359-363) or Ullman (pp. 385-393), which areunfortunately 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 onthe 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 multiplesof 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 havebeen normalized to [1, N] and the tree has been built for scopeinterval [0, 2k], where N + 1 2k.

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 trees17
IntersectionInterval 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)  { active, inactive } = active iff

(L(v)  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 bestored at the highest node where B(v) < bM(v) e < E(v).

Operations preview.

The interval tree supports interval insert, delete, and queryoperations, 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 trees18
IntersectionInterval trees

Example

The structure of the interval tree T(0,16) is shown;

0 = 0 · 24, 16 = 1 · 24.

Each node is labeled with B(v), E(v) of its scope interval.

0,16

[7,12]

0,8

8,16

[0,4]

[1,6]

0,4

4,8

8,12

12,16

[9,10]

[6,7]

[13,15]

[9,11]

0,2

2,4

4,6

6,8

8,10

10,12

12,14

14,16

[1,1]

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.

intersection interval trees19

0,16

[7,12]

0,8

8,16

0,4

4,8

8,12

12,16

[6,7]

[9,10]

[13,15]

[9,11]

L

R

[0,4]

[1,6]

[1,6]

[0,4]

IntersectionInterval 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.

ascending left

descending right

L(v) and R(v) are threaded to allow ordered scans of the data intervals

contained therein without requiring a binary search.

intersection interval trees20

0,16

[7,12]

0,8

8,16

0,4

4,8

8,12

12,16

[9,10]

[6,7]

[13,15]

[9,11]

IntersectionInterval 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.

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 aredata 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 lessthan half the number of non-empty active nodes.

intersection interval trees21
IntersectionInterval trees

Insertion

The interval tree T(l,r) supports insertions and deletions of

data intervals [b, e] with endpoints l < b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M(v) 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M(v) 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 trees22
IntersectionInterval 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M(v) 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 trees23
IntersectionInterval 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M(v) 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 */ begini = 1 while (the ith interval [li, ri] in L(v) has lie) do begin report [li, ri] i++ end QueryIntervalTree(b, e, Lptr(v)) end

else /* M(v) b, i.e. query interval to right of midpoint */ begini = 1 while (the ith interval [li, ri] in R(v) has rib) do begin report [li, ri] i++ end QueryIntervalTree(b, e, Rptr(v)) end endend

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 trees24
IntersectionInterval trees

Analysis preliminaries

It must be shown that the query algorithm has time complexity

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 trees25

b

e

b

e

A

or

B(v)

M(v)

E(v)

B(v)

M(v)

E(v)

b

e

B

B(v)

M(v)

E(v)

b

e

b

e

C1

or

B(v)

M(v)

E(v)

B(v)

M(v)

E(v)

b

e

e

b

C2

or

B(v)

M(v)

E(v)

B(v)

M(v)

E(v)

b

e

D

B(v)

M(v)

E(v)

IntersectionInterval 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 offive classes:

intersection interval trees26
IntersectionInterval 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.

ClassClass of Left ChildClass of Right Child A A or B* No intersection* B C1 or C2 C1 or C2 C1 D C1 or C2 C2 C1 or C2* No intersection* D D D

* These entries assume left overlap; they are reversed forright overlap.

intersection interval trees27

D

D

IntersectionInterval 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

C

C

C

C = C1 or C2

Once a class D node is reached, all data intervals in the subtreeoverlap the query interval and will be reported.

intersection interval trees28
IntersectionInterval trees

Traversal length, 1

The overlap transition rules imply a maximum “fan out” of the

tree searched in a query traversal.

Number ofNumber of non-DClassChild Nodes to SearchChild Nodes to Search A 1 1 B 1 or 2 1 or 2 C1 or C2 1 or 2 1 D 2 0

No A, B, or C (C1 or C2) 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  2 log N.The query time complexity, neglecting class D nodes, is O(log N).

But what about class D nodes?

intersection interval trees29
IntersectionInterval 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 O(K).

This is not quite right because some active class D nodes mighthave empty data interval lists; they are active because both subtreesare 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 O(K).

Overall query time complexity

O(log N + K); O(log N) to traverse the class A, B, C1, and C2 nodes,

and O(K) to traverse the class D nodes and report overlappingintervals.

intersection interval trees30
IntersectionInterval trees

Storage analysis

Assume N data intervals.

 2N distinct endpoints after normalization.

2k-1  2N  2kUpper limit 2k because for T(l,r) r must be a multiple of a power of 2.Lower limit 2k-1 because otherwise 2k-1 would be r.2k-1) 2(2N)  2(2k) Multiply through by 2.

2k  4N 2k+1

2N 2k  4N Collect terms.2k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 tothe 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 trees31
IntersectionInterval 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 treeQuery: 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

(xil, yir)

(xir, yir)

ri

(xil, yil)

(xir, yil)

Considered to intersect.

IntersectionIntersection of rectangles

Problem definition

RECTANGLE INTERSECTION

INSTANCE: Set S = {r1, r2, ..., rN} of rectangles in the plane.

For 1 iN, ri = ((xil, yil), (xil, yir), (xir, yil), (xir, yir)).

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.

intersection intersection of rectangles33

r6

r7

r5

r4

r8

r3

r2

r1

r9

Answer: (r1, r3) (r1, r8) (r3, r4) (r3, r5) (r4, r5) (r7, r8) (r1, r2) (r3, r9)

IntersectionIntersection of rectangles
intersection intersection of rectangles34
IntersectionIntersection of rectangles

Brute force algorithm

For every pair (ri, rj) of rectangles S, ij

if (rirj ) then

report (ri, rj)

Analysis

Preprocessing: None.

Query: O(N2); N = (N(N - 1))/2  O(N2).

2Storage: O(N).

( )

intersection intersection of rectangles35

r6

r7

r5

r4

r8

r3

r2

r1

r9

Answer: (r1, r3) (r1, r8) (r3, r4) (r3, r5) (r4, r5) (r7, r8) (r1, r2) (r3, r9)

IntersectionIntersection 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.

intersection intersection of rectangles36
IntersectionIntersection of rectangles

N, N, what is N?

N rectangles in S 4N distinct coordinates for vertices:

xil, xir, yil, yir for 1 iN.

Assume x- and y-coordinates are normalized together as [1,4N].

Interval tree T(l,r) is built for scope interval [0,2k].

0

1

4N

4N + 1

2k

Smallest (normalized) coordinate

Smallest power of 2  2k 4N + 1

Left end of interval tree scope interval

Right end of interval tree scope interval

Largest (normalized) coordinate

Number of nodes and depth of tree dependent on 2k, not N?

Can operation time complexity be expressed as function of N?

2k-1  4N + 1  2kUpper limit 2kby choice (smallest power of 2  2k 4N + 1).Lower limit 2k-1 because otherwise 2k-1 would be upper limit.2k-1) 2(4N + 1)  2(2k) Multiply through by 2.

2k 8N + 2  2k+1

4N + 1  2k 8N + 2 Collect terms.2kO(N)

Primary interval tree has O(N) nodes and O(log N) levels.

intersection intersection of rectangles37
IntersectionIntersection of rectangles

Preprocessing

Normalize x- and y-coordinates of rectangles. O(N log N) for sort.Construct (empty) interval tree T(0,2k). O(N)

(The interval tree is the sweep-line status.)

Initialize event queue Q with rectangle vertical edges:(xil, yil, yir, left) and (xir, yil, yir, right) for 1 i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) dobegin Get next entry (xil, yil, yir, t) from Q /* t {left, right} */ if t = left then begin /* left edge */

QueryIntervalTree(yil, yir, root(T)) InsertIntervalTree(yil, yir, root(T)) end else /* right edge */

DeleteIntervalTree(yil, yir, 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 aresorted ahead of right so as to find edge-only intersections.

intersection intersection of rectangles38
IntersectionIntersection 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.

We’ve gone to a lot of trouble to improve the time from O(N2)

to O(N log N), i.e., interval tree.

Difference between O(N2) and O(N log N) is significant for VLSI

applications; e.g. if N = 106, N2 = 1012 and N log N = 2  107.

intersection intersection of convex polygons
IntersectionIntersection of convex polygons

Problem descriptionHere we consider a category of related intersection constructionproblems: Given two (or more) geometric objects, constructa 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.)

Applications.

Graphics, constructive solid modeling, linear programming.

intersection intersection of convex polygons40
IntersectionIntersection of convex polygons

Intersection of arbitrary polygonsThe intersection of two arbitrary polygons can have quadratic

complexity. The intersection shown below consists of 25 squares.

intersection intersection of convex polygons41

q1

p1

pN

p2

q2

qM

p3

q3

p8

P

R

Q

q4

p4

q7

p7

q5

p5

q6

p6

IntersectionIntersection of convex polygons

Problem definitionFor convex (rather than arbitrary) polygons, problem is linear.

CONVEX POLYGON INTERSECTION.

INSTANCE: Convex polygons P and Q, with vertex sets

P = {p1, p2, ..., pN} and Q = {q1, q2, ..., qM} 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 O’Rourke).

intersection intersection of convex polygons42
IntersectionIntersection of convex polygons

O’Rourke-Chien-Olson-Naddor algorithmThis same algorithm described in three sources:1. O’Rourke, 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 polygons43
IntersectionIntersection of convex polygons

Intersection structureThe 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 point

P

Q

Chain from P

Chain from Q

In fact, the algorithm will handle degenerate intersections.

intersection intersection of convex polygons44
IntersectionIntersection of convex polygons

Sickles, 1Regions 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 pointsat either end.

The boundary of PQ is formed from the inner chains

of the sickles.

Outer chain

Initial intersection point

Inner chain

Terminal intersection point

intersection intersection of convex polygons45
IntersectionIntersection of convex polygons

Sickles, 2A 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.

Initial intersection point

Terminal intersection point

Also belongs to next sickle

intersection intersection of convex polygons46
IntersectionIntersection of convex polygons

Algorithm overview, 1Define current edges of P and Q:

edge(pi-1pi) and edge(qj-1qj), with destinations pi and qj, respectively.

p0 = pN and q0 = qM, by definition.

IntersectConvexPolygons(P, Q) /* Informal */

begin

i = j = 1 /* Arbitrarily start with vertex 1 of each polygon. */

repeat

if ((w = edge(pi-1pi)  edge(qj-1qj)) ) then add w to RSelect 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 = ) then /* Boundaries of P and Q don’t intersect */ resolve special cases PQ, QP, PQ = 

end

intersection intersection of convex polygons47
IntersectionIntersection of convex polygons

Algorithm overview, 2The algorithm has two phases, both handled by same advance rules:

1. Get current edges edge(pi-1pi) and edge(qj-1qj) into same sickle.2. Advance current edges edge(pi-1pi) and edge(qj-1qj) 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 polygons48
IntersectionIntersection of convex polygons

Aiming atAdvance 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(qj-1qj).

qi-1

qi

If they are not collinear,edge(pi-1pi) aims at edge(qj-1qj) if either of these conditions hold:

1. edge(pi-1pi)  edge(qj-1qj)  0 andpi does not lie to the right of edge(qj-1qj).2. edge(pi-1pi)  edge(qj-1qj) < 0 andpi does not lie to the left of edge(qj-1qj).

If they are collinear,edge(pi-1pi) aims at edge(qj-1qj) if pi does not lie beyond qj.

intersection intersection of convex polygons49
IntersectionIntersection of convex polygons

Advance rules, overall intentAdvance rules are used to select the current edge to advance.

O’Rourke:

‘If edge(pi-1pi) aims at the line containing edge(qj-1qj)

but does not cross it, we want to advance edge(pi-1pi) to

close in on a possible intersection point with edge(qj-1qj).’

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 intersectionpoint.’

intersection intersection of convex polygons50
IntersectionIntersection of convex polygons

Advance rules, Preparata and Laszlo: Case (1)

qj

pi

qj

pi

Advance

Advance

Preparata

Laszlo

Laszlo:

Edge(pi-1pi) and edge(qj-1qj) aim at each other:Advance whichever edge is to the right of the other.

(assuming CCW orientation for P and Q).Assume edge(qj-1qj) is to the right; then the next intersection pointcannot lie on edge(qj-1qj) because qj is outside the intersectionpolygon R.

Preparata:

The choice is arbitrary, and we elect to advance on edge(qj-1qj).

intersection intersection of convex polygons51

qj

pi

IntersectionIntersection of convex polygons

Advance rules, Preparata and Laszlo: Case (2)

qj

Advance

pi

Advance

Preparata

Laszlo

Laszlo:

Edge(pi-1pi) aims at edge(qj-1qj) but not vice versa:Add pi to R if pi is not right of edge(qj-1qj), then advance pi.

Edge(pi-1pi) cannot contain the next intersection point.

In the figure, piis not right of edge(qj-1qj), and is added to R.

Preparata:

Advance on edge(pi-1pi), since the current edge(qj-1qj) of Qmay contain a yet to be found intersection point.

intersection intersection of convex polygons52
IntersectionIntersection of convex polygons

Advance rules, Preparata and Laszlo: Case (3)

Advance

pi

pi

qj

qj

Advance

Preparata

Laszlo

Laszlo:

Edge(qj-1qj) aims at edge(pi-1pi) but not vice versa:Add qj to R if qj is not right of edge(pi-1pi), then advance qj.

Edge(qj-1qj) cannot contain the next intersection point.

In the figure, qjis right of edge(pi-1pi), and is not added to R.

Preparata:

Advance on edge(qj-1qj), since the current edge(pi-1pi) of Pmay contain a yet to be found intersection point.

intersection intersection of convex polygons53

qj

pi

qj

Advance

pi

Advance

Preparata

Laszlo

IntersectionIntersection of convex polygons

Advance rules, Preparata and Laszlo: Case (4)

Laszlo:

Edge(pi-1pi) and edge(qj-1qj) do not aim at each other:Advance whichever edge is to the right of the other.

Preparata:

All intersection points on the current edge(pi-1pi) of P have alreadybeen found, while the current edge(qj-1qj) of Q may still contain anundiscovered intersection point.

intersection intersection of convex polygons54
IntersectionIntersection of convex polygons

Advance rules, O’Rourke, 1

The Preparata and Laszlo cases rename the edges so that edge(pi-1pi)

on polygon P is always to the left/inside, so as to highlight the

four different geometric configurations.

O’Rourke more exhaustively enumerates the possibilities, where

either of the two edges (edge(pi-1pi) on P or edge(qj-1qj) on Q)can be to the left/inside; resulting in eight rules (O’Rourke, p. 246).

Each of the four Preparata and Laszlo cases corresponds to two of

the O’Rourke rules, covering all eight rules.

Unfortunately, when O’Rourke “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 polygons55
IntersectionIntersection of convex polygons

Advance rules, O’Rourke, 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 O’Rourke easier to read.)

Rule ABa H(B) b 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 caseadvance opposite edges. This is correct, because the differencebetween the two corresponding rules is which edge (A or B) is to the

left/inside.

intersection intersection of convex polygons56
IntersectionIntersection of convex polygons

Advance rules, O’Rourke, 3

O’Rourke condenses the eight rules into four condensed rules,

taking advantage of “don’t care” cases,

in the process mixing the Preparata and Laszlo cases.

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

Algorithm details

See O’Rourke (section 7.4, pp. 243-252, C code)or Laszlo (section 6.5, pp. 154-162, C++ code).

intersection intersection of convex polygons59
IntersectionIntersection of convex polygons

Proof of correctness, 1

The proof of correctness is simplified by a notational shorthand:

Polygon Current edge Shorthand edge nameP edge(pi-1pi) pQ edge(qj-1qj) q

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 polygons60

1

4

1

4

2

4

2

p

4

q

q

2

2

2

2

p

IntersectionIntersection 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 applicationseach of advance case (4),

then (1), then (2).

Case 2 (q outside p).

q will remain fixed while p is

advanced by  0 applicationsof advance case (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 polygons61

P

Cs

p

Cr

qr

R

qs

Q

IntersectionIntersection 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, Cr and Cs.

Cr terminates in edge qr, the edge of Q that crosses p going into R.

Cs terminates in edge qs, whose destination vertex lies to the

left of and is farthest from the line determined by p.

intersection intersection of convex polygons62
IntersectionIntersection of convex polygons

Proof of correctness, 4

When p is positioned as defined, q may be either in Cr or Cs.

These two cases are considered separately.

Case 1 (qCr).

p will remain fixed while q is advanced by  0 applications each ofadvance cases (3), then (4), then (1), then (3), when the intersectionpoint is found.

P

Cs

p

Cr

qr

3

R

1

qs

4

3

4

3

4

Q

3

intersection intersection of convex polygons63
IntersectionIntersection of convex polygons

Proof of correctness, 5

Case 2 (qCs).

q will remain fixed while p is advanced by  0 applications each ofadvance 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 hasn’t done so already).

Thus p and q end up in the same sickle, whereafter assertion 1assures correctness.

P

Cs

p

Cr

qr

R

qs

Q

intersection intersection of convex polygons64
IntersectionIntersection of convex polygons

Analysis

 2(N + M) iterations (advances) suffice to find the first intersection

point and get p and q into the same sickle.

Preparata erroneously says  (N + M).

Thereafter,  (N +M) additional iterations will produce R.

The algorithm requires O(N +M), i.e. linear time.

intersection intersection of convex polyhedra
IntersectionIntersection of convex polyhedra

Problem definitionCONVEX POLYHEDRA INTERSECTION.

INSTANCE. Convex polyhedra P0 and P1 in E3.

QUESTION. Construct polyhedron P0P1.

P0 and P1 are given as boundary representations (vertex and edge),

as will the result P0P1.

intersection intersection of convex polyhedra66
IntersectionIntersection of convex polyhedra

SourceHertel, S., Mäntylä, 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 für Polygone und Polyeder”,

Univ. des Saarlandes, Saarbrücken Germany, 1984.

(Dissertation.)

intersection intersection of convex polyhedra67

E1

IntersectionIntersection of convex polyhedra

PreliminariesThe edge set E of the convex polyhedron P0P1consists of:

1. set E1 of segments on the surface of both polyhedra P0P1

2. set E2 of segments that are edges (or part of edges) of only

one of the polyhedra.

E = E1E2 and E1E2 = .

E is the edge set of the intersection.

P0

E2

P1

intersection intersection of convex polyhedra68
IntersectionIntersection of convex polyhedra

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 problemProblem ICP. Given two convex polyhedra P0 and P1

with a total of N vertices, compute a set of intersection points

of proper edges of P0 with bounding triangles of P1.

This set must contain at least one point of each connected

component of E1P0P1.

Lemma. A solution to problem ICP allows the computation of

(a) P0P1 (b) P0P1 or (c) P0 \ P1 in O(N) time.

\ is set difference, i.e., P0 and P1

intersection intersection of convex polyhedra69
IntersectionIntersection of convex polyhedra

Overall algorithm overview

Two convex polyhedra P0 and P1.

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 E1P0P1.

Graph exploration algorithm O(N)

Any of: (a) P0P1 (b) P0P1 or (c) P0 \ P1.

intersection intersection of convex polyhedra70
IntersectionIntersection 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 Pi, i = 0,1 be one of the polyhedra. Let ej, 0 j < Ni, be thecyclically ordered sequence of edges intersected by the sweepplane. A prong is the portion of a bounding triangle boundedby two consecutive edges ej 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 Pi forms the crown Ci.

Sweep plane

Sweep direction

f

p

b

b

f

f

p

p

f

b

b

f

p

f

p

f

b

f

b

“Cap” not part of crown

Edge classifications: b = base, f = forward, p = prong.

intersection intersection of convex polyhedra71
IntersectionIntersection of convex polyhedra

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 C0 and C1.

Radial representation, stored in binary tree ordered on .

Provides needed O(log N) access.

z-axis

5

b

b

4

f

6,7

f

p

b

p

f

p

’5

’6

f

y-axis

’3,4

f

’7

x-axis

b

p

p

’1

3

’2

p

f

1

b

f

b

2

intersection intersection of convex polyhedra72
IntersectionIntersection of convex polyhedra

Space sweep algorithm overview

Two crowns C0 and C1 are maintained, one for each

polyhedron P0 and P1.

The events are the N = N0 + N1 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Pi:1. Update crown Ci with p.2. Intersect all proper edges of Pi starting at p with opposite crown C1-i.3. Intersect a forward edge of opposite crown C1-i with all faces F that start at p.

This procedure suffices to find at least one point of each component

of E1 (i.e. a solution to problem ICP).

intersection intersection of convex polyhedra73
IntersectionIntersection of convex polyhedra

Event algorithm

1 procedure TRANSITION(p, i) /* p is vertex, i is polyhedron */

2 begin

3 update crown Ci of polyhedron Pi

4 if (exactly one edge e of Pi starts at p) then

5 begin

6 intersect e with crown C1-i of P1-i 7 add all intersection points found to S 8 end 9 else 10 begin

11 for every face F of Pi starting at p12 begin13 intersect the starting proper edges of F with crown C1-i14 add all intersection points found to S15 if (no intersection points found for F) then16 begin

17 choose an arbitrary proper forward edge f of crown C1-i18 intersect f with F19 add any intersection found to S

20 end

21 end

22 end

23 end

intersection intersection of convex polyhedra74

z

x

y

IntersectionIntersection of convex polyhedra

Transition algorithm example, line 4

“exactly one edge e of Pi starts at p”

Proper edge

Improper edge

Face F of Pi

e

p

Sweep plane (seen edge on)

Edge e is the only edge added to Ci by this transition.

Only e needs to be tested for intersection points with C1-i.

intersection intersection of convex polyhedra75

Face F1 of Pi

Proper edge

Improper edge

Face F2 of Pi

Sweep plane (seen edge on)

z

x

y

IntersectionIntersection of convex polyhedra

Transition algorithm example, line 11

“for every face F of Pi starting at p”There may be several faces starting at p, each possibly consisting

of several prongs.

f2

f1

f3

f4

p

f5

f6

f1

Two faces comprised of a total of 5 prongs start at p.

intersection intersection of convex polyhedra76

Face F1 of Pi

Proper edge

Improper edge

Face F2 of Pi

Sweep plane (seen edge on)

z

x

y

IntersectionIntersection of convex polyhedra

Transition algorithm example, line 13

“intersect the starting proper edges of F with crown C1-i”

f1, f3, and f6 are the starting proper edges for p.Recall that p is from polyhedron Pi, so C1-i is the opposite crown.

f2

f1

f3

f4

p

f5

f6

f1

intersection intersection of convex polyhedra77
IntersectionIntersection of convex polyhedra

Transition algorithm example, line 15

“no intersections found”

Even if no edge of Pi starting at p intersects C1-i, it is still possible

that C1-i may intersect a face starting at p; see the figure.

Proper edges of F starting at p

p

e

f

Intersection

g

Face Fof Pi

C1-i

e, f, and g are forward edges of C1-i.

The algorithm lines 15-20 take care of this case.

intersection intersection of convex polyhedra78
IntersectionIntersection of convex polyhedra

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 E1.

Let K be any component of E1; 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 polyhedron Pi

and a face F polyhedron P1-i.

TRANSITION will either find v or it will not;

if it does, K is done, because a vertex of E1 is found.

intersection intersection of convex polyhedra79

z

x

y

IntersectionIntersection 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 Ci of Pi.

F P1-i

p P1-i

v Pi

e

G Ci

Conceptually trace the portion of K contained in F and Ci.

Two cases may arise:

1. Not all of K is in F and Ci.

2. All of K is in F and Ci.

intersection intersection of convex polyhedra80

F P1-i

p P1-i

e’

v Pi

e

F  G

z

e’’

G Ci

x

y

IntersectionIntersection of convex polyhedra

Proof of correctness, Case 1

Case 1: Not all of K is in F and Ci.

While tracing K, we reach either a bounding edge e’ of F (subcase a)

or a prong edge e’’ of Ci (subcase b). Because v has the minimal

x-coordinate of K, we do not leave Ci via a base edge.

bounding edge

prong edge

intersection intersection of convex polyhedra81
IntersectionIntersection of convex polyhedra

Proof of correctness, Case 1, subcase a

F P1-i

p P1-i

e’

v Pi

e

F  G

e’  G

z

G Ci

e’’

x

y

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 Ci (because eCi intersects FC1-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 Ci at that time).

intersection intersection of convex polyhedra82
IntersectionIntersection of convex polyhedra

Proof of correctness, Case 1, subcase b

F P1-i

p P1-i

v Pi

e

e’’  F

z

G Ci

e’’

x

y

Subcase b: Tracing K reaches prong edge e’’ of Ci.

Because of the triangulation chosen, e’’ being a prong edge implies

that itis a proper edge.

F will still be part of C1-i when the starting point of e’’ is the event.

Then e’’ F, a vertex of K, will be found at that event.

intersection intersection of convex polyhedra83

p

e

Intersection

v

Face Fof P1-i

Ci

earlier Ci-1

IntersectionIntersection of convex polyhedra

Proof of correctness, Case 2

Case 2: All of K is in F and Ci.

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 Ci 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 Ci; thus K is a closed curve in Fthrough all prongs of Ci and intersecting all forward edges of Ci.

Thus a vertex of K will be found in lines 15-20 of TRANSITION.

intersection intersection of convex polyhedra84
IntersectionIntersection of convex polyhedra

Graph exploration algorithm overview

The graph exploration algorithm constructs a boundary

representation of P0P1 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 E1P0P1.(1) For a point xS, find all edges in E1 and candidate edges for E2 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 polyhedra85
IntersectionIntersection 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S be a point that is the intersection of a proper edge e

separating two bounding triangles F’ and F’’ of P0 with a bounding

triangle of P1. Such a point x exists if PiPi-1.

Step (1) will construct all edges of E1 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 P1.

2. x is the intersection of two edges, but not a polyhedron vertex.

3. x is a vertex of P0 and/or P1.

intersection intersection of convex polyhedra86
IntersectionIntersection of convex polyhedra

Graph exploration cases, case 1

Description:

x is not a polyhedron vertex, and lies in the interior of a boundingtriangle F of P1.

Processing:

1. Intersect F with all bounding triangles of P0 incident to x,

and add the endpoints of the segments of intersection

to the list of points to expand.

P0

e

F

F’’

F’

x

P1

intersection intersection of convex polyhedra87

P0

e

F’’

F’

F’’’

x

F

P1

f

IntersectionIntersection of convex polyhedra

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 P0 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 polyhedra88

P0

e

F’’

F’

x

IntersectionIntersection of convex polyhedra

Graph exploration cases, case 3

Description:

x is a vertex of P0 and/or P1.

Processing:

1. Subcase 1: x is in interior of bounding triangle of P1. Intersect F with all bounding triangles of P0 incident to x.

2. Subcase 2: x is on an edge of P1. As with Subcase 1, handling coplanarities.

3. Subcase 3: x is on a vertex of P1. Find plane D intersecting all edge of P0 incident to x. Compute (P0D)  (P1D), both convex polygons.

Infer structure of E1 around x from resulting polygon.

P1

f

F’’’

F

intersection intersection of convex polyhedra89
IntersectionIntersection of convex polyhedra

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) each2. Graph exploration O(N)

Overall worst case time complexity O(N log N)

ad