2011-06-07 79 views
5

尝试绘制ConvexHull使用ComputationalGeometry包中的PlanarGraphPlot,它在图形中使用时不起作用。图形中的凸凹 - Mathematica

关于如何使用图形绘制ConvexHull的任何想法?

回答

10
Needs["ComputationalGeometry`"] 
pts = RandomReal[{0, 10}, {60, 2}]; 

Graphics[ 
{ 
    [email protected], 
    FaceForm[], EdgeForm[Red], 
    [email protected][[ConvexHull[pts]]] 
    } 
] 

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

Graphics[ 
{ 
    [email protected], 
    Red, 
    [email protected] 
    } 
] 

enter image description here

+0

嗯,其实你有这样想通了使用Faceform [白]。是否有另一种方法,因为我可能需要在ConvexHull – 500 2011-06-07 20:11:31

+0

@ 500下显示一些图形如果你不想看到这些点,没有什么比留下绘制它们的线更容易了,并且为了说明目的我将它包含在内('Point @ pts')。我不确定在这里是否了解你。我不明白你关于'Faceform [white]'的问题。我使用'Faceform []'使多边形透明。 – 2011-06-07 20:30:03

+0

谢谢。对不起,我感到困惑,现在想通了! – 500 2011-06-07 20:51:42

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

+0

哎。我忘了如何附加一个gif。 – 2011-06-07 20:07:05

+0

您可能正在开玩笑,但以防万一您不需要:按编辑窗口上方的小图形按钮以提供链接或路径。我通常输出到PNG,因为如果我没有错误的话,它的色彩分辨率比GIF好。 – 2011-06-07 20:37:03

+0

投票删除。没有gif,没有答案。 – 2011-06-07 20:46:23