How to create a planar graph from a set of random points

In Version 10, we can do this nicely even for 3D point sets:

pointsToGraph[pts_, graph : (Graph | Graph3D)] := 
 Module[{del = DelaunayMesh[pts], edges},
  edges = UndirectedEdge @@@ MeshCells[del, 1][[All, 1]];
  graph[Range@Length@pts, edges, VertexLabels -> "Name", VertexCoordinates -> pts]
  ]

SeedRandom[2];
pts2d = RandomReal[10, {10, 2}];
pointsToGraph[pts2d, Graph]

Mathematica graphics

SeedRandom[2];
pts3d = RandomReal[10, {30, 3}];
pointsToGraph[pts3d, Graph3D]

Mathematica graphics


Using Mark McClure's answer, one can easily build a graph by collecting all the edges of a Delaunay triangulation and then removing duplicates. For non-crossing layout, use GraphLayout -> "PlanarEmbedding" (since v9) and add the original points as vertex coordinates.

Needs["ComputationalGeometry`"];
pts = RandomReal[{0, 10}, {10, 2}];
dt = DelaunayTriangulation[pts];
toPairs[{m_, ns_List}] := Map[{m, #} &, ns];
edges = Union[Sort /@ Flatten[toPairs /@ dt, 1]];
Graph[edges, VertexLabels -> "Name", ImagePadding -> 20,
    GraphLayout -> "PlanarEmbedding", VertexCoordinates -> pts]

enter image description here


Here's one possibility, using an undocumented function for the Delaunay triangulation:

BlockRandom[SeedRandom[131, Method -> "MKL"]; (* for reproducibility *)
            pts = RandomReal[{0, 10}, {10, 2}]];

Graphics`Mesh`MeshInit[];
dt = Delaunay[pts];

Graph[Range[Length[pts]], UndirectedEdge @@@ dt["Edges"], VertexCoordinates -> pts]

Delaunay graph from randomly chosen points

Compare:

GraphicsComplex[dt["Coordinates"],
                {FaceForm[None], EdgeForm[Black], Polygon[dt["Faces"]]}] // Graphics

Delaunay triangles