Search code examples
graphicswolfram-mathematicaconvex-hull

ConvexHull in Graphics - Mathematica


Trying to plot a ConvexHull Using PlanarGraphPlot from the ComputationalGeometry package, it does not work when used in graphics.

Any Idea on how to plot the ConvexHull using Graphics ?


Solution

  • Needs["ComputationalGeometry`"]
    pts = RandomReal[{0, 10}, {60, 2}];
    
    Graphics[
     {
      Point@pts,
      FaceForm[], EdgeForm[Red],
      Polygon@pts[[ConvexHull[pts]]]
      }
     ]
    

    or

    cpts = pts[[ConvexHull[pts]]];
    AppendTo[cpts, cpts[[1]]];
    
    Graphics[
     {
      Point@pts,
      Red,
      Line@cpts
      }
     ]
    

    enter image description here