DiscreteMath`ComputationalGeometry`Computational geometry is the study of efficient algorithms for solving geometric problems. The nearest neighbor problem involves identifying one point, out of a set of points, that is nearest to the query point according to some measure of distance. The nearest neighborhood problem involves identifying the locus of points lying nearer to the query point than to any other point in the set. This package provides functions for solving these and related problems in the case of planar points and the Euclidean distance metric. Computational geometry functions. The convex hull of a set is the boundary of the smallest set containing . The Voronoi diagram of is the collection of nearest neighborhoods for each of the points in . For points in the plane, these neighborhoods are polygons. The Delaunay triangulation of is a triangulation of the points in such that no triangle contains a point of in its circumcircle. This is equivalent to connecting the points in according to whether their neighborhood polygons share a common side. This loads the package. Here is a list of points in the plane. This gives the indices of the points lying on the convex hull in counterclockwise order.
Out[3]=  
Duplicate points are ignored.
ConvexHull::"duplicated": "\!\(1\) duplicated point(s) ignored."
Out[4]=  
This gives the counterclockwise vertex adjacency list for each point in the Delaunay triangulation. For example, the entry {1, {4, 3, 2}} indicates that the first point in data2D is connected in counterclockwise order to the fourth, third, and second points.
Out[5]//Shallow=  
While DelaunayTriangulation need only specify the connections between points, VoronoiDiagram must specify both a set of diagram vertices and the connections between those vertices. Another difference between the two functions is that while a triangulation consists of segments, a diagram consists of both segments and rays. For example, in the case of a Voronoi diagram, points in the interior of the convex hull will have nearest neighborhoods that are closed polygons, but the nearest neighborhoods of points on the convex hull will be open polygons. These considerations make the output of VoronoiDiagram more complex than that of DelaunayTriangulation. The diagram is given as a list of diagram vertices followed by a diagram vertex adjacency list. The finite vertices of the diagram are listed first in the vertex list. The vertices lying at infinity have head Ray and are listed last. This assigns the list of Voronoi diagram vertices to vorvert and the Voronoi diagram vertex adjacency list to vorval. The first vertex in vorvert is a finite diagram vertex having coordinates {0.0158537, 8.44146}. The last vertex in vorvert is a point at infinity. This point is represented by a Ray object having origin {10.5172, 3.46115} and containing {13.95, 0.2}.
Out[7]=  
Each entry in vorval gives the index of a point in data2D followed by a counterclockwise list of the Voronoi diagram vertices that comprise the point's nearest neighborhood polygon.
Out[8]//Short=  
Here is the Voronoi polygon vertex adjacency list for the first point in data2D.
Out[9]=  
This selects the coordinates of the polygon vertices from vorvert. The first two vertices have head List, while the last two have head Ray. Thus, the Voronoi polygon associated with the first point in data2D is open and is defined by a segment and two rays.
Out[10]=  
Computing the Voronoi diagram using the Delaunay triangulation and the convex hull. This computes the Voronoi diagram of data2D more efficiently by making use of the Delaunay triangulation vertex adjacency list. Here the Voronoi diagram is computed using both the Delaunay triangulation and the convex hull. Computational geometry plotting functions. The default of PlanarGraphPlot is a plot of the Delaunay triangulation of the points.
Out[13]=  
This plots the convex hull of the points.
Out[14]=  
Here is an alternative triangulation. This plots the triangulation of data2D given by trival.
Out[16]=  
The default of DiagramPlot is a plot of the Voronoi diagram of the points.
Out[17]=  
Here is an alternative set of diagram vertices. Here is an alternative diagram vertex adjacency list. This plots the diagram of data2D given by diagvert and diagval.
Out[20]=  
Here is a set of threedimensional points having the same coordinates as data2D. The default of TriangularSurfacePlot is a plot of the coordinates according to the connectivity established by the Delaunay triangulation of the coordinates.
Out[22]=  
This plots the coordinates according to the connectivity established by the triangulation trival.
Out[23]=  
Options for computational geometry functions. This gives the minimum set of points needed to define the convex hull.
ConvexHull::"duplicated": "\!\(1\) duplicated point(s) ignored."
Out[24]=  
This returns both the Delaunay triangulation and the convex hull.
Out[25]//Shallow=  
Here is a set of random numbers uniformly distributed on [0, 1][0, 1]. This computes the Voronoi diagram of random. The diagram plot is dominated by outlier vertices.
Out[28]=  
TrimPoints > 2 means that the diagram is plotted so that both the outermost ray and the outermost vertex are eliminated.
Out[29]=  
The TrimPoints option can be used to magnify the diagram until the points in random fill the plot.
Out[30]=  
Testing for a Delaunay triangulation. delval is a Delaunay triangulation, so this returns True.
Out[31]=  
This returns False because trival is not a Delaunay triangulation.
DelaunayTriangulationQ::"inval": "Triangle \!\({11, 15, 12}\) is not a valid Delaunay triangle."
Out[32]=  
Computing the nearest neighbor. This computes the point in data2D nearest to {7.92, 8.92}.
Out[33]=  
If the Voronoi diagram is known, the diagram vertex list and vertex adjacency list can be substituted for the point list for a faster NearestNeighbor calculation.
Out[34]=  
This gives the coordinates of the Voronoi polygon containing {7.92, 8.92}.
Out[35]=  
For each of the points in data2D, the nearest point in data2D is the point itself.
Out[36]=  
The first half of these points is known to derive from one distribution; the second half is known to derive from another. Each of these points is believed to derive from one of the two distributions. This classifies the points in unknown according to the classifications of their nearest neighbors in known.
Out[39]=  
Computing the bounded Voronoi diagram. When spatial data is collected within a finite region of the plane, the unbounded Voronoi diagram of the points may not offer an accurate picture of the region of influence of each point. A tile on the periphery of the diagram will be open, indicating an infinite region of influence, when in fact an open tile is simply due to the limited extent of the spatial sampling. It is sometimes useful to intersect the unbounded Voronoi diagram of the data with the boundary of the convex region from which the data was collected. Then each point in the data can be associated with a closed tile or finite region of influence. BoundedDiagram begins by finding the unbounded Voronoi diagram. It then works counterclockwise around the boundary, integrating bounding polygon vertices into the diagram, and deleting Voronoi diagram vertices falling outside of the boundary. Bounding an open tile of the Voronoi diagram allows one to approximate the true underlying closed tile one would have if the data collection had not been limited to a portion of the plane. The bounded diagram is represented as two lists: (1) a vertex coordinate list, and (2) a vertex adjacency list, one entry for each point in the original unbounded diagram indicating the associated bounded polygon vertices in counterclockwise order. Since BoundedDiagram requires the unbounded Voronoi diagram, the computation of the bounded diagram can be made more efficient by providing additional arguments, such as the Delaunay triangulation vertex adjacency list and the convex hull. These are the coordinates of the rectangular region from which the data2D sample was drawn. This assigns the list of bounded diagram vertices to diagvert1 and the bounded diagram vertex adjacency list to diagval1. Here is a plot of the bounded diagram of data2D given by diagvert1 and diagval1.
Out[42]=  
Computing tile areas. You can make use of Voronoi diagrams to build spatial interaction models, or simply calculate the area of influence of individual tiles. In an unbounded Voronoi diagram, some of the tiles have infinite area.
Out[43]=  
In a bounded diagram, each of the tiles has finite area.
Out[44]=  
This gives the tile areas scaled by the area of the rectangle from which the sample was drawn.
Out[45]=  
