Fire Departments covering area - algorithm

Given a set of points (GPS coordinates), and a polygon that contains all those points, can one determine how well those points are covering the area or what the longest distance from any location within the polygon to the nearest point is?
For example, if I have all fire departments within the city boundary of New York, I want to know how long a fire truck has to drive (in case of an emergency) in the worst case.
Any ideas on what the name of this problem is or what this problem can be reduced to? Or are there any existing algorithms for that?
Thank you :)

First construct the Voronoi diagram of the set of sites (GPS coordinates). The Voronoi diagram is a data structure representing a partition of the plane into cells, one cell for each site, such that each site's cell consists of all the points closer to that site than to any other site.
Constructing the Voronoi diagram can be done in O(nlog(n)) using Fortune's sweep-line algorithm where n is the number of input sites.
Then iterate over the Voronoi cells. Each cell is a polygon. For each cell compute the distance between the cell's site and each of the polygon's vertices. The longest distance between a site and a vertex of the site's cell is the longest distance one would have to walk in order to reach the site.
The running time of the algorithm is O(nlog(n)) as the second phase of the algorithm (iterating over the vertices of each Voronoi cell) requires only linear time. This is because the total number of vertices in the whole diagram grows linearly with the number of sites. Namely, it's not too difficult to show using Euler's formula for planar graphs that the total number of Voronoi vertices is bounded from above by 2n-5.
You can find some open source implementations of Fortune's algorithm on the web. This one for instance.

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.

Algorithm for how to Split Large Area into Convex Polygons

I'm implementing the A* pathfinding algorithm into a grid based engine, but I'm wanting to create nodes in polygonal areas rather than just using the grid points.
There will be obstacles in the area, that shouldn't be moved through.
I'm wondering is there some algorithm that can split up a larger area with obstacles into a graph with the smallest possible number of connected convex polygons?
There's a lot of them. Typically you're dealing with your triangulation algorithms. You remove the lines that travel through an obstacle and likely do a shortest path algorithm on it. I'm not sure why you want the smallest number of connected convex polygons though, but that could equally be done. The answer is simply the convex hull of the points. One polygon is by definition the smallest number there.

Find the number of separate polygons given a list of coordinates/points

Given a list of coordinates (x, y) that form up polygons is there a specific algorithm/s that can be used to find the number of separate polygons "not colliding polygons" that these points create?
And if there is no algorithm/s what would be the most efficient way to calculate these separate polygons?
I have tried using SAT but the performance is bad, since i have to create each individual polygon and check it for collision against every other polygon.
To illustrate what i want to ultimately achieve, in the following picture you can see the polygons that i'd like to calculate/find which are in some cases comprised of connecting squares.
Also note that i actually start with x, y coordinates for the center of a square and based on a radius i calculate corner points, so i have access to both methods, but mainly opted for the corner points for SAT.
P.S. i'm doing this in lua, but would happily accept any code samples/solutions in other languages.
Fast sweep-line algorithm are described in these papers:
Hiroshi Imai, Takao Asano,
Finding the connected components and a maximum clique of an intersection graph of rectangles in the plane,
Journal of Algorithms 4 (1983) 310—323
H. Edelsbrunner, J. v. Leeuwen, Th. Ottmann and D. Wood,
Computing the connected components of simple rectilinear geometrical objects in d-space,
RAIRO Inform. Theor. 18 (1984) 171—183.
Put all the edges of every polygon in a hash table with the edge as the key (specifically the key will be the two corner points which the edge connects, in sorted order) and the polygon identifier as the value. When adding an edge to the hash-table, just check if an identical edge already exists (same key). This would let you find the duplicate/shared edges.

Shortest distance to rectangle caching

I have a list of rectangles that don't have to be parallel to the axes. I also have a master rectangle that is parallel to the axes.
I need an algorithm that can tell which rectangle is a point closest to(the point must be in the master rectangle). the list of rectangles and master rectangle won't change during the algorithm and will be called with many points so some data structure should be created to make the lookup faster.
To be clear: distance from a rectangle to a point is the distance between the closest point in the rectangle to the point.
What algorithm/data structure can be used for this? memory is on higher priority on this, n log n is ok but n^2 is not.
You should be able to do this with a Voronoi diagram with O(n log n) preprocessing time with O(log n) time queries. Because the objects are rectangles, not points, the cells may be curved. Nevertheless, a Voronoi diagram should work fine for your purposes. (See http://en.wikipedia.org/wiki/Voronoi_diagram)
For a quick and dirty solution that you could actually get working within a day, you could do something inspired by locality sensitive hashing. For example, if the rectangles are somewhat well-spaced, you could hash them into square buckets with a few different offsets, and then for each query examine each rectangle that falls in one of the handful of buckets that contain the query point.
You should be able to do this in O(n) time and O(n) memory.
Calculate the closest point on each edge of each rectangle to the point in question. To do this, see my detailed answer in the this question. Even though the question has to do with a point inside of the polygon (rather than outside of it), the algorithm still can be applied here.
Calculate the distance between each of these closest points on the edges, and find the closest point on the entire rectangle (for each rectangle) to the point in question. See the link above for more details.
Find the minimum distance between all of the rectangles. The rectangle corresponding with your minimum distance is the winner.
If memory is more valuable than speed, use brute force: for a given point S, compute the distance from S to each edge. Choose the rectangle with the shortest distance.
This solution requires no additional memory, while its execution time is in O(n).
Depending on your exact problem specification, you may have to adjust this solution if the rectangles are allowed to overlap with the master rectangle.
As you described, a distance between one point to a rectangle is the minimum length of all lines through that point which is perpendicular with all four edges of a rectangle and all lines connect that point with one of four vertices of the rectangle.
(My English is not good at describing a math solution, so I think you should think more deeply for understanding my explanation).
For each rectangle, you should save four vertices and four edges function for fast calculation distance between them with the specific point.

Resources