VOOZH about

URL: https://www.geeksforgeeks.org/dsa/voronoi-diagram/

⇱ Voronoi Diagram - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Voronoi Diagram

Last Updated : 16 Feb, 2024

A Voronoi diagram known as a Voronoi tessellation or Voronoi partition is a geometric structure that divides a given space into the regions based on the distance to a set of the points called "seeds" or "sites". In this diagram, each region represents the area that is closest to a specific seed compared to any other seed in set. Voronoi diagrams have applications in the various fields such as computer graphics, geographical information and more.

Algorithm for Constructing Voronoi Diagram:

One commonly used algorithm for constructing Voronoi diagrams is the "Fortune's Algorithm" which operates in O(n log n) time where n is the number of input seeds.

  • Initialization: Begin by sorting the seed points along a line or plane using the appropriate sorting algorithm such as Quicksort or Merge Sort.
  • Event Queue: To Create a priority queue to manage events. Events can be either site events or circle events (circles formed by three consecutive seed points). Initially the event queue contains site events for the each seed point.
  • Sweep Line: The Introduce a vertical sweep line that moves from the left to right across the diagram. As the sweep line encounters events and it processes them updating the Voronoi diagram.
  • Beach Line: The Maintain a beach line which is a set of the parabolic arcs that represent the boundaries between Voronoi regions.
  • Event Processing: As the sweep line encounters a site event a new arc is inserted into the beach line. As the sweep line encounters a circle event the corresponding arc is removed from beach line.
  • Beach Line Adjustment: The beach line is adjusted based on the events. When a new arc is added due to a site event and it splits an existing arc.
  • Cell Creation: As the sweep line progresses Voronoi cells are constructed based on beach line's configuration.
  • Output: The Voronoi diagram is the constructed as the sweep line completes its traversal.

Consider a set of seed points in a 2D plane. The blue lines represent the Voronoi edges and each shaded region represents a Voronoi cell corresponding to the seed point.

👁 Screenshot-2023-08-31-210714

the sweep line moves from the left to right and beach line adjusts new Voronoi edges are formed and Voronoi cells are created. The algorithm processes site events and circle events to determine the Voronoi structure.

Voronoi Diagram Using Sweep Line Algorithm:

The Sweep Line algorithm constructs the Voronoi Diagram by the sweeping a vertical line across the plane. As the sweep line encounters events like Voronoi vertices and cell intersections and it updates the Voronoi regions.

Below is the implementation of voronoi diagram using sweep line:


Output
Voronoi Region #1: Site (0, 0)

Voronoi Region #2: Site (0, 0)

Voronoi Region #3: Site (0, 0)

Voronoi Region #4: Site (0, 0)

Time Complexity: O(N log N)
Space Complexity: O(N)

Comment