尝试使用ComputationalGeometry包中的PlanarGraphPlot绘制ConvexHull,在图形中使用它时不起作用。
关于如何使用Graphics绘制ConvexHull的任何想法?
答案 0 :(得分:9)
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
}
]
答案 1 :(得分:5)
不确定到底想要什么。也许下面的代码可以帮助您入门。
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]]]]]