ConvexHull in Graphics - Mathematica

后端 未结 2 815
清酒与你
清酒与你 2021-01-13 01:44

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 ConvexH

相关标签:
2条回答
  • 2021-01-13 02:25
    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

    0 讨论(0)
  • 2021-01-13 02:25

    Not sure exactly what is wanted. Maybe the code below will get you started.

     pts = RandomReal[{-10, 10}, {20, 2}]
    (*
    Out[1]= {{1.7178, -1.11179}, {-7.10708, -8.1637},
     {8.74461, -2.42551}, {6.64129, -2.87008}, {9.9008, 6.47825},
     {8.27081, 9.94116}, {9.97325, 7.61094}, {-2.7876, 9.70449},
     {-3.69357, 0.0253506}, {-0.503817, -1.98649}, {6.3056, -1.16892},
     {-4.69983, -1.93242}, {-6.09983, 7.49229}, {8.08545, 6.67951},
     {-6.91195, 8.34752}, {-2.63136, 6.0506}, {-0.130006, 2.10929},
     {1.64401, 3.32165}, {0.611335, -8.11364}, {-2.03548, -9.37277}}
    *)
    With[{hull = pts[[Graphics`Mesh`ConvexHull[pts]]]}, 
      Graphics[Line[Append[hull, First[hull]]]]]
    

    enter image description here

    0 讨论(0)
提交回复
热议问题