图形学中的凸包 - Mathematica

5

尝试使用ComputationalGeometry包中的PlanarGraphPlot绘制凸包时,如果在图形中使用,则无法正常工作。

有没有想法如何使用Graphics绘制凸包?

2个回答

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
  }
 ]

enter image description here


其实,你已经使用Faceform[white]解决了这个问题。但如果我需要在ConvexHull下显示一些图形,是否还有其他方法? - 500
如果您不想看到这些点,那么最简单的方法就是省略绘制它们的行(Point@pts),我只是为了说明而包含它。我不确定我是否理解您的意思。我也不明白您关于 Faceform[white] 的问题。我使用 Faceform[] 使多边形透明。 - Sjoerd C. de Vries
谢谢。对于混淆表示抱歉,我现在弄清楚了! - 500

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]]]]]

enter image description here


哎呀,我忘记了如何附加一个gif。 - Daniel Lichtblau
你可能是在开玩笑,但以防万一:按编辑窗口上方的小图形按钮提供链接或路径。如果我没有记错,我通常会导出为PNG,因为它比GIF具有更好的颜色分辨率。 - Sjoerd C. de Vries
投票删除。无gif,无答案。 - Dr. belisarius
不是开玩笑。我确实做对了,但没有图片显示出来。对JPEG有效,但对GIF无效?! - Daniel Lichtblau
@Sjoerd C. de Vries 啊,那可能就是发生的事情。谢谢你的解释。 - Daniel Lichtblau
显示剩余2条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接