Выпуклый корпус в графике - Mathematica - PullRequest
5 голосов
/ 07 июня 2011

Пытаясь построить ConvexHull с помощью PlanarGraphPlot из пакета ComputationalGeometry, он не работает при использовании в графике.

Есть идеи о том, как построить ConvexHull с помощью Graphics?

Ответы [ 2 ]

9 голосов
/ 08 июня 2011
Needs["ComputationalGeometry`"]
pts = RandomReal[{0, 10}, {60, 2}];

Graphics[
 {
  Point@pts,
  FaceForm[], EdgeForm[Red],
  Polygon@pts[[ConvexHull[pts]]]
  }
 ]

или

cpts = pts[[ConvexHull[pts]]];
AppendTo[cpts, cpts[[1]]];

Graphics[
 {
  Point@pts,
  Red,
  Line@cpts
  }
 ]

enter image description here

5 голосов
/ 08 июня 2011

Не уверен, что именно то, что хотел. Возможно, приведенный ниже код поможет вам начать работу.

 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

...