14 views

Uploaded by Bhudev Mahato

- Content for Programming Interviews Exposed, 3rd Edition
- AVL Tree Program
- jhtp7_SSM_17
- Mary Austine P
- 2014 - Del Et Al. - Improving Circuit Performance With Multispeculative Additive Trees in High-level Synthesis
- A Survey on Various Web Template Detection and Extraction Methods
- Dat Structure Homework3
- 04-dynamic-programming.pdf
- abs
- 370_2617318598.pdf
- 1. Granularity of Locks and Degrees of Consistency in a Shared Database - Gray
- data structure
- 20160829_Divide_and_Conquer.pdf
- acml09
- discrete math mix
- 1 McTaggart Rancourt Project3Writeup
- Cohensutherland Using Vc++
- Final Exam Ver2.9
- documentation
- Tree Data Struc

You are on page 1of 67

Is this the lower bound of the problem? Is this good for our problem? Why?

Even there are no intersections, we will spend O(n2) time

Desiderata output (intersection) sensitive Desiderata: Observation: Segments that are close Observation together are the candidates for intersection

How do you define two segments are close or far away???

Can distance of two segments tell you anything?

Closeness of Segments

Draw a line l (horizontal line) find intersections between segments and l, Order segments from left to right according to the intersecting point on l Now, we know which segments are close to each ( w.r.t l )

s1 s2 s3 s4 s5 s6 s8 l

s7

Plane Sweep

Now if we move the line up and down

we should reveal the relationships (closeness) of the line segment across the plane How do you compute the intersections between l

and segments efficiently? Do you have to compute the intersections all the time when l sweeps?

s1

s2 s s4 3

s5

s6 s8 s7

Plane Sweep

How do you compute the intersections between l and segments efficiently?

Project the interval to Y-axis and build a data structure (interval tree) (?) y

Plane Sweep

Do you have to compute the intersections all the time when l when move up and down?

No! The intersections only change at (Events):

End points intersections

s1

s2 s s4 3

s5

s6 s8 s7

event point l : sweep line

Maintain a data structure T so the intersecting segments are sorted from left to right

Plane Sweep

Status of l : (insert S6 to T)

S6

s2 s 3 s5 s6 s8 s7 l

s1

Plane Sweep

Status of l : (insert S5 to T)

S5S6

s1 s2 s3 s5 s6 s8 s7 l

Plane Sweep

Status of l : (insert S2 to T)

S2S5S6

s1 s2 s3 s5 s6 s8 s7 l

Plane Sweep

Status of l : (insert S3 to T)

S2S3S5S6

s1 s2 s3 s5 s6 s8 s7 l

Plane Sweep

Status of l : (insert S1 and S8 to T)

S1S2S3S5S6S8

s1 s2 s3 s5 s6 s8 s7 l

Plane Sweep

Status of l : (delete S6 to T)

S1S2S3S5S8

s1 s2 s3 s5 s6 s8 l s7

Plane Sweep

Status of l : (swap S1 and S2 in T)

S2S1S3S5S8

s1 s2 s3 s5 s6 s8 s7 l

Plane Sweep

Status of l : (swap S3 and S5 in T)

S2S1S5S3S8

s1 s2 s3 s5 s6 s8 s7 l

Plane Sweep

Status of l : (add S7 to T)

S2S1S5S3S7S8

s1 s2 s3 s5 s6 s8 s7 l

Plane Sweep

Status of l : (swap S7 S8 in T)

S2S1S5S3S8S7

s1 s2 s3 s5 s6 s8 s7 l

Plane Sweep

Status of l : (delete S1 , S8 from T)

S2S5S3S7

s1 s2 s3 s5 s6 s8 s7 l

Plane Sweep

Status of l : (delete S7 from T)

S2S5S3

s1 s2 s3 s5 s6 s8 s7 l

Plane Sweep

Status of l : (delete S2 ,S5 ,S3 from T)

s1 s2 s3 s5 s6 s8 s7 l

Sketch 1

Create an event queue Q and add end points of the segments from top to bottom to the event queue Create a horizontal sweep line l and maintain a sorted list T Repeat until no events in Q

e Q.pop() Place l at e Find the segments intersecting the sweep line l and store them in T For each pair of adjacent segments in T

Check intersection Add intersection to Q

To include the idea of being close in the horizontal direction, only test segments that are adjacent in the horizontal direction - Only test each with ones to its left and right New status: ordered sequence of segments New event points: endpoints and intersects

l Sj Sk Sl Sm

Plane Sweep

Status of l : (insert S6 to T)

s1 c s2 e s3

b h

s g 5

j

s6

i k

s8

o

s7n

m

Q={i,g,c,e,a,k,j,n,b,m,o,d,h,f}

Plane Sweep

Status of l : (insert S6 to T)

S6

s g 5

j b h

s1

s2 e s

s6

i k

s8

o

s7n

m

Q={g,c,e,a,k,j,n,b,m,o,d,h,f}

Plane Sweep

Status of l : (insert S5 to T)

S5S6

s g 5

j b h

s1 c s2 e s3

s6

i k

s8

o

s7n

m

Q={c,e,a,k,j,n,b,m,o,d,h,f}

Plane Sweep

Status of l : (insert S2 to T)

S2S5S6

s g 5

j b h

s1 c s2 e s3

s6

i k

s8

o

s7n

m

Q={e,a,k,j,n,b,m,o,d,h,f}

Plane Sweep

Status of l : (insert S3 to T)

S2S3S5S6

s g 5

j b h

s1 c s2 e s3

s6

i k

s8

o

s7n

m

Q={a,k,j,n,b,m,o,d,h,f}

Plane Sweep

Status of l : (insert S1 and S8 to T)

S1S2S3S5S6S8 s6

i k j q d b h f

s1 c s2 e s3

p

s g 5

s8

o

s7n

m

Q={j,p,q,n,b,m,o,d,h,f}

Plane Sweep

Status of l : (delete S6 to T)

S1S2S3S5S8

s g 5

j q d b h f

s1 c s2 e s3

p

s6

i k

s8 l

o

s7

n m

Q={p,q,n,b,m,o,d,h,f}

Plane Sweep

Status of l : (swap S1 and S2 in T)

S2S1S3S5S8 s6

i k j q d b h f

s1 c s2 e s3

p

s g 5

s8 l

o

s7n

m

Q={q,n,b,m,o,d,h,f}

Plane Sweep

Status of l : (swap S3 and S5 in T)

S2S1S5S3S8 s6

i k j q d b h f

s1 c s2 e s3

p

s g 5

s8 l

o

s7n

m

Q={n,b,m,o,d,h,f}

Plane Sweep

Status of l : (add S7 to T)

S2S1S5S3S7S8 s6

i k j q d b h f

s1 c s2 e s3

p

s g 5

s8 l

o

s7n

m

Q={r,b,m,o,d,h,f}

Plane Sweep

Status of l : (swap S7 S8 in T)

S2S1S5S3S8S7 s6

i k j q d b h f

s1 c s2 e s3

p

s g 5

s8 l

o

s7n

m

Q={b,m,o,d,h,f}

Plane Sweep

Status of l : (delete S1 , S8 from T)

S2S5S3S7 s6

i k j q d b h f

s1 c s2 e s3

p

s g 5

s8

o

s7n

m

Q={o,d,h,f}

Plane Sweep

Status of l : (delete S7 from T)

S2S5S3 s6

i k j q d b h f

s1 c s2 e s3

p

s g 5

s8

o

s7n

m

Q={d,h,f}

Plane Sweep

Status of l : (delete S2 ,S5 ,S3 from T)

s1 c s2 e s3

p q b h

s g 5

j

s6

i k

s8

o

s7n

m

Q={}

Sketch 1

Whats the problem of this algorithm?

Create an event queue Q and add end points of the segments from top to bottom to the event queue Create a horizontal sweep line l and maintain a sorted list T Repeat until no events in Q

e Q.pop() Place l at e Find the segments intersecting the sweep line l and store them in T For each pair of adjacent segments in T No need to

Check intersection Add intersection to Q

check

all pairs!

Sketch 2

Create an event queue Q and add end points of the segments from top to bottom to the event queue Create a horizontal sweep line l and maintain a sorted list T Repeat until no events in Q

e Q.pop() Place l at e If e is an upper point of a segment s

Add s to T Check intersection between s and s left and right segments in T

Remove s from T Check intersection between s left and right segments in T

Reorder S in T accordingly Check the leftmost segment with the segment on its left Check the rightmost segment with the segment on its right

Plane Sweep

Status of l : (insert S6 to T)

S6

s g 5

j b h

s1

s2 e s

s6

i k

s8

o

s7n

m

Q={g,c,e,a,k,j,n,b,m,o,d,h,f}

Plane Sweep

Status of l : (insert S5 to T)

S5S6

Check intersection: S5S6 s g 5

j b h

s1 c s2 e s3

s6

i k

s8

o

s7n

m

Q={c,e,a,k,j,n,b,m,o,d,h,f}

Plane Sweep

Status of l : (insert S2 to T)

S2S5S6

Check intersection: S2S5 s g 5

j b h

s1 c s2 e s3

s6

i k

s8

o

s7n

m

Q={e,a,k,j,n,b,m,o,d,h,f}

Plane Sweep

T - Status of l : (insert S3 to T)

S2S3S5S6

Check intersection: S3S5 Check intersection: S3S2 s g 5

j b h

s1 c s2 e s3

s6

i k

s8

o

s7n

m

Q={a,k,j,n,b,m,o,d,h,f}

Plane Sweep

T - Status of l : (insert S1 and S8 to T)

S1S2S3S5S6S8

Check intersection: S1S2 Check intersection: S8S6 s g 5

j q d b h f

s1 c s2 e s3

p

s6

i k

s8

o

s7n

m

Q={j,p,q,n,b,m,o,d,h,f}

Plane Sweep

T - Status of l : (delete S6 to T)

S1S2S3S5S8

Check intersection: S5S8 s g 5

j q d b h f

s1 c s2 e s3

p

s6

i k

s8 l

o

s7

n m

Q={p,q,n,b,m,o,d,h,f}

Plane Sweep

T - Status of l : (swap S1 and S2 in T)

S2S1S3S5S8

Check intersection: S1S3 s g 5

j q d b h f

s1 c s2 e s3

p

s6

i k

s8 l

o

s7n

m

Q={q,n,b,m,o,d,h,f}

Plane Sweep

T - Status of l : (swap S3 and S5 in T)

S2S1S5S3S8

Check intersection: S1S5 Check intersection: S3S8 s g 5

j q d b h f

s1 c s2 e s3

p

s6

i k

s8 l

o

s7n

m

Q={n,b,m,o,d,h,f}

Plane Sweep

T - Status of l : (add S7 to T)

S2S1S5S3S7S8

Check intersection: S7S3 Check intersection: S7S8 s g 5

j q d b h f

s1 c s2 e s3

p

s6

i k

s8 l

o

s7n

m

Q={r,b,m,o,d,h,f}

Plane Sweep

T - Status of l : (swap S7 S8 in T)

S2S1S5S3S8S7

Check intersection: S8S3 s g 5

j q d b h f

s1 c s2 e s3

p

s6

i k

s8 l

o

s7n

m

Q={b,m,o,d,h,f}

Plane Sweep

T - Status of l : (delete S1 , S8 from T)

S2S5S3S7

Check intersection: S2S5 s g 5

j q d b h f

s1 c s2 e s3

p

s6

i k

s8

o

s7n

m

Q={o,d,h,f}

Plane Sweep

T - Status of l : (delete S7 from T)

S2S5S3

s g 5

j q d b h f

s1 c s2 e s3

p

s6

i k

s8

o

s7n

m

Q={d,h,f}

Plane Sweep

T - Status of l : (delete S2 ,S5 ,S3 from T)

s g 5

j q d b h f

s1 c s2 e s3

p

s6

i k

s8

o

s7n

m

Q={}

Horizontal lines Overlapping line segments Multiple line segments intersect at one single point

S1 S4 S7 S5 S3 S8 l

S3 S2

S1

HandleEventPoint (p)

1. Let U(p) be set of segments whose upper end point is p 2. Search in T for set S(p) of all segments that contains p; they are adjacent in T. Let L(p) S(p) be the set of segments whose lower endpts in p and C(p) S(p) be the set of segments that contains p in its interior 3. If L(p) See C(p) contains more than 1 segment U(p) your textbook for detail 4. Most ofReportare just some work on bookkeeping C(p) then these p as an intersect with L(p), U(p) and 5. Delete segments in L(p) C(p) from T 6. Insert segments in U(p) C(p) into T. Order segments in T according to their order on sweep line just below p. A horizontal one comes last among all containing p.

Data Structure

Type: Event queue that stores events Operations

remove next event and return it to be treated among 2 events with the same y-coordinate, the one with smaller x-coordinate is returned (left-to-right priority order) allow for insertions & check if it is already there allow 2++ event points to coincide (ex) two upper end points coincide

Define an order on event points, according to which they will be handled Store the event points in a balanced binary search tree T according to their orders

both fetching & insertion takes O(log m) time, where m is the number of events

the left-to-right order of segments on the line l <=> the left-to-right order of leaves in T segments in internal nodes guide search each update and search takes O(log m)

Status Structure, T

Si Sj Sk Sl Sm l

Sk

T

Si

Si Sj Sl S S

Sl Sm

S1 S2 S3 S4 S3 S1

S4 S7 S5

T

S7

S5

T

S3 S7 S7

S3 S8

S1 S2 S1 S8

S8

S7

S5

S4

S1

S3

l

S1

Algorithm Analysis

Important property

All the intersections above the sweep line must be found

see the proof in the textbook

Algorithm Analysis

Correctness: Does the algorithm find all intersections? (sketch)

Assume there is an intersecting point p that is not found The segments intersecting at p never become adjacent when the line sweeps down There is no event above p, which makes the segments adjacent However, this is not possible.

Algorithm Analysis

Let S be a set of n segments in a plane All intersections in S can be reported in

O(n log n + I log n) time O(n) space where I is the number of intersection points

Doubly-Connected Edge List Doubly 3 records: vertices, faces and half-edges Vertex:

coordinates(v) a ptr to a half-edge

Face:

OuterComponent(f): outer boundary InnerComponent(f): holes boundaries

Edge:

a ptr to Origin(e) a ptr to a twin-edge ptrs to Next(e) & Prev(e) edges its left IncidentFace(e)

OuterComponent(f): e7 InnerComponent(f): e11

v3

e6 e4 e5 e7

e11

v8

e10 e3

v2

f3 v7 f2

v6

e8 e9

v5

e1:

a ptr to Origin(e): v3 a ptr to a twin-edge: e2 ptrs to Next(e) & Prev(e) edges: e2 and e9 its left IncidentFace(e): f1

f1

e2

v3 e1

v1

Doubly-Connected Edge List Doubly How do you find all incident edges of f1 ? How do you find all incident vertices of e4? How do you find all incident edges of v3 ? How do you find all incident faces of v3 ?

e4

v3

e6 e5 e7

e11

v8

e10 e3

v2

f3 v7 f2

v6

e8 e9

v5

f1

e2

v3 e1

v1

Application 3

Polygon intersection

Let P1, P2 be two polygons, check if they collide with each other in O(n logn) time

P1

P1 P2 no collision

P2 collision

Application 4

Boolean Operations

Let P1, P2 be two polygons with n1 and n2 vertices respectively; and let n = n1 + n2 Their Boolean operations (intersection, union, and difference) can each be computed in O(n log n + k log n) time, where k is the complexity of the output

Application 4

Boolean Operations

P-Q PQ PQ

Q P

Conclusion

Line segments intersection

Line sweep paradigm Output sensitive algorithm

Applications

GIS map overlay (lines, regions) 2D collision detection and Boolean operations 3D morphing

- AVL Tree ProgramUploaded byapi-26548538
- Content for Programming Interviews Exposed, 3rd EditionUploaded byzarickzheng
- jhtp7_SSM_17Uploaded byFelipe Robles
- Mary Austine PUploaded bypsylocke_shanta201
- 2014 - Del Et Al. - Improving Circuit Performance With Multispeculative Additive Trees in High-level SynthesisUploaded byHassaan Ahmad
- Dat Structure Homework3Uploaded byjitenderthakur490
- 04-dynamic-programming.pdfUploaded byNilay Pochhi
- A Survey on Various Web Template Detection and Extraction MethodsUploaded byIJSTR Research Publication
- absUploaded byShivank Agarwal
- 1. Granularity of Locks and Degrees of Consistency in a Shared Database - GrayUploaded byPanos Koukios
- data structureUploaded byAhmed Khan
- 370_2617318598.pdfUploaded byRohit Bansaal
- 20160829_Divide_and_Conquer.pdfUploaded byFyyrree
- acml09Uploaded byKevin Mondragon
- discrete math mixUploaded byAnkit Mittal
- 1 McTaggart Rancourt Project3WriteupUploaded byMatthewMcT
- Cohensutherland Using Vc++Uploaded byUjjwal Agrawal
- Final Exam Ver2.9Uploaded byBlooddy Moon
- documentationUploaded byapi-285553674
- Tree Data StrucUploaded byLemia malabanan
- a13-MasunagaUploaded byHòa Nguyễn
- Unit3-DS.pdfUploaded byKarthikeyan Ramajayam
- Morton&MareelsUploaded byYashveer Takoory
- 2sharon4-2Uploaded byrobinpt
- H5-solution[www.alirezaweb.com].pdfUploaded byVahid Esmaeilzadeh
- b+treeUploaded byrebv
- Time Table Ch2Uploaded bymadan321
- Conference ProceedingUploaded byAnand Singh
- optifin - bdtUploaded byMark Narciso

- OligopolyUploaded bybalram nayak
- Psych Drug StudyUploaded byChris Facundo
- other wes moore essay- 1st draftUploaded byapi-384171515
- Zinc exhibits ideal physiological corrosion behavior for bioabsorbable stents (Bowen et al., Advanced Materials, 2013)Uploaded byPatrick Bowen
- - BiometeorologyUploaded bywicak_sp
- Sinha et al_BIOREMEDIATION OF CONTAMINATED SITES.pdfUploaded byBio Innovations
- Sample Testing PolicyUploaded bysuthacj
- Data RecoveryUploaded bytingisha
- 1999 Issue 4 - Why I Want to Join the RPCUS - Counsel of ChalcedonUploaded byChalcedon Presbyterian Church
- Akai Service ManualUploaded byDa_costa
- Linear AlkylbenzeneUploaded bymark_59
- paper2Uploaded bysuperpindonga
- second lesson planUploaded byapi-285000116
- JEE Main 2014 First Round Opening & Closing RankUploaded byaglasem
- CMS Supervisor ODBC and JDBC Data Connection DocumentationUploaded byKent Cook
- Second Language IdentityUploaded byTina Ursu
- APPROACHES TO CURRICULUM.pptxUploaded byathira
- rocket writingUploaded byapi-281447357
- TESTING THE WEAR CHARACTERISTICS OF NATURAL FIBER COMPOSITEUploaded byTJPRC Publications
- Sustainability Doc LEEDUploaded byKaushaveer Ghoora
- Piano Level Requirements by Degree for Piano MajorUploaded byspajda69
- Intercultural CommunicationUploaded byVirgilio R. Biagtan
- FXD Recloser EatonUploaded bytri
- Unit 4 TMISUploaded bySanthosh Kumar
- [Md. Rabiul Islam MMC DesignUploaded byRudra Simha
- Semester ViiUploaded byPrasanth Logaraman
- 3.1(1).pdfUploaded byDejan
- Ohm's Law Lab experimentUploaded byAira Cannille Lalic
- Zwitterion's Complete MDMA ..Uploaded byinvitacions
- Director Manager Internal Audit in Washington DC Resume Jeffrey BarnesUploaded byJeffreyBarnes2