# Voronoi Diagrams

Embed Size (px)

description

### Transcript of Voronoi Diagrams

1

Voronoi DiagramsVoronoi Diagrams

2

Voronoi DiagramVoronoi Diagram

• Input:Input: A set of points A set of points locations (locations (sitessites) in the ) in the plane.plane.

• Output:Output: A planar A planar subdivision into cells. subdivision into cells. Each cell contains all the Each cell contains all the points for which a certain points for which a certain site is the closest.site is the closest.

• Application: Nearest-neighbor queries (by point location in the diagram).

The bisector between two points is a line.

3

Voronoi DiagramVoronoi Diagram

Assume no four sites are co-Assume no four sites are co-circular.circular.

The Voronoi diagram is a planar The Voronoi diagram is a planar graph, whose vertices are graph, whose vertices are equidistant from three sites, and equidistant from three sites, and edges equidistant from two sites. edges equidistant from two sites.

The convex hull of the sites are The convex hull of the sites are those who have an unbounded cell. 7those who have an unbounded cell. 7

4

Voronoi Diagram – Naïve Voronoi Diagram – Naïve ConstructionConstruction

Construct a bisector between Construct a bisector between one site and all others.one site and all others.

A Voronoi cell is the A Voronoi cell is the intersection of all half-planes intersection of all half-planes defined by the bisectors.defined by the bisectors.

Time complexity: O(Time complexity: O(nnloglognn) for ) for eacheach cell. Total time O( cell. Total time O(nn22loglognn) )

Corollary:Corollary: Each cell in a Each cell in a Voronoi diagram is a convex Voronoi diagram is a convex polygon, possibly unbounded.polygon, possibly unbounded.

5

Voronoi DiagramVoronoi Diagram

If all the sites are colinear, the If all the sites are colinear, the Voronoi diagram will look like Voronoi diagram will look like this:this:

Otherwise, the diagram is a Otherwise, the diagram is a connected planar graph, in which connected planar graph, in which all the edges are line segments or all the edges are line segments or raysrays

6

Voronoi Diagram ComplexityVoronoi Diagram Complexity

A Voronoi diagram of A Voronoi diagram of nn distinct sites contains distinct sites contains nn cells.cells.

One cell can have complexity One cell can have complexity nn-1, but not all the cells -1, but not all the cells can.can.

• The number of vertices The number of vertices V V 22n-n-55

• The number of edges The number of edges E E 33n-n-66• The number of faces The number of faces F = nF = n

7

Voronoi Diagram PropertiesVoronoi Diagram Properties

A vertex of a Voronoi diagram is the A vertex of a Voronoi diagram is the center of a circle passing through three center of a circle passing through three sites. sites.

Each point on an edge is the center of a Each point on an edge is the center of a circle passing through two sites. circle passing through two sites.

8

Computing Voronoi DiagramsComputing Voronoi Diagrams

Plane sweep.Plane sweep. The difficulty: If we The difficulty: If we

maintain the VD of all maintain the VD of all points seen in the sweep points seen in the sweep so far – this can change so far – this can change as new points are swept.as new points are swept.

9

The Beach LineThe Beach Line

The bisector between a point The bisector between a point and a line is a parabola. The and a line is a parabola. The beachbeach lineline is the lower is the lower envelope of all the parabolas envelope of all the parabolas already seen.already seen.

Sweep the plane from above, Sweep the plane from above, while maintaining the while maintaining the invariant: the Voronoi invariant: the Voronoi diagram is correct up to the diagram is correct up to the beach line.beach line.

The beach line is an The beach line is an xx--monotone curve consisting of monotone curve consisting of parabolic arcs. The parabolic arcs. The breakpointsbreakpoints of the beach line of the beach line lie on the Voronoi edges of lie on the Voronoi edges of the final diagram.the final diagram.

Beach line

breakpoint

10

Possible events:Possible events:• Site eventSite event – The sweep line – The sweep line

meets a site. A vertical meets a site. A vertical edge (skinny parabola) edge (skinny parabola) connects the point and the connects the point and the arc above it. These events arc above it. These events are predeterminedare predetermined

• Vertex eventVertex event – An existing – An existing arc of the beach line arc of the beach line shrinks to a point and shrinks to a point and disappears, creating a disappears, creating a Voronoi vertex. Generated by Voronoi vertex. Generated by consecutive triples of consecutive triples of sites.sites.

The AlgorithmThe Algorithm

11

Beach Line Data StructureBeach Line Data Structure A binary tree of sites:A binary tree of sites:

• A leaf contains a site A leaf contains a site representing a parabolic representing a parabolic arc. arc.

• A site may appear in more A site may appear in more than one leaf.than one leaf.

• Interior nodes describe Interior nodes describe immediate neighborhood immediate neighborhood relations.relations.

• The tree must support The tree must support insertion and deletion.insertion and deletion.

P1P3

P1P2 P1P3

P3P1P2P1

P1

P3

P2

12

Complexity of the Beach LineComplexity of the Beach Line

The complexity of the The complexity of the beach line is O(beach line is O(nn). ).

The first site The first site generates one generates one parabola.parabola.

Each other site can Each other site can transform one parabola transform one parabola into three.into three.

Total: 1+(3-1)(Total: 1+(3-1)(nn-1) = -1) = 22nn-1-1

P1 P1, P2, P1

P1

P2

Beach line

13

The Event QueueThe Event Queue

Contains two types of information:Contains two types of information:• For a site event – site ID.For a site event – site ID.• For a vertex event – lowest point of the circle For a vertex event – lowest point of the circle and IDs of the triple of sites.and IDs of the triple of sites.

• Event priority: Its Event priority: Its yy coordinate. coordinate.

Events are added Events are added and deletedand deleted..

14

Creating a Vertex EventCreating a Vertex Event

Each time a new arc is created Each time a new arc is created in the beach line, check for a in the beach line, check for a possible vertex event among possible vertex event among new consecutive triples of new consecutive triples of arcs.arcs.

The circle must:The circle must:• Intersect the sweep line.Intersect the sweep line.• Contain no other points lying Contain no other points lying

above the sweep line.above the sweep line.

Note:Note: Some events may be false Some events may be false alarms (the circle contains alarms (the circle contains points below the sweep line), points below the sweep line), which will be deleted later which will be deleted later during a site event.during a site event.

False Alarm

Vertex event

15

Handling EventsHandling Events

Site eventSite event• Split arc vertically above site.Split arc vertically above site.• Delete old triples from tree.Delete old triples from tree.• Add new triples to tree.Add new triples to tree.• Delete vertex events whose three Delete vertex events whose three generators have been eliminated. generators have been eliminated.

Vertex event Vertex event • Create Voronoi vertex.Create Voronoi vertex.• Delete appropriate arc. Delete appropriate arc. • Delete old triples from tree. Delete old triples from tree. • Add new triples to tree.Add new triples to tree.

16

Complexity AnalysisComplexity Analysis

Initialization – O(Initialization – O(nnloglognn).). Number of events: O(Number of events: O(nn). Each event ). Each event requires O(log requires O(log nn) time. ) time.

Note:Note: A constant number of false alarm A constant number of false alarm vertex events are created and deleted only vertex events are created and deleted only when another real event occurs (so their when another real event occurs (so their number is also O(number is also O(nn)). )).

Total time: O(Total time: O(nnloglognn).). Space: The beach line structure and the Space: The beach line structure and the Voronoi diagram both consume linear space Voronoi diagram both consume linear space – O(– O(nn).).

17

Constructing Voronoi diagram Constructing Voronoi diagram using Divide-and-Conquerusing Divide-and-Conquer

Divide the points into two parts.Divide the points into two parts.

18

Merging two Voronoi diagramsMerging two Voronoi diagrams Merging along the piecewise linear hyperplaneMerging along the piecewise linear hyperplane

19

After mergingAfter merging

The final Voronoi diagramThe final Voronoi diagram

20

Divide-and-conquer for Voronoi diagramDivide-and-conquer for Voronoi diagram

Input:Input: A set S of n planar points. A set S of n planar points. Output:Output: The Voronoi diagram of S. The Voronoi diagram of S.

Step 1:Step 1: If S contains only one point, return. If S contains only one point, return.

Step 2:Step 2: Find a median line L perpendicular to the X- Find a median line L perpendicular to the X-axis which divides S into Saxis which divides S into SLL and S and SRR such that S such that SLL

(S(SRR) lies to the left(right) of L and the sizes of ) lies to the left(right) of L and the sizes of

SSLL and S and SRR are equal. are equal.

21

Step 3:Step 3: Construct Voronoi diagrams of S Construct Voronoi diagrams of SLL and S and SRR recursively. Denote these Voronoi diagrams by recursively. Denote these Voronoi diagrams by VD(SVD(SLL) and VD(S) and VD(SRR).).

Step 4:Step 4: Construct a dividing Construct a dividing piece-wise linear piece-wise linear hyperplanehyperplane HP which is the locus of points HP which is the locus of points simultaneously closest to a point in Ssimultaneously closest to a point in SLL and a and a point in Spoint in SRR. Discard all segments of VD(S. Discard all segments of VD(SLL) ) which lie to the right of HP and all segments which lie to the right of HP and all segments of VD(Sof VD(SRR) that lie to the left of HP. The ) that lie to the left of HP. The resulting graph is the Voronoi diagram of S.resulting graph is the Voronoi diagram of S.

(See details on the next page.)(See details on the next page.)

22

Mergeing Two Voronoi Diagrams into One Mergeing Two Voronoi Diagrams into One Voronoi DiagramVoronoi Diagram

Input:Input: (a) S (a) SLL and S and SRR where S where SLL and S and SRR

are divided by a perpendicular line L.are divided by a perpendicular line L.

(b) VD(S(b) VD(SLL ) and VD(S ) and VD(SRR ). ).

Output:Output: VD(S) where S = S VD(S) where S = SLL ∩S ∩SRR

Step 1:Step 1: Find the convex hulls of S Find the convex hulls of SLL and S and SRR, ,

denoted as Hull(Sdenoted as Hull(SLL) and Hull(S) and Hull(SRR), ),

respectively. (A special algorithm for respectively. (A special algorithm for finding a convex hull in this case will by finding a convex hull in this case will by given later.)given later.)

23

Step 2:Step 2: Find segments and Find segments and which join HULL(Swhich join HULL(SLL ) and HULL(S ) and HULL(SRR ) into a ) into a

convex hull (Pconvex hull (Paa and P and Pcc belong to S belong to SLL and and

PPbb and P and Pdd belong to S belong to SRR) Assume that ) Assume that

lies above . Let x = a, y = lies above . Let x = a, y = b, SG= and HP = b, SG= and HP = . .

Step 3:Step 3: Find the perpendicular bisector of Find the perpendicular bisector of SG. Denote it by BS. Let HP = HP {BS}. ∪SG. Denote it by BS. Let HP = HP {BS}. ∪ If SG = , go to Step 5; If SG = , go to Step 5; otherwise, go to Step 4.otherwise, go to Step 4.

dcPPbaPP

baPP

dcPPyxPP

dcPP

24

Step 4:Step 4: The ray from VD(S The ray from VD(SLL ) and VD(S ) and VD(SRR) ) which BS first intersects with must be a which BS first intersects with must be a perpendicular bisector of either or perpendicular bisector of either or for some z. If this ray is the for some z. If this ray is the perpendicular bisector of , then let perpendicular bisector of , then let SG = ; otherwise, let SG = . SG = ; otherwise, let SG = . Go to Step 3.Go to Step 3.

Step 5:Step 5: Discard the edges of VD(S Discard the edges of VD(SLL) which ) which extend to the right of HP and discard the extend to the right of HP and discard the edges of VD(Sedges of VD(SRR) which extend to the left ) which extend to the left of HP. The resulting graph is the of HP. The resulting graph is the Voronoi diagram of S = SVoronoi diagram of S = SLL S∪S∪ RR..

zxPPzyPP

zyPPzxPP

yzPP

25

Time ComplexityTime Complexity

Merging takes O(Merging takes O(nn)) time (time (This is the This is the Key!Key!))

TT((nn)) == 2 *2 * T T((n/2n/2)) ++ O(O(nn)) TT((nn)) = O(= O(n n loglog n n))

Veure:Veure: http://www.personal.kent.edu/~rmuhamma/Compgeometry/MyCG/Voronoi/DivConqVor/divConqVor.htmhttp://www.personal.kent.edu/~rmuhamma/Compgeometry/MyCG/Voronoi/DivConqVor/divConqVor.htm