cse 4101/5101

38
EECS 4101/5101 Prof. Andy Mirzaian

Upload: jolie

Post on 23-Feb-2016

71 views

Category:

Documents


0 download

DESCRIPTION

CSE 4101/5101. Prof. Andy Mirzaian. Line Segments Intersections. Line Segments Intersections Thematic Map Overlay. Photos courtesy of ScienceGL. References:. [CLRS] chapter 33 [M. de Berge et al ’00] chapter 2 [Preparata-Shamos’85] chapter 7 [O’Rourke’98] chapter 7. Applications : - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CSE 4101/5101

EECS 4101/5101

Prof. Andy Mirzaian

Page 2: CSE 4101/5101

Line Segments Intersections Thematic Map Overlay

Photos courtesy of ScienceGL

2

Page 3: CSE 4101/5101

References: • [CLRS] chapter 33• [M. de Berge et al ’00] chapter 2• [Preparata-Shamos’85] chapter 7• [O’Rourke’98] chapter 7

Applications:

• Graphics: hidden line/surface removal• GIS: Geographic Information Systems• Cartography • VLSI circuit layout• Pattern recognition• Optimization: Linear Programming• Arrangement of lines, planes, hyper-planes• Visibility, kernels, etc.

3

Page 4: CSE 4101/5101

Line Segments Intersection ProblemGiven a set L={ l1,l2, … , ln } of n line segments in the plane,report all pair-wise intersections in L.(Modes: reporting, counting or disjointness.)

• Naïve approach: check every pair in L in O(n2) time.

• Can we make this output sensitive?

• Suppose there are a total of R intersecting pairs to report, where 0 R (n2).

O(R + n log n) time is achievable for reporting mode. O(n log n) time for counting & disjointness mode.

4

Page 5: CSE 4101/5101

Special Case: rectilinear LAssume segments in L are vertical (blue) or horizontal (red),and each intersection is between a red-blue pair.

e.g., in VLSI

5

Page 6: CSE 4101/5101

Special Case: rectilinear LAssume segments in L are vertical (blue) or horizontal (red),and each intersection is between a red-blue pair.

Plane Sweep Method: vertical sweep-line moving left-to-right. • Active segments: horizontal segments that intersect the sweep-line.• Sweep event schedule: x-sorted segment endpoints (2 per red, 1 per blue).• Sweep Status: y-ordering of the active horizontal segments maintained

in an efficient dictionary D.

Sweep-line

b

a

c

d

eb

a

d

D

6

Page 7: CSE 4101/5101

Special Case: rectilinear LAssume segments in L are vertical (blue) or horizontal (red),and each intersection is between a red-blue pair.

Plane Sweep Method: vertical sweep-line moving left-to-right. • Active segments: horizontal segments that intersect the sweep-line.• Sweep event schedule: x-sorted segment endpoints (2 per red, 1 per blue).• Sweep Status: y-ordering of the active horizontal segments maintained

in an efficient dictionary D.

Sweep-line

b

a

c

d

eb

a

d

cD

7

Page 8: CSE 4101/5101

Special Case: rectilinear LAssume segments in L are vertical (blue) or horizontal (red),and each intersection is between a red-blue pair.

Plane Sweep Method: vertical sweep-line moving left-to-right. • Active segments: horizontal segments that intersect the sweep-line.• Sweep event schedule: x-sorted segment endpoints (2 per red, 1 per blue).• Sweep Status: y-ordering of the active horizontal segments maintained

in an efficient dictionary D.

Sweep-line

b

a

c

d

eb

a

d

cD

e1

e2

e1

e2

8

Page 9: CSE 4101/5101

Special Case: rectilinear LAssume segments in L are vertical (blue) or horizontal (red),and each intersection is between a red-blue pair.

Plane Sweep Method: vertical sweep-line moving left-to-right. • Active segments: horizontal segments that intersect the sweep-line.• Sweep event schedule: x-sorted segment endpoints (2 per red, 1 per blue). • Sweep Status: y-ordering of the active horizontal segments maintained

in an efficient dictionary D. • Computational Complexity:

O(n) space O(R + n log n) time - reporting mode O(n log n) time - counting or disjointness modes.

Sweep-line

b

a

c

d

e

9

Page 10: CSE 4101/5101

Algorithm Rectilinear-Intersection-Report(L) Q {x-sorted end-points of segments in L} Sweep Schedule D Sweep Status for each event (p,s)Q in sorted order do O(n) iterations

if p is left-end of horizontal s then Insert (s,D) O(log n) timeif p is right-end of horizontal s then Delete (s,D) O(log n) time if s is vertical then RangeReport (s,D) O(Rs+ log n) time

end

RangeReport (s,D)O(Rs+ log n) time

Rs = # with s

D

s1

s2

s

s2s1

O(log n) forcounting ordisjointness

test

Total time = O( n log n + s(Rs+ log n) ) = O(R + n log n).

10

Page 11: CSE 4101/5101

General Case Bentley-Ottman [1979], “Algorithms for reporting and counting geometric intersections,” IEEE Trans. Comput. C-28:643-647.

O((R+n) log n) reporting time & O(n) space.

Improved by:

Balaban [1995], “An optimal algorithm for finding segments intersections,”Proc. SoCG, pp:211-219.

O(R + n log n) reporting time & O(n) space.E

A

B

C

D

E

A BA

CB

AD

CB

A

EC

BA

D

EC

AD

EA

CD

EA

DC

E

AD

ED

swee

p-li n

e

Sweep status:

See also AAW

11

Page 12: CSE 4101/5101

Bentley-OttmanData Structures:

• Sweep Status D: an efficient dictionary to maintain the linear order of active segments in the order they intersect the sweep-line.

• Sweep Schedule Q: a priority queue of sweep events (priority=x-coordinate).

segments left/right end points Event points = pair-wise segments intersection points

Book-keeping: a constant number of two-way pointers between

each segment and its contributed events in Q.

12

Page 13: CSE 4101/5101

Bentley-OttmanTemporary assumption: No two events have the same priority. (lexicographic)

FACT: Let p = li lj be an intersection event, and q its predecessor event. Just after q is processed, both li and lj are active and adjacent in the linear ordering of the sweep status D.

Proof: The shaded region must be empty of segments.

pq

li

lj

Corollary: Every intersection event can eventually be detected and inserted into Q before the sweep-line gets past it.

Proof: Each time the sweep status D changes, check its affected adjacent active segment pairs to see if they intersect to the right of the sweep-line.

13

Page 14: CSE 4101/5101

Algorithm Bentley-Ottman(L) O( (R+n) log n ) time

Q {the 2n end-points of segments in L} n=|L| D while Q do 2n+R iterations e DeleteMin(Q) O(log n) time ProcessEvent(e) O(log n) time end

Time = O( (R+n) log n ) Space used:

|D| = O(n) size

O(R+n) without “trimming” (see next slide)|Q| =

O(n) with “trimming”

14

Page 15: CSE 4101/5101

Procedure ProcessEvent(e) O(log n ) time

1. If e is left end-point of segment s thenInsert (s,D); A Above(s,D); B Below(s,D)Insert As and/or Bs into Q if they are “future” eventsTrim: Delete AB from Q if it’s there

2. If e is right end-point of segment s thenA Above(s,D); B Below(s,D); Delete(s,D)Insert AB into Q if it’s a “future” event

3. If e is si sj then { suppose si = Above(sj,D) }Interchange(si,sj,D); A Above(sj,D); B Below(si,D)Insert Asj and/or Bsi into Q if they are “future” eventsTrim: Delete Asi and Bsj from Q if they are thereREPORT (e = si sj)

end

B

A

es

B

A

es

B

A

esi

sj

15

Page 16: CSE 4101/5101

How to search in Dictionary D• D maintains the y-ordering of the active line segments along the sweep-line.• Each item in D is a line segment, with no explict “key”.• How do we search in D for an event point e?• Ask “is e vertically above/below node segment?”,

then go to right/left subtree accordingly.

B

A

e

C

D

E

EC

DA

B

Search path of e in the dictionary

sweepline

16

Page 17: CSE 4101/5101

Generalizations of Bentley-Ottman edges with common end-points edge – vertex intersections

Trapzoidization (or Vertical Visibility Map)

These can be done during the plane-sweep without increase in computational complexity.

17

Page 18: CSE 4101/5101

Sweep technique for intersection of other kinds of objects

CONVEX NON-CONVEXA is above B Is A above B?

A

B

A

B

18

Page 19: CSE 4101/5101

Intersection of two Convex Sets

Fact 0: Intersection of any two convex sets is convex (possibly empty).

Examples of convex sets: Lines, line segments, convex polygons, half-planes, etc.Line: ax + by = cHalf-plane: ax + by c (or ax + by c )

ax + by = c

ax + by cax + by c

A

B

PQ

Proof: A,B [ (A,B P Q) (A,BP)(A,BQ) (AB P) (AB Q) (AB PQ) ].

19

Page 20: CSE 4101/5101

Intersection of two Convex Polygons

Let P and Q be convex polygons with, respectively, n and m vertices.Consider the convex (possibly empty) polygon R = PQ.

Fact 1: R has at most n+m vertices.

Proof: Let e be any edge of P. e’ = eQ is convex, hence, either empty, a single vertex of Q,or a sub-segment of e. In the latter case e’ is an edge of R.(Similarly, with e an edge of Q and e’ = eP.)Each edge e of P or Q can contribute at most one such edge e’ to R.P and Q have n and m edges, respectively. Hence, R can have at most n+m edges.

20

Page 21: CSE 4101/5101

Intersection of two Convex PolygonsFact 2: R = PQ can be computed in O(n+m) time.

Proof: Use the plane-sweep method. The upper and lower chains of P and Q are x-monotone (from leftmost to rightmost vertex each). In O(n+m) time, merge these 4 x-sorted vertex-lists to obtain the n+m vertices of P and Q in x-sorted order. This forms the sweep-schedule. These n+m vertical sweep-lines partition the planeinto n+m-1 vertical slabs. The intersection of each slab with P or Q is a trapezoid.The two trapezoids within a slab can be intersected in O(1) time. Hence, we can obtain PQ in O(n+m) time.

slab

21

Page 22: CSE 4101/5101

Intersection of n Half-Planes

Problem: Given n half-planes H1, H2, … , Hn, compute their intersection R = H1 H2 … Hn .

Input: Hi: ai x + bi y ci , i = 1..nOutput: convex polygon R (empty, bounded or unbounded).

R

22

Page 23: CSE 4101/5101

Intersection of n Half-PlanesProblem: Given n half-planes H1, H2, … , Hn, compute their intersection

R = H1 H2 … Hn .

Divide-&-Conquer in O(n log n) time: (Use Facts 1 and 2.)

(H1 … H n/2 ) (H n/2 +1 … Hn )Convex P, |P| n/2

T(n/2) timeConvex Q, |Q| n/2

T(n/2) time

Convex R = PQ, |R| |P|+|Q| nO(n) time

T(n) = 2 T(n/2) + O(n) = O(n log n).

23

Page 24: CSE 4101/5101

Linear Programming

24

Page 25: CSE 4101/5101

maximize c1 x1 + c2 x2 + … + cd xd

subject to:

a11 x1 + a12 x2 + … + a1d xd b1

a21 x1 + a22 x2 + … + a2d xd b2

an1 x1 + an2 x2 + … + and xd bn

Linear Programming

LP is a mathematical optimization problem:Given reals (aij), (bi), (cj), for i=1..n, j=1..d,Find reals (xj), j=1..d, to

objective function

constraints

25

Page 26: CSE 4101/5101

References:

Applications of LP:

• Management science (Operations Research).• Engineering, technology, industry, commerce, economics.• Efficient resource allocation:

– Airline transportation,– Communication network – opt. transmission routing,– Factory inventory/production control,– Fund management, stock portfolio optimization.

• Approximation of hard optimization problems.• …

• [CLRS] chapter 29• books on optimization listed on the course web page

26

Page 27: CSE 4101/5101

Example in 2D

subject to:

maximize

8.10443352643

xx

yxyxyx)1(

)2(

)3(

)4(

(5)

(1) (2)

(3)

(4)

x

y

(5)

feasibleregion

Optimum x=5/3, y=1/4x + y

x+y =

Objective -level x + y = . Increase :

27

Page 28: CSE 4101/5101

Example in 3D

subject to:

maximize zOptimum

(x,y,z)=(0,0,3)

x

y

z

0002

3

zyxy

zyx

28

Page 29: CSE 4101/5101

2D Linear Programming

maximize c1 x + c2 y

subject to: a11 x + a12 y b1

a21 x + a22 y b2

an1 x + an2 y bn …

objective function

n half-planes

2D LP is a mathematical optimization problem:Given reals (aij), (bi), (cj), for i=1..n, j=1,2,Find a point (x,y) in the plane to

29

Page 30: CSE 4101/5101

2D Linear Programming

Fy

x

Objective value = c1 x + c2 yFeasible region F

increasing

optimummax = c 1 x + c 2 y

30

Page 31: CSE 4101/5101

2D Linear Programming

• Feasible region F is the intersection of n half-planes.

• F is possibly empty, bounded or unbounded convex polygon with n

vertices.

• F can be obtained in O(n log n) time by divide-&-conquer.

• If F is empty, then LP is infeasible.

• Otherwise, we can check its vertices, and its possibly up to 2 unbounded

edges, to determine the optimum.

• The latter step can be done by binary search in O(log n) time.

• If objective changes but constraints do not, we can update the optimum in

only

O(log n) time. (We don’t need to start from scratch).

• Megiddo’s prune-&-search technique solves 2D LP in O(n) time.To learn more about LP see my CSE6114 Lecture Slide on LP here.

31

Page 32: CSE 4101/5101

An Art Gallery ProblemWe are given the floor-plan of an art gallery (with opaque walls) represented by a simple polygon P with n vertices. Is it possible to place a single point camera guard (with 360 vision) in the gallery so that it can “see” every point inside the gallery? The set of all such points is called the “Kernel” of P. If Kernel(P) is not empty, then P is called a “star” polygon.

P

32

Page 33: CSE 4101/5101

An Art Gallery ProblemWe are given the floor-plan of an art gallery (with opaque walls) represented by a simple polygon P with n vertices. Is it possible to place a single point camera guard (with 360 vision) in the gallery so that it can “see” every point inside the gallery? The set of all such points is called the “Kernel” of P. If Kernel(P) is not empty, then P is called a “star” polygon. Kernel(P) is the intersection of n half-planes defined by P’s edges.

P

33

Page 34: CSE 4101/5101

An Art Gallery ProblemWe are given the floor-plan of an art gallery (with opaque walls) represented by a simple polygon P with n vertices. Is it possible to place a single point camera guard (with 360 vision) in the gallery so that it can “see” every point inside the gallery? The set of all such points is called the “Kernel” of P. If Kernel(P) is not empty, then P is called a “star” polygon. Kernel(P) is the intersection of n half-planes defined by P’s edges. Kernel(P) can be computed in O(n log n) time by divide-&-conquer.

P

It can be computed in O(n) time by a careful incremental method that scans the edges of P in order around its boundary. How?

34

Page 35: CSE 4101/5101

Exercises

35

Page 36: CSE 4101/5101

1. Nested Circles: We are given a set C = {C1 , ... , Cn} of n circles in the plane. Each circle is given by the xy-coordinates of its center and its radius. One of these circles is the bounding circle and encloses the remaining n -1 circles in C. All circles in C have disjoint boundaries. So, for any pair of circles Ci and Cj in C, either they are completely outside each other, or one encloses the other. Therefore, we may have several levels of nesting among these circles. (See Figure 1(a) below.) We say Ci is immediately enclosed by Cj, if Cj is the smallest circle that encloses Ci. This relationship corresponds to the parent-child relationship in the Nesting Tree of C. (See Figure 1(b) below.) The problem is: given C, construct its Nesting Tree by parent pointers, that is, output the array p[1.. n] such that p[i] = j means C i is immediately enclosed by Cj .

(a) Briefly describe a simple O(n2) time algorithm to solve the problem.(b) Design and analyze an O(n log n) time algorithm to solve the problem.

36

Page 37: CSE 4101/5101

2. We are given a set T of n triangles and a set P of n points, all in the plane. The triangles in T have disjoint boundaries, but some triangles may enclose some others. There may be several nested levels of such enclosures. Design and analyze an O(n log n) time algorithm that reports all points in P that are outside all triangles in T.

3. Design efficient plane-sweep algorithms to decide whether a given set S of n objects from a certain object class is pair-wise disjoint for the following cases:(a) Objects are circular disks. (A disk includes the interior.)(b) Objects are circles. (A circle does not include the interior.)(c) Objects are axis-parallel rectangular areas.

4. We are given n axis-parallel rectangular areas in the plane. Assume the plane background is white and the given rectangle areas are painted blue. Design an O(n log n) time algorithm to compute the total blue area.

5. We are given two simple polygons P and Q with n and m vertices, respectively.(a) Design and analyze an efficient algorithm to test whether P is completely inside Q.(b) Show an O(n+m) time solution if in addition we know Q is convex.

6. Show the kernel of a given simple polygon can be computed in linear time.

37

Page 38: CSE 4101/5101

END

38