1

Considering the following example (from Sjoerd Solution on plotting a ConvexHull)

Needs["ComputationalGeometry`"]
pts = RandomReal[{0, 10}, {60, 2}];
dtpts=DelaunayTriangulation[pts]

I would now like to plot the DelaunayTriangulation for a set of point but can`t figure out the Plot syntax using Graphics.

Thoughts ?

Community
  • 1
  • 1
500
  • 6,509
  • 8
  • 46
  • 80

3 Answers3

4

Method one, using polygons like Sjoerd, but without the problem caused by points on the convex hull:

Graphics[{FaceForm[], EdgeForm[Black], 
  Polygon[pts[[#]] & /@ 
    DeleteCases[dtpts, {i_, _} /; MemberQ[ConvexHull[pts], i]][[All, 
      2]]], Red, Point[pts]}]

Method two, using lines connecting the adjacent points:

edges[pts_, {a_, l_List}] := {pts[[a]], #} & /@ pts[[l]]
Graphics[{Line[edges[pts, #]] & /@ dtpts, Red, Point[pts]}]

Both of these methods result in duplicated primitives (three polygons or two lines, from using each point as a starting point.)

We can modify the data slightly and use built in visualization functions:

Graphics[{FaceForm[], EdgeForm[Black], 
  Cases[Normal[
    ListDensityPlot[{##, 0.} & @@@ pts, Mesh -> All]], _Polygon, 
   Infinity], Red, Point[pts]}, ImageSize -> 175]

enter image description here

Brett Champion
  • 8,497
  • 1
  • 27
  • 44
3
Graphics[
  GraphicsComplex[
    pts, 
    {
      Function[{startPt, finishPts},Line[{startPt, #}] & /@ finishPts] @@@ dtpts, 
      Red, Point@Range[Length@pts]
    }
   ]
  ]

enter image description here

And if you need real polygons:

Graphics[
 GraphicsComplex[
  pts, 
  {EdgeForm[Black], 
   Function[{startPt, finishPts}, 
      {FaceForm[RGBColor[RandomReal[], RandomReal[], RandomReal[]]], 
        Polygon[{startPt, ##}]} & @@@ 
          Transpose[{Drop[finishPts, 1], 
                     Drop[RotateRight@finishPts, 1]
                    }
          ]
         ] @@@ dtpts, 
   Red, Point@Range[Length@pts]
  }
 ]
]

enter image description here

Sjoerd C. de Vries
  • 16,122
  • 3
  • 42
  • 94
1

I like Sjoerd's use of GraphicsComplex, but I don't see the need for the baroque code in the middle.

This appears to work just fine:

Needs["ComputationalGeometry`"]
pts = RandomReal[{0, 10}, {60, 2}];
dtpts = DelaunayTriangulation[pts];

Lines

Graphics[GraphicsComplex[
  pts,
  {Line /@ Thread /@ dtpts, Red, Point@Range@Length@pts}
]]

enter image description here


Polygons

Graphics[GraphicsComplex[
  pts,
  {
    EdgeForm[Black],
    ( {FaceForm[RGBColor @@ RandomReal[1, 3]], Polygon@#} & /@ 
      Append @@@ Thread@{Partition[#2, 2, 1], #} & ) @@@ dtpts,
    Red,
    Point@Range[Length@pts]
  }
]]

enter image description here

Mr.Wizard
  • 24,179
  • 5
  • 44
  • 125