【问题标题】:ConvexHull in Graphics - Mathematica图形中的 ConvexHull - Mathematica
【发布时间】:2011-09-10 09:02:56
【问题描述】:

尝试使用 ComputationalGeometry 包中的 PlanarGraphPlot 绘制 ConvexHull,但在图形中使用时不起作用。

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

【问题讨论】:

    标签: graphics wolfram-mathematica convex-hull


    【解决方案1】:
    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
      }
     ]
    

    【讨论】:

    • 嗯,实际上你已经用 Faceform[white] 解决了这个问题。还有另一种方法,因为我可能必须在 ConvexHull 下显示一些图形
    • @500 如果您不想看到这些点,没有什么比省略绘制它们的线更容易的了,我为了说明目的而包括在内 (Point@pts)。我不确定我是否理解你的意思。我也不明白你关于Faceform[white] 的问题。我使用Faceform[] 使多边形透明。
    • 谢谢。对不起,我现在明白了!
    【解决方案2】:

    不确定到底想要什么。也许下面的代码会让你开始。

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

    【讨论】:

    • 哎哟。我忘了如何附加 gif。
    • 您可能在开玩笑,但以防万一:按编辑窗口上方的小图形按钮以提供链接或路径。我通常会导出为 PNG,因为如果我没记错的话,它的颜色分辨率比 GIF 更好。
    • 投票删除。没有 gif,没有答案。
    • 不是在开玩笑。实际上,我做得正确,但没有图像出现。为 jpeg 但不是 gif 工作?!
    • 这很奇怪;我通常将 GIF 用于 StackOverflow。
    猜你喜欢
    • 1970-01-01
    • 2011-09-12
    • 2010-12-09
    • 2011-06-10
    • 2011-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-13
    相关资源
    最近更新 更多