(*^

::[paletteColors = 128; 
	fontset = title, "New York", 18, L2, center, bold, nohscroll;
	fontset = subtitle, "New York", 14, L2, center, bold, nohscroll;
	fontset = subsubtitle, "New York", 14, L2, center, bold, nohscroll;
	fontset = section, "New York", 12, L2, bold, nohscroll, grayBox;
	fontset = subsection, "New York", 10, L2, bold, nohscroll, blackBox;
	fontset = subsubsection, "New York", 10, L2, bold, nohscroll, whiteBox;
	fontset = text, "New York", 9, L2, nohscroll;
	fontset = smalltext, "New York", 10, L2, nohscroll;
	fontset = input, "Courier", 10, L2, bold, nowordwrap;
	fontset = output, "Courier", 10, L2, nowordwrap;
	fontset = message, "Courier", 12, L2, R65535, nowordwrap;
	fontset = print, "Courier", 12, L2, nowordwrap;
	fontset = info, "Courier", 12, L2, nowordwrap;
	fontset = postscript, "Courier", 12, L2, nowordwrap;
	fontset = name, "Geneva", 10, L2, italic, B65535, nowordwrap, nohscroll;
	fontset = header, "Times", 10, L2;
	fontset = footer, "Times", 12, L2, center;
	fontset = help, "Geneva", 10, L2, nohscroll;
	fontset = clipboard, "New York", 12, L2;
	fontset = completions, "New York", 12, L2, nowordwrap;
	fontset = network, "Courier", 10, L2, nowordwrap;
	fontset = graphlabel, "Courier", 12, L2, nowordwrap;
	fontset = special1, "New York", 12, L2, nowordwrap;
	fontset = special2, "New York", 12, L2, center, nowordwrap;
	fontset = special3, "New York", 12, L2, right, nowordwrap;
	fontset = special4, "New York", 12, L2, nowordwrap;
	fontset = special5, "New York", 12, L2, nowordwrap;]
:[font = title; inactive; startGroup; ]
Computational Geometry
:[font = subsubtitle; inactive; ]

Steven S. Skiena
Department of Computer Science
State University of New York
Stony Brook, NY 11794

(516) 632-9026/8470
skiena@sbcs.sunysb.edu

;[s]
2:0,1;1,0;145,-1;
2:1,19,14,New York,1,14,0,0,0;1,19,14,New York,0,14,0,0,0;
:[font = text; inactive; ]
This package provides Mathematica implementations for several important algorithms and structures in Computational Geometry.  It is written as an extension of Combinatorica, the author's package for combinatorics and graph theory, described in [1].  Each geometric object is represented as a graph structure, where the adjacency information is represented by an adjacency matrix and the points by a list of {x,y} pairs.
;[s]
5:0,0;22,1;33,0;407,1;412,0;420,-1;
2:3,14,10,New York,0,9,0,0,0;2,12,10,New York,2,9,0,0,0;
:[font = text; inactive; ]
All implementations of geometric algorithms are subject to numerical instabilities, and robust geometric computation is an area of active research.  In this package, we make the standard assumptions that the points are in general position, meaning no three vertices are collinear.  Further, we assume that no two vertices have the same x or y-coordinate.  While these conditions hold with probability one on random data, these assumptions are inappropriate for certain applications.  We recommend perturbing non-random data slightly using the Combinatorica function ShakeGraph with an appropriately small constant, which will eliminate degeneracies while maintaining the combinatorial structure of the arrangement.
;[s]
5:0,0;336,1;337,0;341,1;342,0;715,-1;
4:3,14,10,New York,0,9,0,0,0;2,12,10,New York,2,9,0,0,0;0,12,10,New York,1,9,0,0,0;0,12,10,New York,3,9,0,0,0;
:[font = text; inactive; ]
[1] S. S. Skiena, 'Implementing Discrete Mathematics: Combinatorics and Graph Theory with Mathematica', Addison-Wesley, Reading MA, 1990.
;[s]
3:0,0;19,1;101,0;138,-1;
2:2,14,10,New York,0,9,0,0,0;1,12,10,New York,2,9,0,0,0;
:[font = input; initialization; ]
*)
<<Combinatorica.m
(*
:[font = input; initialization; endGroup; ]
*)
<<Geometry.m
(*
:[font = input; ]

:[font = section; inactive; startGroup; ]
Convex and Simple Polygons
:[font = text; inactive; ]
The convex hull of a set of points is the smallest polygon to enclose all the points.  Convex hulls form the basis of many algorithms in computational geometry, because convex polygons are more convenient to work with than arbitrary simple polygons.
:[font = text; inactive; ]
To illustrate the convex hull algorithm, we will start with a random point set:
:[font = input; startGroup; ]
ShowGraph[ p = RandomPointSet[10] ];
:[font = postscript; inactive; PostScript; output; endGroup; pictureLeft = 37; pictureWidth = 193; pictureHeight = 193; preserveAspect; ]
%!
%%Creator: Mathematica
%%AspectRatio: 1 
MathPictureStart
% Scaling calculations
0.03038 1.00485 0.04545 0.90909 [
[ 0 0 0 0 ]
[ 1 1 0 0 ]
] MathScale
% Start of Graphics
1 setlinecap
1 setlinejoin
newpath
%%Object: Graphics
[ ] 0 setdash
0 setgray
gsave
gsave
grestore
grestore
0 0 moveto
1 0 lineto
1 1 lineto
0 1 lineto
closepath
clip
newpath
0 setgray
gsave
0.025 setlinewidth
0.1544 0.04545 Mdot
0.13031 0.619 Mdot
0.05024 0.69602 Mdot
0.84236 0.55994 Mdot
0.18554 0.95455 Mdot
0.50008 0.39614 Mdot
0.93626 0.44811 Mdot
0.40544 0.31183 Mdot
0.94976 0.62571 Mdot
0.56933 0.78978 Mdot
grestore
% End of Graphics
MathPictureEnd
:[font = text; inactive; ]
The convex hull passes through at least three vertices of the point set, including the leftmost, rightmost, topmost, and bottommost vertices:
:[font = input; startGroup; ]
ShowGraph[ ConvexHull[p, All] ];
:[font = postscript; inactive; PostScript; output; endGroup; pictureLeft = 37; pictureWidth = 193; pictureHeight = 193; preserveAspect; ]
%!
%%Creator: Mathematica
%%AspectRatio: 1 
MathPictureStart
% Scaling calculations
0.03038 1.00485 0.04545 0.90909 [
[ 0 0 0 0 ]
[ 1 1 0 0 ]
] MathScale
% Start of Graphics
1 setlinecap
1 setlinejoin
newpath
%%Object: Graphics
[ ] 0 setdash
0 setgray
gsave
gsave
grestore
grestore
0 0 moveto
1 0 lineto
1 1 lineto
0 1 lineto
closepath
clip
newpath
0 setgray
gsave
0.025 setlinewidth
0.1544 0.04545 Mdot
0.93626 0.44811 Mdot
0.94976 0.62571 Mdot
0.56933 0.78978 Mdot
0.18554 0.95455 Mdot
0.05024 0.69602 Mdot
0.13031 0.619 Mdot
0.40544 0.31183 Mdot
0.50008 0.39614 Mdot
0.84236 0.55994 Mdot
0.004 setlinewidth
0.1544 0.04545 moveto
0.93626 0.44811 lineto
stroke
0.1544 0.04545 moveto
0.05024 0.69602 lineto
stroke
0.93626 0.44811 moveto
0.1544 0.04545 lineto
stroke
0.93626 0.44811 moveto
0.94976 0.62571 lineto
stroke
0.94976 0.62571 moveto
0.93626 0.44811 lineto
stroke
0.94976 0.62571 moveto
0.56933 0.78978 lineto
stroke
0.56933 0.78978 moveto
0.94976 0.62571 lineto
stroke
0.56933 0.78978 moveto
0.18554 0.95455 lineto
stroke
0.18554 0.95455 moveto
0.56933 0.78978 lineto
stroke
0.18554 0.95455 moveto
0.05024 0.69602 lineto
stroke
0.05024 0.69602 moveto
0.1544 0.04545 lineto
stroke
0.05024 0.69602 moveto
0.18554 0.95455 lineto
stroke
grestore
% End of Graphics
MathPictureEnd
:[font = text; inactive; ]
Since any three points form a triangle, the convex hull of three randomly selected points on the unit-square contains three points.  However, the probability of k random points forming a convex k-gon decreases rapidly with k.  Here we illustrate the distribution of hull sizes in random sets of seven points.
;[s]
3:0,0;161,1;162,0;309,-1;
2:2,14,10,New York,0,9,0,0,0;1,12,10,New York,2,9,0,0,0;
:[font = input; startGroup; ]
Distribution[ 
	Table[ V[ ConvexHull[RandomPointSet[7]] ], {30}],
	Range[7]
]
:[font = output; inactive; output; endGroup; ]
{0, 0, 0, 7, 11, 11, 1}
;[o]
{0, 0, 0, 7, 11, 11, 1}
:[font = text; inactive; ]
Any set of points can be connected to form a simple polygon, meaning no two edges intersect:
:[font = input; startGroup; ]
ShowGraph[ simple = SimplePolygon[p] ];
:[font = postscript; inactive; PostScript; output; endGroup; pictureLeft = 37; pictureWidth = 193; pictureHeight = 193; preserveAspect; ]
%!
%%Creator: Mathematica
%%AspectRatio: 1 
MathPictureStart
% Scaling calculations
0.03038 1.00485 0.04545 0.90909 [
[ 0 0 0 0 ]
[ 1 1 0 0 ]
] MathScale
% Start of Graphics
1 setlinecap
1 setlinejoin
newpath
%%Object: Graphics
[ ] 0 setdash
0 setgray
gsave
gsave
grestore
grestore
0 0 moveto
1 0 lineto
1 1 lineto
0 1 lineto
closepath
clip
newpath
0 setgray
gsave
0.025 setlinewidth
0.1544 0.04545 Mdot
0.93626 0.44811 Mdot
0.94976 0.62571 Mdot
0.84236 0.55994 Mdot
0.50008 0.39614 Mdot
0.40544 0.31183 Mdot
0.56933 0.78978 Mdot
0.18554 0.95455 Mdot
0.13031 0.619 Mdot
0.05024 0.69602 Mdot
0.004 setlinewidth
0.1544 0.04545 moveto
0.93626 0.44811 lineto
stroke
0.1544 0.04545 moveto
0.05024 0.69602 lineto
stroke
0.93626 0.44811 moveto
0.1544 0.04545 lineto
stroke
0.93626 0.44811 moveto
0.94976 0.62571 lineto
stroke
0.94976 0.62571 moveto
0.93626 0.44811 lineto
stroke
0.94976 0.62571 moveto
0.84236 0.55994 lineto
stroke
0.84236 0.55994 moveto
0.94976 0.62571 lineto
stroke
0.84236 0.55994 moveto
0.50008 0.39614 lineto
stroke
0.50008 0.39614 moveto
0.84236 0.55994 lineto
stroke
0.50008 0.39614 moveto
0.40544 0.31183 lineto
stroke
0.40544 0.31183 moveto
0.50008 0.39614 lineto
stroke
0.40544 0.31183 moveto
0.56933 0.78978 lineto
stroke
0.56933 0.78978 moveto
0.40544 0.31183 lineto
stroke
0.56933 0.78978 moveto
0.18554 0.95455 lineto
stroke
0.18554 0.95455 moveto
0.56933 0.78978 lineto
stroke
0.18554 0.95455 moveto
0.13031 0.619 lineto
stroke
0.13031 0.619 moveto
0.18554 0.95455 lineto
stroke
0.13031 0.619 moveto
0.05024 0.69602 lineto
stroke
0.05024 0.69602 moveto
0.1544 0.04545 lineto
stroke
0.05024 0.69602 moveto
0.13031 0.619 lineto
stroke
grestore
% End of Graphics
MathPictureEnd
:[font = text; inactive; ]
The area of a simple polygon can be estimated using a Monte Carlo technique, using predicates which test whether a point is in the interior of the polygon:
:[font = input; startGroup; ]
Length[ RangeQuery[ simple, RandomPointSet[20] ] ] / 20
:[font = output; inactive; output; endGroup; ]
2/5
;[o]
2
-
5
:[font = text; inactive; ]
Testing whether a point is within a rectangle is a simpler, but still important problem.  Here we use the Monte Carlo method to estimate the area of the lower quadrant of the unit square.
:[font = input; startGroup; ]
Length[
	OrthogonalRangeQuery[ RandomPointSet[100], {0,0.5}, {0,0.5}]
] / 100
:[font = output; inactive; output; endGroup; ]
21/100
;[o]
21
---
100
:[font = input; endGroup; ]

:[font = section; inactive; startGroup; ]
Triangulations and Voronoi Diagrams
:[font = text; inactive; ]
A triangulation of a point set divides the convex hull into regions, each of which is a triangle.  This involves adding diagonals between vertices, until no other diagonal can be added which does not intersect an edge of the triangulation.  Triangulations are important because the provide a convenient decomposition of a poylgon into convex regions.
:[font = input; startGroup; ]
ShowLabeledGraph[ tri = Triangulation[p] ];
:[font = postscript; inactive; PostScript; output; endGroup; pictureLeft = 37; pictureWidth = 193; pictureHeight = 193; preserveAspect; ]
%!
%%Creator: Mathematica
%%AspectRatio: 1 
MathPictureStart
% Scaling calculations
0.03038 1.00485 0.04545 0.90909 [
[ 0 0 0 0 ]
[ 1 1 0 0 ]
] MathScale
% Start of Graphics
1 setlinecap
1 setlinejoin
newpath
%%Object: Graphics
[ ] 0 setdash
0 setgray
gsave
gsave
grestore
grestore
0 0 moveto
1 0 lineto
1 1 lineto
0 1 lineto
closepath
clip
newpath
0 setgray
gsave
0.025 setlinewidth
0.1544 0.04545 Mdot
0.93626 0.44811 Mdot
0.94976 0.62571 Mdot
0.56933 0.78978 Mdot
0.18554 0.95455 Mdot
0.05024 0.69602 Mdot
0.13031 0.619 Mdot
0.40544 0.31183 Mdot
0.50008 0.39614 Mdot
0.84236 0.55994 Mdot
0.004 setlinewidth
0.1544 0.04545 moveto
0.93626 0.44811 lineto
stroke
0.1544 0.04545 moveto
0.94976 0.62571 lineto
stroke
0.1544 0.04545 moveto
0.56933 0.78978 lineto
stroke
0.1544 0.04545 moveto
0.18554 0.95455 lineto
stroke
0.1544 0.04545 moveto
0.05024 0.69602 lineto
stroke
0.1544 0.04545 moveto
0.13031 0.619 lineto
stroke
0.1544 0.04545 moveto
0.40544 0.31183 lineto
stroke
0.1544 0.04545 moveto
0.84236 0.55994 lineto
stroke
0.93626 0.44811 moveto
0.1544 0.04545 lineto
stroke
0.93626 0.44811 moveto
0.94976 0.62571 lineto
stroke
0.94976 0.62571 moveto
0.1544 0.04545 lineto
stroke
0.94976 0.62571 moveto
0.93626 0.44811 lineto
stroke
0.94976 0.62571 moveto
0.56933 0.78978 lineto
stroke
0.94976 0.62571 moveto
0.40544 0.31183 lineto
stroke
0.94976 0.62571 moveto
0.50008 0.39614 lineto
stroke
0.94976 0.62571 moveto
0.84236 0.55994 lineto
stroke
0.56933 0.78978 moveto
0.1544 0.04545 lineto
stroke
0.56933 0.78978 moveto
0.94976 0.62571 lineto
stroke
0.56933 0.78978 moveto
0.18554 0.95455 lineto
stroke
0.56933 0.78978 moveto
0.40544 0.31183 lineto
stroke
0.56933 0.78978 moveto
0.50008 0.39614 lineto
stroke
0.18554 0.95455 moveto
0.1544 0.04545 lineto
stroke
0.18554 0.95455 moveto
0.56933 0.78978 lineto
stroke
0.18554 0.95455 moveto
0.05024 0.69602 lineto
stroke
0.18554 0.95455 moveto
0.13031 0.619 lineto
stroke
0.05024 0.69602 moveto
0.1544 0.04545 lineto
stroke
0.05024 0.69602 moveto
0.18554 0.95455 lineto
stroke
0.05024 0.69602 moveto
0.13031 0.619 lineto
stroke
0.13031 0.619 moveto
0.1544 0.04545 lineto
stroke
0.13031 0.619 moveto
0.18554 0.95455 lineto
stroke
0.13031 0.619 moveto
0.05024 0.69602 lineto
stroke
0.40544 0.31183 moveto
0.1544 0.04545 lineto
stroke
0.40544 0.31183 moveto
0.94976 0.62571 lineto
stroke
0.40544 0.31183 moveto
0.56933 0.78978 lineto
stroke
0.40544 0.31183 moveto
0.50008 0.39614 lineto
stroke
0.40544 0.31183 moveto
0.84236 0.55994 lineto
stroke
0.50008 0.39614 moveto
0.94976 0.62571 lineto
stroke
0.50008 0.39614 moveto
0.56933 0.78978 lineto
stroke
0.50008 0.39614 moveto
0.40544 0.31183 lineto
stroke
0.84236 0.55994 moveto
0.1544 0.04545 lineto
stroke
0.84236 0.55994 moveto
0.94976 0.62571 lineto
stroke
0.84236 0.55994 moveto
0.40544 0.31183 lineto
stroke
0.1544 0.04545 moveto
0.93626 0.44811 lineto
stroke
0.1544 0.04545 moveto
0.94976 0.62571 lineto
stroke
0.1544 0.04545 moveto
0.56933 0.78978 lineto
stroke
0.1544 0.04545 moveto
0.18554 0.95455 lineto
stroke
0.1544 0.04545 moveto
0.05024 0.69602 lineto
stroke
0.1544 0.04545 moveto
0.13031 0.619 lineto
stroke
0.1544 0.04545 moveto
0.40544 0.31183 lineto
stroke
0.1544 0.04545 moveto
0.84236 0.55994 lineto
stroke
0.93626 0.44811 moveto
0.1544 0.04545 lineto
stroke
0.93626 0.44811 moveto
0.94976 0.62571 lineto
stroke
0.94976 0.62571 moveto
0.1544 0.04545 lineto
stroke
0.94976 0.62571 moveto
0.93626 0.44811 lineto
stroke
0.94976 0.62571 moveto
0.56933 0.78978 lineto
stroke
0.94976 0.62571 moveto
0.40544 0.31183 lineto
stroke
0.94976 0.62571 moveto
0.50008 0.39614 lineto
stroke
0.94976 0.62571 moveto
0.84236 0.55994 lineto
stroke
0.56933 0.78978 moveto
0.1544 0.04545 lineto
stroke
0.56933 0.78978 moveto
0.94976 0.62571 lineto
stroke
0.56933 0.78978 moveto
0.18554 0.95455 lineto
stroke
0.56933 0.78978 moveto
0.40544 0.31183 lineto
stroke
0.56933 0.78978 moveto
0.50008 0.39614 lineto
stroke
0.18554 0.95455 moveto
0.1544 0.04545 lineto
stroke
0.18554 0.95455 moveto
0.56933 0.78978 lineto
stroke
0.18554 0.95455 moveto
0.05024 0.69602 lineto
stroke
0.18554 0.95455 moveto
0.13031 0.619 lineto
stroke
0.05024 0.69602 moveto
0.1544 0.04545 lineto
stroke
0.05024 0.69602 moveto
0.18554 0.95455 lineto
stroke
0.05024 0.69602 moveto
0.13031 0.619 lineto
stroke
0.13031 0.619 moveto
0.1544 0.04545 lineto
stroke
0.13031 0.619 moveto
0.18554 0.95455 lineto
stroke
0.13031 0.619 moveto
0.05024 0.69602 lineto
stroke
0.40544 0.31183 moveto
0.1544 0.04545 lineto
stroke
0.40544 0.31183 moveto
0.94976 0.62571 lineto
stroke
0.40544 0.31183 moveto
0.56933 0.78978 lineto
stroke
0.40544 0.31183 moveto
0.50008 0.39614 lineto
stroke
0.40544 0.31183 moveto
0.84236 0.55994 lineto
stroke
0.50008 0.39614 moveto
0.94976 0.62571 lineto
stroke
0.50008 0.39614 moveto
0.56933 0.78978 lineto
stroke
0.50008 0.39614 moveto
0.40544 0.31183 lineto
stroke
0.84236 0.55994 moveto
0.1544 0.04545 lineto
stroke
0.84236 0.55994 moveto
0.94976 0.62571 lineto
stroke
0.84236 0.55994 moveto
0.40544 0.31183 lineto
stroke
0 setgray
[(1)] 0.12425 0.01818 0 1 Mshowa
0 setgray
[(2)] 0.90612 0.42084 0 1 Mshowa
0 setgray
[(3)] 0.91961 0.59844 0 1 Mshowa
0 setgray
[(4)] 0.53918 0.76251 0 1 Mshowa
0 setgray
[(5)] 0.15539 0.92727 0 1 Mshowa
0 setgray
[(6)] 0.0201 0.66875 0 1 Mshowa
0 setgray
[(7)] 0.10017 0.59173 0 1 Mshowa
0 setgray
[(8)] 0.3753 0.28456 0 1 Mshowa
0 setgray
[(9)] 0.46993 0.36886 0 1 Mshowa
0 setgray
[(10)] 0.81221 0.53266 0 1 Mshowa
grestore
% End of Graphics
MathPictureEnd
:[font = text; inactive; ]
The faces of a triangulated planar subdivision can be identifed by sweeping a vertical line from left to right, stopping at each vertex to record which faces have been completed.  Here the faces are described by the position of the vertices within the triangulation.
:[font = input; startGroup; ]
subdivision = PlanarSweep[ tri ]
:[font = output; inactive; output; endGroup; ]
{{6, 1, 7}, {6, 5, 7}, {5, 1, 7}, {4, 1, 5}, {4, 1, 8}, {8, 4, 9}, 
  {8, 1, 10}, {4, 3, 9}, {8, 3, 9}, {8, 3, 10}, {3, 1, 10}, {2, 1, 3}}
;[o]
{{6, 1, 7}, {6, 5, 7}, {5, 1, 7}, {4, 1, 5}, {4, 1, 8}, {8, 4, 9}, 
 
  {8, 1, 10}, {4, 3, 9}, {8, 3, 9}, {8, 3, 10}, {3, 1, 10}, {2, 1, 3}}
:[font = text; inactive; ]
Each point lies within exactly one region of the planar subdivision.  Point locations are more specific than range queries, since they identify which region of the subdivision the point lies in.
:[font = input; startGroup; ]
PointLocation[{0.5,0.5}, tri, subdivision]
:[font = output; inactive; output; endGroup; ]
{4, 3, 9}
;[o]
{4, 3, 9}
:[font = text; inactive; ]
Because geometric objects are represented as graphs,  all functions in Combinatorica can be used on them.  There are a variety of results relating graphs to geometric objects, for example, every convex polyhedron defines a planar graph.  All triangulations are planar, and many but not all are Hamiltonian.
:[font = input; startGroup; ]
HamiltonianCycle[ tri ]
:[font = output; inactive; output; endGroup; ]
{1, 2, 3, 10, 8, 9, 4, 5, 6, 7, 1}
;[o]
{1, 2, 3, 10, 8, 9, 4, 5, 6, 7, 1}
:[font = text; inactive; ]
Not all triangulations are created equal.  For many applications, it is important to avoid long, skinny triangles.  The Delaunay triangulation maximizes the minimum angle over all triangulations, and can be constructed from an arbitrary triangulation by fliping edges to increase angle sizes:
:[font = input; startGroup; ]
ShowGraph[ dt = DelaunayTriangulation[ p ] ];
:[font = postscript; inactive; PostScript; output; endGroup; pictureLeft = 37; pictureWidth = 193; pictureHeight = 193; preserveAspect; ]
%!
%%Creator: Mathematica
%%AspectRatio: 1 
MathPictureStart
% Scaling calculations
0.03038 1.00485 0.04545 0.90909 [
[ 0 0 0 0 ]
[ 1 1 0 0 ]
] MathScale
% Start of Graphics
1 setlinecap
1 setlinejoin
newpath
%%Object: Graphics
[ ] 0 setdash
0 setgray
gsave
gsave
grestore
grestore
0 0 moveto
1 0 lineto
1 1 lineto
0 1 lineto
closepath
clip
newpath
0 setgray
gsave
0.025 setlinewidth
0.1544 0.04545 Mdot
0.93626 0.44811 Mdot
0.94976 0.62571 Mdot
0.56933 0.78978 Mdot
0.18554 0.95455 Mdot
0.05024 0.69602 Mdot
0.13031 0.619 Mdot
0.40544 0.31183 Mdot
0.50008 0.39614 Mdot
0.84236 0.55994 Mdot
0.004 setlinewidth
0.1544 0.04545 moveto
0.93626 0.44811 lineto
stroke
0.1544 0.04545 moveto
0.05024 0.69602 lineto
stroke
0.1544 0.04545 moveto
0.13031 0.619 lineto
stroke
0.1544 0.04545 moveto
0.40544 0.31183 lineto
stroke
0.93626 0.44811 moveto
0.1544 0.04545 lineto
stroke
0.93626 0.44811 moveto
0.94976 0.62571 lineto
stroke
0.93626 0.44811 moveto
0.40544 0.31183 lineto
stroke
0.93626 0.44811 moveto
0.50008 0.39614 lineto
stroke
0.93626 0.44811 moveto
0.84236 0.55994 lineto
stroke
0.94976 0.62571 moveto
0.93626 0.44811 lineto
stroke
0.94976 0.62571 moveto
0.56933 0.78978 lineto
stroke
0.94976 0.62571 moveto
0.84236 0.55994 lineto
stroke
0.56933 0.78978 moveto
0.94976 0.62571 lineto
stroke
0.56933 0.78978 moveto
0.18554 0.95455 lineto
stroke
0.56933 0.78978 moveto
0.13031 0.619 lineto
stroke
0.56933 0.78978 moveto
0.50008 0.39614 lineto
stroke
0.56933 0.78978 moveto
0.84236 0.55994 lineto
stroke
0.18554 0.95455 moveto
0.56933 0.78978 lineto
stroke
0.18554 0.95455 moveto
0.05024 0.69602 lineto
stroke
0.18554 0.95455 moveto
0.13031 0.619 lineto
stroke
0.05024 0.69602 moveto
0.1544 0.04545 lineto
stroke
0.05024 0.69602 moveto
0.18554 0.95455 lineto
stroke
0.05024 0.69602 moveto
0.13031 0.619 lineto
stroke
0.13031 0.619 moveto
0.1544 0.04545 lineto
stroke
0.13031 0.619 moveto
0.56933 0.78978 lineto
stroke
0.13031 0.619 moveto
0.18554 0.95455 lineto
stroke
0.13031 0.619 moveto
0.05024 0.69602 lineto
stroke
0.13031 0.619 moveto
0.40544 0.31183 lineto
stroke
0.13031 0.619 moveto
0.50008 0.39614 lineto
stroke
0.40544 0.31183 moveto
0.1544 0.04545 lineto
stroke
0.40544 0.31183 moveto
0.93626 0.44811 lineto
stroke
0.40544 0.31183 moveto
0.13031 0.619 lineto
stroke
0.40544 0.31183 moveto
0.50008 0.39614 lineto
stroke
0.50008 0.39614 moveto
0.93626 0.44811 lineto
stroke
0.50008 0.39614 moveto
0.56933 0.78978 lineto
stroke
0.50008 0.39614 moveto
0.13031 0.619 lineto
stroke
0.50008 0.39614 moveto
0.40544 0.31183 lineto
stroke
0.50008 0.39614 moveto
0.84236 0.55994 lineto
stroke
0.84236 0.55994 moveto
0.93626 0.44811 lineto
stroke
0.84236 0.55994 moveto
0.94976 0.62571 lineto
stroke
0.84236 0.55994 moveto
0.56933 0.78978 lineto
stroke
0.84236 0.55994 moveto
0.50008 0.39614 lineto
stroke
grestore
% End of Graphics
MathPictureEnd
:[font = text; inactive; ]
The Voronoi diagram of a point set p partitions the plane into regions, such that all the points in the plane which have the same nearest neighbor in p belong to the same region.  Thus Voronoi diagrams facilitate nearest neighbor queries for arbitrary points.
;[s]
5:0,0;35,1;36,0;150,1;151,0;260,-1;
2:3,14,10,New York,0,9,0,0,0;2,12,10,New York,2,9,0,0,0;
:[font = text; inactive; ]
Voronoi digrams can be constructed from Delaunay triangulations by taking the dual of the triangulation.  Each triangle becomes a point, representing the intersection of the perpendicular bisectors of the three edges.  Two dual points are connected by an edge if and only if the associated triangles share an edge. 
:[font = input; startGroup; ]
ShowGraph[ DualTriangulation[ dt ] ];
:[font = postscript; inactive; PostScript; output; endGroup; pictureLeft = 37; pictureWidth = 193; pictureHeight = 193; preserveAspect; ]
%!
%%Creator: Mathematica
%%AspectRatio: 1 
MathPictureStart
% Scaling calculations
0.03262 0.97959 0.04545 0.90909 [
[ 0 0 0 0 ]
[ 1 1 0 0 ]
] MathScale
% Start of Graphics
1 setlinecap
1 setlinejoin
newpath
%%Object: Graphics
[ ] 0 setdash
0 setgray
gsave
gsave
grestore
grestore
0 0 moveto
1 0 lineto
1 1 lineto
0 1 lineto
closepath
clip
newpath
0 setgray
gsave
0.025 setlinewidth
0.04898 0.48612 Mdot
0.43624 0.82415 Mdot
0.33084 0.49606 Mdot
0.4882 0.6144 Mdot
0.50099 0.8152 Mdot
0.55251 0.70399 Mdot
0.70808 0.68101 Mdot
0.78862 0.53971 Mdot
0.82277 0.29907 Mdot
0.90032 0.04545 Mdot
0.8298 0.80241 Mdot
0.94235 0.64811 Mdot
0.38164 0.28696 Mdot
0.94136 0.58265 Mdot
0.95102 0.71307 Mdot
0.67868 0.83355 Mdot
0.40393 0.95455 Mdot
0.30707 0.7647 Mdot
0.36439 0.70814 Mdot
0.56135 0.48257 Mdot
0.6291 0.54448 Mdot
0.87413 0.66477 Mdot
0.004 setlinewidth
0.04898 0.48612 moveto
0.43624 0.82415 lineto
stroke
0.04898 0.48612 moveto
0.33084 0.49606 lineto
stroke
0.43624 0.82415 moveto
0.04898 0.48612 lineto
stroke
0.43624 0.82415 moveto
0.50099 0.8152 lineto
stroke
0.33084 0.49606 moveto
0.04898 0.48612 lineto
stroke
0.33084 0.49606 moveto
0.4882 0.6144 lineto
stroke
0.33084 0.49606 moveto
0.90032 0.04545 lineto
stroke
0.4882 0.6144 moveto
0.33084 0.49606 lineto
stroke
0.4882 0.6144 moveto
0.55251 0.70399 lineto
stroke
0.4882 0.6144 moveto
0.82277 0.29907 lineto
stroke
0.50099 0.8152 moveto
0.43624 0.82415 lineto
stroke
0.50099 0.8152 moveto
0.55251 0.70399 lineto
stroke
0.55251 0.70399 moveto
0.4882 0.6144 lineto
stroke
0.55251 0.70399 moveto
0.50099 0.8152 lineto
stroke
0.55251 0.70399 moveto
0.70808 0.68101 lineto
stroke
0.70808 0.68101 moveto
0.55251 0.70399 lineto
stroke
0.70808 0.68101 moveto
0.78862 0.53971 lineto
stroke
0.70808 0.68101 moveto
0.8298 0.80241 lineto
stroke
0.78862 0.53971 moveto
0.70808 0.68101 lineto
stroke
0.78862 0.53971 moveto
0.82277 0.29907 lineto
stroke
0.78862 0.53971 moveto
0.94235 0.64811 lineto
stroke
0.82277 0.29907 moveto
0.4882 0.6144 lineto
stroke
0.82277 0.29907 moveto
0.78862 0.53971 lineto
stroke
0.82277 0.29907 moveto
0.90032 0.04545 lineto
stroke
0.90032 0.04545 moveto
0.33084 0.49606 lineto
stroke
0.90032 0.04545 moveto
0.82277 0.29907 lineto
stroke
0.8298 0.80241 moveto
0.70808 0.68101 lineto
stroke
0.8298 0.80241 moveto
0.94235 0.64811 lineto
stroke
0.94235 0.64811 moveto
0.78862 0.53971 lineto
stroke
0.94235 0.64811 moveto
0.8298 0.80241 lineto
stroke
grestore
% End of Graphics
MathPictureEnd
:[font = text; inactive; ]
In this implementation, Voronoi diagram edges which go to infinity are not represented.
:[font = input; endGroup; ]

:[font = section; inactive; ]
Functions
:[font = text; inactive; ]
Each function in the package listed below has an associated usage string providing on-line documentation:
:[font = text; inactive; ]
ConvexHull
ConvexPolygonQ
CCW
DelaunayTriangulation
DualTriangulation
InsideConvexQ
InsideQ
LineSegmentsIntersect
OrthogonalRangeQuery
PlanarSweep
PointLocation
RandomPointSet
RangeQuery
SimplePolygon
SurfaceInterpolation
Triangulation
VoronoiDiagram
;[s]
2:0,1;250,0;251,-1;
2:1,14,10,New York,0,9,0,0,0;1,12,10,New York,1,9,0,0,0;
:[font = input; ]

^*)
