How can I represent a voronoi diagram? - algorithm

I have some polygons (obstacles) within a rectangle (the borders are obstacles) and I want to find the Voronoi diagram, that means the diagram that shows the lines that have equal distance to two obstacles.
For example (created with this, please ignore the smiley and the flag):
The voronoi diagram seems to be not a set of polygons (which would be easy to represent). This one seems to have curves. It was generated by calculating for each pixel the distance to each obstacle.
I have seen this, but it has no polygons, but only points.
How can I represent such a voronoi diagram?
(By the way, I would also be happy if you had some good articles about this voronoi path planning problem ... I can only find many for points as obstacles.)

You may use the Voronoi Diagram implementation from Boost.Polygon. Maybe if you want your own implementation you can learn looking at the Boost source code.
The Boost.Polygon library provides implementation of the Voronoi
diagram data structure in 2D space. The internal representation
consists of the three arrays, that respectively contain: Voronoi cells
(represent the area around the input sites bounded by the Voronoi
edges), Voronoi vertices (points where three or more Voronoi edges
intersect), Voronoi edges (the one dimensional curves containing
points equidistant from the two closest input sites). Each of the
primitives (cell, vertex, edge) contains pointers to the other linked
primitives, so that it's always possible to efficiently traverse
Voronoi graph.
There is also this link with a visual representation from that data structure.

Related

Having the final Thiessen polygons, is it possible to find the initial set of points?

I'm trying to find a way to reverse the Voronoi algorithm.
Basically, having some connected shapes which mostly consist of triangles and squares, I'm trying to find the set of points which, by using the Voronoi algorithm would recreate the initial shapes.
Introduction.
This problem has been solved in a paper by Biedl et al. in 2013 after a partial solution by Ash and Boker in 1985. In case your Voronoi nodes are all of odd degree then the algorithm by Ash and Bolker works for you.
First of all note that there might not be the point set but many point sets all having the same Voronoi diagram you ask for. For instance, consider this picture
taken from this website. The red point set and the blue point set give you the same black Voronoi diagram. (And, by the way, the straight skeletons of the red and blue polygon coincide with the Voronoi diagrams of the point sets as well.)
Overview of the algorithm.
The rough idea is the following. Assume an oracle told you one candidate point in a Voronoi cell. Then you can mirror this point to neighboring Voronoi cells by the common edges between the neighboring cells, and keep on propagating.
But there could be troubles: The mirrored point may lie outside the neighboring cell. Also if you consider a Voronoi node and the incident cells then you can keep propagating the point around one cycle by the incident Voronoi edges, but you may not end up at the original point again.
So what the paper does is the following:
It gives sufficient and necessary conditions for your input to form a Voronoi diagram.
It tells you how to choose a valid starting point if such a point exists. Actually, it gives you set of all possible starting points.
The second part works roughly as follows: For each Voronoi cell one knows a "region" where the point has to lie by investigating the Voronoi nodes of the cell. Then take a spanning tree of the dual graph of the Voronoi diagram and choose an arbitrary root. For every cell you have a unique "mirroring path" to the "root cell". Apply the mirroring sequences of the regions mentioned above and intersect the mirror images.
The intersection is the set of all possible starting points. If it is empty then your input was not a Voronoi diagram.
Further simplification.
In case your Voronoi nodes are of odd degree then the problem is much simpler. Consider Fig-4 in the paper by Biedl et al. to find out for each node the lines where the points must lie on. If a Voronoi cell has two nodes of odd degree then you can intersect these lines and get the single possible candidate point. You can do this for every Voronoi cell.
Wouldn't finding the centroid of every triangle give you a point that is by definition, as far as possible from the other points.

Voronoi site points from Delaunay triangulation

How can one determine the exact Voronoi sites (cells/regions) from a Delaunay triangulation?
If one has an already constructed delaunay triangulation it is easy to calculate the edges of a voronoi by simply connecting adjacent circum-circle centers of every triangle.
It is also easy to determine the Voronoi points/sites because they are represented by every point of every triangle in the Delaunay triangulation.
However how do you determine that a specific voronoi site goes with a specific list of edges from a delaunay triangulation?
It seems it is simple to get one and the other as separate entities but putting them together is another challenge?
Looking at the diagram below, you can see the Delaunay triangulation along with the dual Voronoi diagram. All that I described can be pictured below for an easy reference. Ignore the green circle as that is just an artifact of this particular reference i took from the web.
If you want polygons from edges pick the midpoint of each edge and the distance to each site then sort the result and pick the first and second (when they are equal) and save them into polygons. For the borders there is of course only 1 edge. Maybe a dupe:Getting polygons from voronoi edges.
It's a bit tricky and hard to visualize. I am little stuck with the borders. Here is the original answer from Alink:How can I get a dictionary of cells from this Voronoi Diagram data?.
Each vertex in the Delaunay triangulation represents a Voronoi site. So to create the cell of a site you take one such triangle t and a vertex v in t. Now compute the Voronoi edges between v and the two remaining vertices of t. Repeat this process by traversing the triangles around v one by one. Assuming you can store the neighbourhood relation between the triangles this should at most take O(k) time, k being the number of adjacent triangles of v.
This converts the Delaunay triangulation into the Voronoi Diagram in O(n) time/space, for n sites. No sorting is required, otherwise what is the point in having the Delaunay triangulation in the first place.

How to find Voronoi diagram with specific distance function?

There are quite many algoritms for finding Voronoi diagram with Euclidean distance. However, I haven't found any algorithms other distance functions, for example, Manhattan distance (perhaps, because of no practical applications).
You can see example at Wikipedia:
https://en.wikipedia.org/wiki/Voronoi_diagram#/media/File:Manhattan_Voronoi_Diagram.svg
Manhattan Voronoi diagram also consists of polygons (but non-convex), so I guess that algorithm similar to Fortune's algorithm can be constructed.
However, using more complex distance functions, boundaries won't be polygons anymore. There will be need in different data structure and algorithm.
Are there any algorithms for finding Voronoi diagram with specific distance function (in 2D for simplicity)?
Note:
I don't need an algorithm which works with pixels, it's pretty straightforward, I need algorithm, which founds the boundaries of cells.
Note 2
Practically I need Voronoi diagram with distance function abs(dx)^3 + abs(dy)^3, however, theoretically, I'm interested how one do make an algorithm for other distance functions.
Here is how Voronoi with abs(dx)^3 + abs(dy)^3 look like. Sites are continous and their edges resemble graphs of y=x^3 (just assumption).
Most likely you can use the pixel taxi voronoi and give each polygon a different color. You can then use a pixel color test to check the bounds.

Closest-point and farthest-point Voronoi diagrams

There is a problem in my book that uses the concept of closest-point and farthest-point Voronoi diagrams to construct a minimum width annulus for a set of points (used in coordinate measurement machines).
What I need to know:
Say you construct the closest-point voronoi diagram (CPVD) and the farthest-point voronoi diagram (FPVD) on a set of points P. What is an efficient way to find the intersections between the CPVD's edges and the FPVD's edges (if you overlay the two diagrams) if you know there are only O(n) intersections.
I just can't think of a way that is faster than O(n^2). Is there some property I'm glossing over?

Find nearest edge in graph

I want to find the nearest edge in a graph. Consider the following example:
Figure 1: yellow: vertices, black: edges, blue: query-point
General Information:
The graph contains about 10million vertices and about 15million edges. Every vertex has coordinates. Edges are defined by the two adjacent vertices.
Simplest solution:
I could simply calculate the distance from the query-point to every other edge in the graph, but that would be horribly slow.
Idea and difficulties:
My idea was to use some spatial index to accelerate the query. I already implemented a kd-tree to find the nearest vertex. But as Figure 1 shows the edges incident to the nearest vertex are not necessarily the nearest to the query-point. I would get the edge 3-4 instead of the nearer edge 7-8.
Question:
Is there an algorithm to find the nearest edge in a graph?
A very simple solution (but maybe not the one with lowest complexity) would be to use a quad tree for all your edges based on their bounding box. Then you simply extract the set of edges closest to your query point and iterate over them to find the closest edge.
The extracted set of edges returned by the quad tree should be many factors smaller than your original 15 million edges and therefore a lot less expensive to iterate through.
A quad tree is a simpler data structure than the R-tree. It is fairly common and should be readily available in many environments. For example, in Java the JTS Topology Suite has a structure QuadTree that can easily be wrapped to perform this task.
There are spatial query structures which are appropriate for other types of data than points. The most general is the "R-tree" structure (and its many, many variants), which will allow you to store the bounding rectangles of your line segments. You can then search outward from your query points, examining the segments in the bounding rectangles and stopping when the nearest remaining rectangle is further than the closest line encountered so far. This could have poor performance when there are many long line segments overlapping, but for a PSLG such as you seem to have here, that shouldn't happen.
Another option is to use the segments to define a BSP tree, and scan outwards from your point to find all the "visible" lines. This in turn will be problematic if your point can see many edges.
Without proof:
You start with a constrained Delaunay Triangulation, that is a triangulation that takes the existing edges into account. E.g. CGAL or Triangle can do this. For each query point you determine which triangle it belongs to. Then you you only have to check the edges touching a corner of that triangle.
I think this should work in most cases, but there are certainly corner cases where it fails, e.g. when there are many vertices without any edge at all, so at least you have to remove those empty vertices.
You can compute the voronoi diagram and run a query on each voronoi cell. You can subdivide the voronoi diagram to get a better result. You can combine metric and voronoi diagram:http://www.cc.gatech.edu/~phlosoft/voronoi/
you could insert extra vertices in long edges to get some approximation based on closest vertices ..

Resources