Top Banner
COSC 6114 Prof. Andy Mirzaian
65

COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Mar 30, 2015

Download

Documents

Vivian Northen
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

COSC 6114

Prof. Andy Mirzaian

Page 2: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

References:• [Preparata-Shamos’85] chapter 1.3• [Edelsbrunner’87] chapter 1.6, 4.2, 14• [O’Rourke’98] chapter 6• [Matoušek] Lecture Notes [at http://kam.mff.cuni.cz/~matousek/ ]• Guibas, Stolfi [1987] “Ruler, Compass and computer: The design and analysis of

geometric algorithms,” Proc. of the NATO Advanced Science Institute, series F, vol. 40: Theoretical Foundations of Computer Graphics and CAD, 111-165.

• Edelsbrunner, O’Rourke, Seidel [1986] “Constructing Arrangements of Lines and Hyper-planes with Applications,” SIAM J. Comp. 15, 341-363.

• Edelsbrunner, Guibas [1989] “Topologically sweeping an arrangement,” JCSS 38, pp:165-194 [correction in JCSS …]

Applications: • range searching, • geometric optimization, • motion planning, • visualization, • molecular modeling, • wireless networks: shadow edge estimation & sensor selection• …

Page 3: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Super-sampling in Ray Tracing

• A ray through each pixel center.

• Problems: jagged edges, false hit/miss.

• A solution: super-sampling. Shoot many rays per pixel (usually at random) if 100 rays shot at pixel, and 43 hit the same object, we say object visible in roughly 43% pixel area.

Determining visible objects by ray tracing.

Page 4: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Computing the Discrepancy

DS(h) = |1/4 – 3/10 | = 0.05

Pixel U = [0 : 1] [0 : 1] S = a set of n sample points in U H = set of all half-planes

For h H define:m(h) = area(h U) continuous measure

mS(h) = |S h| / |S| discrete measure

DS(h) = | m(h) - mS(h) | discrepancy of h

DH (S) = sup hH DS(h) half-plane discrepancy of S

The bounding line of this worst half-plane h passesthrough either only 1, or at least 2, sample points.

FACT: DH (S) can be computed in O(n2) time, using

Geometric Duality &Arrangement of lines in the plane.

Page 5: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

geometric duality

2D arrangements of lines Incremental Construction Ham-Sandwich Cuts Topological Sweep Applications

Page 6: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

GEOMETRIC DUALITY

Page 7: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Geometric Duality

Point -to- hyperplane Transformations

Some Applications:

Intersection of half-spaces Convex Hull of point sets

Whenever the problem becomes intuitively “easier” in the dual space.

Page 8: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

1. Hough (or Reciprocal) Transform (1969)

dPoint: (a1, a2, … , ad )

origin

Hyper-plane: a1x1+a2x2+… +adxd +1 = 0

not passing through the origin

2 Point: (a,b) (0,0) Line: ax + by + 1 = 0

p* = dual of p

d(0,p) d(0,p*) = 1

The origin is “above” the line.

(a,b)

ax + by + 1 = 0

slope = -a/b

1/d

dx

y

Page 9: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

2. Another Point-Line Transform

(a,b)

y=ax + b

slope = a

x

y

Point p: (a, b) line p*: y = ax + b (non-vertical line)Line l: y = ax + b point l*: (-a, b)

“asymmetric”: p** p, l** l.

Page 10: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

3. Another Point-Line Transform

(a,b)

y=2a

x - b

x

y

Point p: (a, b) line l: y = 2ax – b

“symmetric”: p** = p, l** = l.

(a,a2)

y=2a

x –

a2

y = x2

Some technical difficulties:• In (1) the origin is not mapped suitably.• In (2) and (3) lines parallel to the y-axis are not mapped.• How to interpret dual of oriented lines?

(Answer: Use “inversive” transforms (see [PrS85] section 1.3.)

Page 11: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Duality Transforms Preserve Incidence1. Point p is mapped to line p*.2. Line l is mapped to point l*.3. Point p and line l are incident line p* and point l* are incident

4. Above/Below relation is also preserved (or reversed).

5. Line l passes through points p & q Lines p* & q* intersect at point l*.

6. Points p, q, r are collinear Lines p*, q*, r* are concurrent.

lp l*

p*

l

p

p*

l*

lp

l*

p*

q

q*

lp

l*p*

q

q*r*

r

Th

ey preserve in

ciden

ce since th

ey are affine tran

sform

s

Page 12: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Problem Transformation by Duality

Problem 1: Compute the discrepancy:

p

q

p*q*

L*

PRIMAL PLANE DUAL PLANE

L

Now compute levels in arrangementof lines in the dual plane

Problem 2: [Degeneracy]: are there any 3 collinear points among n given points?Solution: Duality: are there 3 concurrent lines among n given lines?

(Use arrangement of lines)

Page 13: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Problem Transformation by Duality

Problem 3: Find upper (respectively, lower) envelope of n given linesSolution: Compute upper (respectively, lower) convex hull of the n dual points

l1

PRIMAL PLANEDUAL PLANE

l2 l3

l4l1*

l2*l3*

l4*

Problem 4: Compute intersection of n half-spacesSolution: Compute Convex Hull of n dual pointsCaution: What happens if the origin is not in the intersection?

Page 14: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Arrangements

Page 15: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Arrangements of lines and hyper-planes

L = { l1 , l2 , … , ln } n lines in 2 (in general: n hyper-planes in d )

A(L ) = arrangement of L , i.e., subdivision of 2 (resp., d ) induced by L .

Assume: L is in general position, i.e., no 2 lines in L are parallel, & no 3 are concurrent.

d

nnnn

210

2

n

Combinatorial complexity of A(L ) in 2 :

V = # vertices =

E = # edges = n2 (each line is cut into n edges)

F = # regions = Q (n2)

Euler: (V+1) – E + F = 2 vertex at

F = (n2 + n + 2) / 2

Page 16: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Arrangement Construction

Will take at least W(n2) time & space, due to combinatorial size of A(L ).

1. Plane Sweep:At least W(n2 log n) time, since it will “sort” the arrangement vertices.

2. Naïve Incremental AlgorithmA ({ l1 , l2 , … , lk-1 }) A ({ l1 , l2 , … , lk }), for k=2..n Binary Search to find vi1 , vi+1,1 .

O(log k) for each of l1 , l2 , … , lk-1. O(k log k) to insert lk.

Total O( Sk k log k) = O(n2 log n) time, and O(n2) space.

lk

l1

vi1vi+1,1

Page 17: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Refined Incremental Algorithm

How to insert lk in A({ l1 , l2 , … , lk-1 }) ?

lk

l1

u0

u1

u2

u3

v0

v1

v2

lm

“upward”movement

on oneside of

l1

“downward”movement

on theother side

of l1

Page 18: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Refined Incremental Algorithm

How to insert lk in A({ l1 , l2 , … , lk-1 }) :

1. Find u0 = l1 lk and rightmost vertex v0 on l1 to the left of u0, in O(k) time.

Let v0v1 be CCW from v0u0 on vertex v0 .

2. If segment v0v1 intersects lk , then we have closed a polygonal line that starts

from a previous intersection point, namely u0, and ends in another intersection point, namely u1. Therefore, we can insert u1 properly in the adjacency list.

We now go to u1 and repeat steps 1,2,3 with u1 as the new u0 and lm as the new l1.

3. If v0v1 does not intersect lk , then we take the next vertex v2 CCW on v1 from v1v0

and repeat the same procedure.

4. When we encounter a vertex that has a leftmost edge which is a ray diverging from

lk, we have finished the “upward” movement.

5. We do a similar “downward” movement, starting from v0, on the other side of l1.

Page 19: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

ZONE of a line in the arrangement

Zone of lk

= collection of the polygonal regions of the arrangement

that have an edge on lk.

Combinatorial complexity of a zone = total number of vertices of the polygonal regions in the zone (counting multiplicities).

lk

upper zone

lower zone

Page 20: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

ZONE Complexity

THEOREM: Combinatorial complexity of zone of lk in A({ l1 , l2 , … , lk-1 }) is

5k-6 on each side ( 10k–12 on both sides).

lk

floor

vtop

leftwalls

rightwalls

ceiling

lk

lj e1

e2

e3

Proof 1: k convex polygonal regions incident to in the “upper” zone of lk (similarly in the “lower” zone).

Define: ceiling, left/right wall, & floor edges for each polygon as the figure on the right.

Claim: 1 left wall & 1 right wall on each line lj , j =1..k-1.

Proof: e1 ceiling e3’s extension cuts Pm a contradiction.

Corollary: 2(k-1) -2 = 2k-4 wall edges. (First poly has no left wall, last poly has no right wall.)

Total count: k floors 2k-4 walls 2k-2 ceilings (1s & last have only one ceiling edge) 5k-6 total

Pi

Pm

Page 21: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Davenport–Schinzel Sequences

DSs(n) : a1 a2 a3 … • n different characters• ai ai+1 • … a … b … a … b … a … b … (length s+2 alternating subsequence

is forbidden)

ls(n) = max length DS sequence (n,s)

Fact: l1(n) = n l2(n) = 2n-1 l3(n) = Q(n a(n)) (a(n) = inverse Ackermann’s function,

very slow growing.)

Example: max length of upper envelope of n (possibly crossing) line-segments in the plane= Q(l3(n)).

Page 22: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

ZONE Complexity

THEOREM: Combinatorial complexity of zone of lk in A({ l1 , l2 , … , lk-1 }) is

5k-6 on each side ( 10k–12 on both sides).

lk

lk

Proof 2: By Davenport-Schinzel sequences.Consider the sequence of only left wall/ceiling edges inthe traversal of upper-zone of lk (similarly for right … ).

Claim: This is a (k-1, 2) DS sequence. That is, …a…b…a…b…is a forbidden sub-sequence.

a b c d

d b d c a c d

a b

Canno

t

cont

ribut

ean

y le

ftw/c

.

..b..b..b..a..a..b..b.. Total count:

k floors

2(k-1) -1 left walls / ceilings

2(k-1) -1 right walls / ceilings 5k-6 total lk

ab

..a..a..a..b..b..b..

Page 23: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Arrangement Complexity

THEOREM: The arrangement A(L) of n lines L = { l1 , l2 , … , ln } in 2 can be constructed in optimal time & space O(n2).

THEOREM: Let H = { h1 , h2 , … , hn } be a set of n hyper-planes in d.

(a) The combinatorial size of the zone of any hyper-plane in the

arrangement A(H) is O(nd-1).

(b) A(H) can be constructed in optimal time & space O(nd).

Page 24: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Levels and Discrepancy

U = [0 : 1] [0 : 1], S = a set of n points in U.Dualize: S S* A(S*).

For each vertex v in A(S*) we need to compute how many lines of S* area) strictly above it [let’s call this level(v)],b) pass through it,c) strictly below it.

We essentially need to compute the levels of all vertices of the arrangement A(S*).Take a walk along each line, and compute the level of each vertex on it.

0

112 3 2

2

3 4

33

l

level=1

2

-1

0

+1

1-1

1

+1 +1

3

Compute level of leftmost vertex of l in O(n) time, then compute each of itssubsequent vertices in order of degree of the vertex.

Total time, over all lines in S*, is O( sum of vertex degrees + n2) = O(n2).

Page 25: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Ham-Sandwich Cuts

Page 26: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Ham-Sandwich Cuts

Duality D: point p: (a,b) line p*: y = ax – b line l: y = a x + b point l*: (a, -b)

Fact: D preserves point-line incidence & above-below relationships.

Definition: A bisector hyper-plane of n points in d is one such that each of its induced open half-spaces contains n/2 of the points.

Page 27: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Ham-Sandwich TheoremBorsuk-Ulam Theorem [1933]: Let f: Sd-1 | d-1 be any continuous mapping

from the sphere Sd-1 to d-1.Then, f(x) = f(-x) for some anti-podal pair x and –x on Sd-1. (For details see [Ede87].)

x

-x

S1

Ham-Sandwich Theorem:Let P1 , P2 , … , Pd be d finite point sets in d.

There exists a hyper-plane h in d that simultaneously bisects P1 , P2 , … , Pd.

Proof: By Borsuk-Ulam Theorem. Let x be an arbitrary point on the sphere Sd-1. Consider the hyper-plane h(x) that bisects Pd and has x as unit normal vector. Define f(x) = (n1, n2, , … , nd-1), where nk is # points of Pk on the “positive” side of h(x), plus half the # points of Pk on h(x).Note that, f(-x) = ( |P1| - n1, |P2| - n2 , … , |Pd-1| - nd-1 ).Function f(x) can be “made” continuous.By Borzuk-Ulam Theorem, there is an x on Sd-1 such that f(x) = f(-x).For such an x, h(x) is a ham-sandwich cut, i.e., simultaneously bisects P1, P2, …, Pd.Stone-Tukey [1942]: Proved the continuous version: volume bisection.

Page 28: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

2D Ham-Sandwich Cut (HSC)

Ham-Sandwich Theorem in 2D: Consider finite point sets P and Q in the plane, where |P|=m, |Q|=n.There exists a line L in the plane that simultaneously bisects P and Q.[WLOGA m and n are odd. We may add extra point if even.]

L

Page 29: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

2D HSCConsider sets of points P and Q in the plane, where |P|=m, |Q|=n, both odd.Then HSC of P&Q can be computed in O((m+n) log (m+n)) time. [Lo, Matoušek, Steiger [1994], Discr. Comp. Geom. 433-452]

improved it to O(m+n) time.

Page 30: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

2D HSCConsider sets of points P and Q in the plane, where |P|=m, |Q|=n, both odd.Then HSC of P&Q can be computed in O((m+n) log (m+n)) time. [Lo, Matoušek, Steiger [1994], Discr. Comp. Geom. 433-452]

improved it to O(m+n) time.

L

COROLLARY: A set in 2D (also in 3D) can be 4-sected in linear time.

THEOREM: If P and Q are linearly separable, then HSC of P&Q can be computed in O(m+n) time.

P Q P Q

We will show:

Page 31: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

2D HSCTHEOREM: If P and Q are linearly separable, then HSC of P&Q can be computed in O(m+n) time.

METHOD: Apply duality. Consider the dual sets of lines G = P* and H = Q*.Find the intersection of the mid-level of their arrangements by prune-&-search.WLOGA P&Q are separated by the y-axis.

PQ

y

X < 0 X > 0

G

H

L*

LP,Q

L*

Slope > 0

Slope < 0

Page 32: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Prune-&-Search: TEST(line t)

(1) Line t is vertical (Fig. (a))i(P) above i(Q) s is to the right of t.

(2) 0 < slope(t) < (Fig. (b))i(P) above i(Q) s is below t.

(3) - < slope(t) < 0 (similar).

(4) slope(t) = 0 (Fig. (c))i(P) left of i(Q) s is below t.

L(G)

L(H)

t

i(P)

i(Q)

s

K(H)th level of H

K(G)th level of G

(a)

L(G)

L(H)

t’

i(P)

i(Q)

s (b)t

L(G)

L(H)

i(P)

i(Q)

s

(c)

t

Page 33: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

(1) Lmed median-slope line in G H.

L< { L G H | slope(L) < slope(Lmed) }

L= { L G H | slope(L) = slope(Lmed) }

L> { L G H | slope(L) > slope(Lmed) }

(2) Pair up lines in L< with those in L> as much as possible into a set of pairs called Pairs.

( | | L< | - | L>| | lines of either L< or L> remain unmatched.)

(3) A multiset of x-coordinates of intersection points of each pair in Pairs.

(4) t1 the vertical line through median point in A. TEST(t1). It either terminates having found a

point in L(G) L(H), or determines the half-plane t1+ that contains L(G) L(H).

(5) B the multiset of points on t1 as follows: intersections of t1 with lines in L= and

intersections of t1 with lines of slope(Lmed ) through intersections of those pairs in Pairs

that are not in t1+.

(6) t2 line with slope (Lmed ) through median point in B. TEST(t2). It either terminates having

found a point in L(G) L(H), or determines the half-plane t2+ that contains L(G) L(H).

(7) q t1+ t2+ (quadrant that contains a point in L(G) L(H).)

Finding test lines & pruning

slope(Lmed) t1+

t1

t1

t2q

Page 34: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

LEMMA: Suppose |G H| = L and let q be the quadrant t1+ t2+ computed in the procedure. Then, at least L/8 of the lines in G H avoid the quadrant q.

Finding test lines & pruning

t1

t2

q

avoids q

Proof: Define N< = | L< | , N= = | L= | , N> = | L> |.

L = N< + N= + N> ,

|A| = min {N< , N> } ,

|B| N= + ½ |A| ,

# lines avoiding q ½ |B|

½ N= + ¼ min {N< , N> }

1/4 N= + ¼ min {N< + N= , N> + N= }

1/4 N= + ¼ ½ L

1/8 L

by median property

N< N= N>

L

Page 35: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

ALGORITHM: Ham-sandwich cut in the plane for 2 linearly separated point sets.

Finding test lines & pruning

t1

t2

q wheres lies

SEARCH: Find t1 and t2 and TEST

PRUNE: Eliminate all lines of G and H that avoid region q andupdate levels K(G) and K(H) accordingly.

RECURSE: Repeat the above process with the new G & H & K(G) & K(H).

RECURRENCE: T(L) = T(7L/8) + O(L) T(L) = O(L)

THEOREM: Total time = O( m+n ).

Page 36: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Half-plane Range QueriesHalf-Plane Range Query Processing: Given a fixed set P of n points in the plane, preprocess P for such queries: given a half-plane H, report H P.

Idea: Any intersecting pair of lines divide the plane into 4 quadrants. Any half-plane either completely contains or completely misses at least one quadrant.

Ham-Sandwich Trees:

L1L2

L3

L4

L5

L6

L8

L7

L1

L2 L2

L3 L3 L4 L4

L5 L5 L6 L6 L8 L8L7

Preprocessing Time = O(n log n) Space = O(n)

Query Time Q(n) = Q(n/2) + Q(n/4) + O(log n) = O(na), a = log (1+5)/2 < 0.69

Query Report = O(K + na) .

Page 37: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Half-plane Range Queries

Ham-Sandwich Tree:

Preprocessing Time = O(n log n) Space = O(n)Query Report = O(K + na) , a = log (1+5)/2 < 0.69

OPEN: Can it be improved to O(K + log n) time without increasing the preprocessing time or space?

Partial Answer by Point Location in Arrangements:

O(n2) preprocessing time & space to form A(P*), arrangement of dual of P.

Preprocess A(P*) for point location in O(n2) time & space.

Query Time: O(K + log n).

Page 38: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

TOPOLOGICAL SWEEP

Page 39: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Topological Sweep of Line Arrangements

IDEA: It requires only O(n) space, instead of O(n2) to maintain the entire arrangement of n lines in the plane, all at once.

Definition: A cut is a simple curve that intersects each line of the arrangement once. Cut = (c1 , c2 , … , cn ) is sequence of cut edges from top to bottom.

1

2

3

4

c1

c2

c3

c4

1

2

3

4

c1

c2

c3c4

Technical Assumption: In the arrangement each edge is half-open; it contains its right end-point, but not its left-end-point.

cut cut

Page 40: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Leftmost & Rightmost cutsleftmost cut

(no vertex to its left)rightmost cut

(no vertex to its right)

Page 41: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Where to advance the cutC C’

Li

Lj

above

below

FACT 1: Let C = (c1 , c2 , … , cn ) be any cut, except the right-most cut.

Then at least one pair of adjacent edges of the cut, say (ci , ci+1), have a common right end-point.

Proof: Let ci be the cut edge with the leftmost right end-point ri.

We claim ri is either ci ci+1 or ci ci-1 .

ri

ci

ci+1

ri

ri rici

ci

ci

ci-1

impossible

ri

rici

ci

Page 42: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Topological Sweep

1. Start from the leftmost cut.

2. Using Fact 1, choose an adjacent pair of cut edges with a common right end-point vertex v, and advance the cut past vertex v.

3. Repeat step 2 until the rightmost cut is reached.

Auxiliary data structures to help quickly find such a vertex v in step 2.

Stack I: of intersection points (ci , ci+1) that are vertices of the arrangement

Upper Horizon Tree (UHT)

Lower Horizon Tree (LHT)

M[1..n]: permutation of lines L1, L2 , … , Ln that contain edges of the cut C.

N[1..n]: N[i] contains left & right ends of ci and tells

which 2 lines delimit these end-points.

Total space O(n).

Page 43: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Upper Horizon Tree

UHT: For a given cut C = (c1 , c2 , … , cn ) , add a vertical line at x= . Start from each edge of the cut and move right. When reached a vertex of the arrangement, take the higher edge out of it to the right and continue the same way until hitting the vertical line at x = . The edges of the arrangement traversed this way form the UHT.

LHT: defined similarly.

See next slides for an example.

Page 44: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

A Cut

Cut

Page 45: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

UHT

Cut

Vertical line at x = not shown

Page 46: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

LHT

Cut

x =

Page 47: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

More Facts

FACT 2: UHT & LHT are indeed trees.

Proof: Recall the technical assumption (left end-points of cut edges are not part of the edge. So, no cycle that way). As we go up the tree from each edge to the parent edge, the slope changes monotonically. So, no cycle can occur. The line at x = is the root.

FACT 3: Two cut-edges share a right end-point they do so in both UHT & LHT.

[This is the reason for using UHT & LHT.]

Page 48: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Topological-sweep overview

1. Sort L1, L2, … , Ln in increasing order of slope O(n log n) time

2. Initialize the data-structures for the “left-most” cut: O(n) timeUHT, LHT, N[1..n], Stack I, M[1..n] (use the sorted order of step 1)

3. General Step: O(n2) iterations, each takes O(1) amortized time while stack I do (3a) pop a vertex v = ci ci+1 from stack I (3b) push the cut past vertex v and update the data-structures.

end

Total time = O(n2), space = O(n).

Page 49: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Step 2 details O(n) time

Initialize UHT: Incrementally add Ln, Ln-1, … , Li+1, Li, …, L1.

Go CCW along the Bay “up-wards” & eliminate lines until Li is added at the proper place.

Implement the Bay as a stack.

LiLi+1

Ln

Bay

Initialize LHT: Similar.

Initialize N[1..n]:

The leftmost segment of each line (which is the appropriate edge for the leftmost cut) is the shorter of the segments of the line in the UHT & LHT.

Initialize Stack I: Once N[1..n] is known, stack I can be trivially obtained using FACT 3.

Initialize M[1..n]: Use sorted order of step 1.

newBay

Page 50: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Step 3 details Pop vertex v=cici+1 from stack I & update the structures after advancing the cut past v.

How to update the UHT:

Line M[i+1], with greater slope, needs no change

Line M[i] should be updated:

ci+2

c’i+1

?

c’i

Bay

w

ci+1

ci

vw

cutcut

Before After

push vertex v

c’i proceeds as before along M[i+1] in UHT.

c’i+1 : CCW scan the Bay starting from leaf ci+2 of UHT and move up along its ancestral path

to find which edge is hit by c’i+1.

As we topologically sweep over vertices, we compute the desired info on vertices/edges ofthe arrangement (see next application).

M[i+1]

v

Page 51: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

CLAIM: Step 3 takes O(1) amortized time per iteration.

Corollary: Topological-sweep of an arrangement of n lines in the plane requires O(n2) time but only O(n) space.

L).n(O)12n10(

L1 1 1charges

2

TheoremZone

L linetouching

polygons of vertices#

edgean as ewith

region a tobelongs

othereach see""can e &v

e ve)(v,

Proof: [Note: actual time of each vertex-push could be as high as O(n).]

(1) Charge vertex v, 1 for each edge of the Bay we span (except the last).

(2) Transfer charges received by w to v due to edges of the Bay after the one intersected by c’i+1

(they are still visible to v but not to w).

(3) Charge Invariant: Currently a pair (v,e) is charged iff vertex v and edge e can “see” each other at the current situation of the cut, i.e., portion of the arrangement swept over + edges in the UHT.

ci+2

c’i+1

?

c’i

Bay

w

cut

v

Page 52: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Application: Smallest Area Triangle

Problem: Given n points in the plane, find 3 of the points with minimum possible triangle area.

Solution tools used:

geometric duality

arrangement of lines

plane sweep

trapezoidal decomposition

topological sweep

Application: [Degeneracy Test] Are any of the 3 points collinear?

Page 53: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Application: Smallest Area Triangle

SOLUTIONS TIME SPACE

Brute force O(n3) O(n)

Geometric Duality O(n2 log n) O(n2)

Geometric Duality + O(n2 log n) O(n)Plane Sweep

Geometric Duality + O(n2) O(n2)Arrangement

Geometric Duality + O(n2) O(n)Topological Sweepof Arrangement

OPEN PROBLEM: Known lower and upper bounds on time complexity: W(n log n) and O(n2). Resolve the gap between the lower and upper bound.

See next pages for details

Page 54: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Geometric Duality

Primal space Dual space

Point p = (a,b) line p*: y = ax + b

Line L: y = ax + b point L* = (-a , b)

Technicality: Vertical lines can’t be represented by points in the dual space.

How to avoid: Sort the points (in primal space), then check to see if any two have the same x-coordinate. If so, the line through them will be vertical. Rotate the coordinate axes slightly, if necessary, to avoid this. This can be achieved in O(n log n) time.

d(p,

L)

p

L

Notation:

Li = p*i line dual to point pi.

d(p,q) = Euclidean distance between the two points p and q.

d(p,L) = orthogonal distance of point p from line L

L(pi , pj) = line (not line-segment) through points pi & pj.

Page 55: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Geometric Duality

Primal Space: Take 2 points pi , pj. Find 3rd point pk that minimizes d(pk, L(pi,pj)). Then, triangle Dpipjpk is the smallest area triangle with (pi,pj) as one of its sides.

Triangle Area = ½ d(pi,pj)d(pk ,L(pi , pj)).

pk

pi

pj Lk

LiLj

CLAIM 2: dV(pk ,L(pi , pj)) = dV(I(Li , Lj) , Lk)

Proof: Algebra exercise.

CLAIM 1: The ratio d(pk ,L(pi , pj)) dV(pk ,L(pi , pj)) is fixed as pk varies among the remaining n-2 points.

d(p,

L)

p

L

dV(p,L)

Define:dV(pk ,L(pi , pj)) = vertical distance of pk from L(pi , pj). I(Li , Lj) = intersection point of dual lines Li & Lj.

Page 56: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Solution 1: Geometric Duality

CONSEQUENCE: In the dual space consider the arrangement of lines L1 , L2 , … , Ln and observethat vertical distance between I(Li , Lj) and Lk is attained only when Lk is the linethat is immediately above or below point I(Li , Lj) . Therefore, it belong to the same face of the Arrangement.

ALGORITHM 1:

1. Sort by x-coordinate all O(n2) intersection points I(Li , Lj), 1 i < j n.

2. Order all L1 , L2 , … , Ln vertically just to the left of the leftmost intersectionpoint, and in O(n) time rank this intersection point & find the pair of lines just above & below it.

3. At intersection point I(Li , Lj), swap Li & Lj in the vertical ordering (they are adjacent in that ordering), and get the 2 lines just above & below the intersection in O(1) time.

Repeat this process in sorted order of intersection points.

CLAIM: Step 1 takes O(n2 log n) time. The rest takes O(n2) time by spending O(1) time per intersection point. Space is O(n2).

Page 57: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Solution 2: Plane Sweep in dual space

ALGORITHM 2:

Use plane-sweep method to compute the intersection points “on the fly” and maintain

the vertical ordering of the dual lines in a dictionary as the sweep progresses.

CLAIM: Algorithm 2 requires O(n2 log n) time and O(n) space.

[O(log n) time per intersection point processed.]

Page 58: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Solution 3: Trapezoidal Decomposition in dual space

ALGORITHM 3:

Construct the arrangement of dual lines L1 , L2 , … , Ln.

(Convex regions, hence x-monotone.)

Obtain the trapezoidal decomposition of the arrangement.

Obtain the 2 lines immediately above & below each intersection point.

CLAIM: Algorithm 3 requires O(n2) time and O(n2) space.

Page 59: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Solution 4: Topological sweep in dual space

ALGORITHM 4:

Use topological sweep on the arrangement of dual lines.

Whenever the cut advances past a vertex v=cici+1, compute the necessary

info about v,i.e., its vertical distance from the line above it and the line below it.

Details: Exercise.

CLAIM: Algorithm 4 requires O(n2) time and O(n) space.

Page 60: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

Exercises

Page 61: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

1. Let P be any set of n 3 points in the plane, not all on a line. (a) Prove that there is a line that contains exactly two points of P.(b) Prove that there are at least n lines each passing through at least two points of P.

2. We are given a set L of n lines and a set P of n points in the plane. We want to determine whether some point in P is on some line in L . (a) What is the geometric dual of this problem? (b) Design an efficient algorithm to solve the problem. [Hint: shoot for a sub-quadratic running time. Begin by dividing L into roughly n/m groups of size m each. Then optimize the total running time over the parameter m.]

3. Given a set L of n lines in the plane, design an O(n log n) time algorithm to compute the convex hull of the O(n2) vertices of the arrangement A(L) .

4. Define a strip to be the region bounded by two (non-vertical) parallel lines. The width of a strip is the vertical distance between the two lines. The problem is, given a set of n points in the plane find the non-vertical strip of minimum width that encloses all of these points.(a)  What is the problem in the dual setting?(b) Give an O(n) time algorithm to solve the problem. [Hint: use prune-&-search.]

width

Page 62: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

5. Let A(L ) denote the arrangement of a set L of n lines generally positioned in the plane, i.e., no two lines of L are parallel, and no three of them pass through the same point. A triangle in A(L ) is a region of A(L ) that is bounded and has three sides. Prove that A(L ) must have at least n2 triangles.

6. Let Q denote the intersection of n given half-planes {H1 , H2 , …, Hn } in the plane.

Design and analyze a linear time deterministic algorithm to determine whether Q isempty, and if not, find a point q Q. [Hint: One method is to use geometric duality and prune-&-search.]

7. Given a set P of n points in the plane, design an efficient data structure that can answer line-dragging queries. Such a query is specified by giving a non-vertical line l and asking for the first point of P that would be hit by dragging l vertically upward without changing its slope. [Hint: Shoot for a query time of O(log n) with a data structure using O(n2) space.]

8. Given an n-vertex simple polygon P and an edge e of P, show how to construct a data structure to answer the following queries in O(log n) time and O(n) space. Given a ray r whose origin lies on e and which is directed into the interior of P, find the first edge of P that this ray hits. For example, in the figure below the query for ray r should report edge f. You may assume that e is rotated into a convenient position, if it helps to simplify things. [Hint: Use duality to reduce this to a point location query.]

r

e

f

P

Page 63: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

9. Consider a set P of n points in the plane. For k < n/2, a point q (not necessarily in P) is called a k-splitter if for every line l passing through q at least k points of P lie on or above l, and at least k points of P lie on or below l. (For example, point q shown in the figure below isa 3-splitter, since every line passing through q has at least 3 points of P lying on either side. But it is not a 4-splitter, since the horizontal line through q has only 3 points below it.)

(a) Prove that there exists a k-splitter if and only if in the dual line arrangement of P, levels L(k) and L(n-k+1) can be separated by a line. (L(k) is the set of arrangement edgesthat each have k-1 arrangement lines strictly above them. For example, L(1) is the upper-envelope, and L(n) is the lower envelope of the arrangement lines.)

(b) Let u and v be two arbitrary points of level L(k) of the dual line arrangement. Let w be an arbitrary point on the line segment uv. What is the maximum number of lines of the arrangement that can be at or below (respectively, at or above) w? Express your answers in terms of n and k and prove your claim.

(c) Using (b), prove that any set of n points in the plane has a n/3-splitter.

(d) Describe an O(n2) time algorithm for computing a n/3-splitter of P.

(e) Prove or disprove: for all n and all k > n/3, there exists a set of n points in the plane that has no k-splitter.

q

Page 64: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

10. Let P be a given set of n points in the plane. 3 concurrent lines define a 6-partition of P if the

removal of these 3 lines partitions the plane into 6 open sectors such that each sector contains at most n/6 points of P. (Note: The points of P that lie on the 3 lines do not count.)(a) Prove that any set P admits a 6-partition.(b) Design and analyze an efficient algorithm to find a 6-partition of P.

11. Let L = { l0 , l1 , . . . , ln-1} be a set of n non-vertical lines in general position in the plane (i.e., no two parallel, no three concurrent). Furthermore, assume the lines in L are given sorted in increasing order of slope. That is, if the equation of line li is y = ai x + bi , then a0 < a1 < . . . < an-1 . Consider the arrangement A (L) of L in the plane. Let F denote the set of all polygonal regions in the arrangement. Let F¥ denote the subset of F consisting of only unbounded regions. For each polygonal region R ÎF, let size(R) denote the number of boundary edges of R.

(a) Show that {S size(R)2 | R Î F } = O(n2). [Hint: use aggregate of zones of lines in A (L) .]

(b) Show that {S size(R) | R Î F¥ } = O(n).(c) Let S be the set of n(n − 1)/2 vertices of the arrangement. Let P be the union of the bounded faces of the arrangement A (L). We consider all vertices in S on the boundary of P as vertices of P. So, P may have many collinear vertices. Prove that P is a simple polygon and it has O(n) vertices.(d) Show that we can construct polygon P in O(n) time, assuming the lines in L are given in sorted order of slope. [Hint: Use topological sweep (implicitly). Maintain the upper horizon tree for the leftmost cut while continuously rotating the coordinate axes CCW.](e) Recall the lines in L are given in sorted order of slope, and S is the set of all vertices of the arrangement. Let vertex qi be the intersection of lines li and l(i+1)modn, for i = 0 .. n − 1. Prove that CH(S) = CH(q0 , q1 , . . . , qn-1 ).(f) Show that CH(S) can be computed in O(n) time.

Page 65: COSC 6114 Prof. Andy Mirzaian. References: [Preparata-Shamos85] chapter 1.3 [Edelsbrunner87] chapter 1.6, 4.2, 14 [ORourke98] chapter 6 [Matoušek] Lecture.

END