如何用凸形状形成凹形状?

发布于 2024-11-19 22:59:13 字数 378 浏览 3 评论 0原文

我试图绕过只能在 SFML C++ 库中形成凸形状的规则。

为此,我计划测试给定的顶点,如果是凹的, 将顶点分成组,测试每个组的凹性, 并重复直到得到看起来像的全套凹形形状 组合起来就像原来的形状

我想知道的是...

  • 测试形状凹度的方程式是什么:它是什么以及它如何工作?

  • 我将如何分割凹形状的顶点,以便最终形成形状由尽可能少的凸形状组成可能吗?

  • 实现我的目标的最佳实践是什么?

谢谢!


i'm trying to get around the rule of only being able to form convex shapes in the SFML c++ library.

To do this I'm planning on testing given vertices, and if concave,
splitting the vertices into groups, testing each groups' concaveness,
and repeating until a full set of concave shapes results that look
just like the original shape when put together

What I would like to know is...

  • What the equation for testing a shapes concaveness is: What is it and how does it work?

  • How would i split up the vertices of the concave shape so in the end the shape is formed out of as few convex shapes as possible?

  • Whats the best practice for achieving my goal?

Thanks!


如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

走过海棠暮 2024-11-26 22:59:14

Boost Geometry 库 昨天发布,有一个实现<代码>凸包算法。一张图片表达了一千多个单词:

在此处输入图像描述

尽管这构建了一个“新的” ' 非凹形(即凸形)的形状;这可能是也可能不是您想要的。然而,在此过程中,算法必然能够对凹/凸形状进行分类,因此您可能仍然对该库感兴趣。

有关凸包算法的一般信息:


由于 Adrian Japon 或多或少地建议“命中测试”(遏制测试)是关心凸/凹几何形状的常见原因,而无需话不多说,我将重点介绍相应的 Boost Geometry 算法:

再说一遍,真的是因为图片太漂亮了。请注意,虽然图片建议查询多边形上的点,但这些算法是完全通用的,可用于测试另一个n多边形的完全包含子>

在此处输入图像描述

The Boost Geometry library that was published yesterday, has an implementation of Convex Hull algorithm. A picture says more than a thousand words:

enter image description here

Although this constructs a 'new' shape that is non-concave (i.e. convex); This may or may not be precisely what you want. However, in the process the algorithm is bound to be able to classify shape a concave/convex, so you'd likely be interested in the library nonetheless.

General information on convex hull algorithm:


Since Adrian Japon more or less suggested that 'hit testing' (containment test) is of a usual reason to care about convex/concave geometries, without further ado, I'll highlight the corresponding Boost Geometry algorithm for that: within.

Again, really because the picture is so pretty. Note that though the picture suggests querying for a point against a polygon, the algorithms are fully generic and can be used to test complete containment on n-dimensional polygons in another

enter image description here

逐鹿 2024-11-26 22:59:14

好吧,只是将所有信息混合在一起:

  • 要测试多边形凹度,请查看此页由阿德里安提供
    泰勒
  • 实现我的目标的一种方法是使用单调分解和三角测量
  • 您可以在 这个可爱的网站:(摘要如下)

img 1

  • 最后,使用 此幻灯片

    1. 将 u1 和 u2 压入堆栈。
    2. j = 3 /* j 是当前顶点的索引 */
    3. u = uj
    4. 情况(i):u 与v1 相邻,但不与vi 相邻。
      添加对角线 uv2、uv3、...、uvi。
      从堆栈中弹出 vi、vi-1、...、v1。
      将 vi、u 压入堆栈。
      情况(ii):u 与vi 相邻,但不与v1 相邻。
      当我> 1 且角 uvivi-1 < 
      添加对角线 uvi-1
      从堆栈中弹出 vi
      最后
      推你
      情况(iii):u 与v1 和vi 都相邻。
      添加对角线 uv2、uv3、...、uvi-1。
      退出
    5. j = j + 1
      转到步骤 3。

**Note:**
By “adjacent” we mean connected by an edge in P.   
Recall that v1 is the bottom of the stack, vi is the top.    
By “Push” we mean push the item(s) to the back of the list    

希望这对某人有帮助...但我仍在寻找更好/更快的解决方案。

Alright, just to mash all the info together:

  • To test polygon Concaveness, look at this page given by Adrian
    Taylor
  • One way to accomplish my goal is to use Monotone Decomposition and Triangulation
  • You can learn about Monotone Decomposition at this lovely site: (summary of it below)

img 1

  • Finally, triangulate the now Monotone shapes using the information in this Powerpoint:

    1. Push u1 and u2 on the stack.
    2. j = 3 /* j is index of current vertex */
    3. u = uj
    4. Case (i): u is adjacent to v1 but not vi.
      add diagonals uv2, uv3, …, uvi.
      pop vi, vi-1, …, v1 from stack.
      push vi, u on stack.
      Case (ii): u is adjacent to vi but not v1.
      while i > 1 and angle uvivi-1 < 
      add diagonal uvi-1
      pop vi from stack
      endwhile
      push u
      Case (iii): u adjacent to both v1 and vi.
      add diagonals uv2, uv3, …, uvi-1.
      exit
    5. j = j + 1
      Go to step 3.

**Note:**
By “adjacent” we mean connected by an edge in P.   
Recall that v1 is the bottom of the stack, vi is the top.    
By “Push” we mean push the item(s) to the back of the list    

Hope this helps someone... but I'm still looking for any better/faster solutions.

远山浅 2024-11-26 22:59:14

需要考虑的一些事情:

  • 左手角和右手角(叉积的符号是区分的简单方法)。凸形中的所有角都是相同的旋向性。

  • 扩展边并添加新顶点可能会比在现有顶点之间添加边获得更好的结果。

Some things to think about:

  • Left-handed and right-handed corners (the sign of the cross-product is an easy way to distinguish). All corners in a convex shape are the same handed-ness.

  • Extending an edge and adding a new vertex may give you better results than adding edges between existing vertices.

战皆罪 2024-11-26 22:59:14

我假设您将多边形作为点列表,一种非常简单的方法是围绕多边形并考虑连续点(A,B,C)的三元组序列。

然后,您只需检查 det(AB,BC) 在某一点是否更改其符号,其中

det(AB,AC) = (x_a-x_b)(yc-yb) - (x_c-x_b)(y_a-y_b)

I assume you have your polygon as a list of point, a very simple way would be to go around your polygon and consider the sequence of triplet of consecutive points (A,B,C).

Then you just check that at one point det(AB,BC) changes its sign, where

det(AB,AC) = (x_a-x_b)(yc-yb) - (x_c-x_b)(y_a-y_b)

甜扑 2024-11-26 22:59:13

您可以通过绕过所有边缘并检查下一条边缘始终沿相同方向移动(左/右手)来测试形状是否为凸包。这是一种快速且廉价的算法。这里有一个实现:en.wikipedia.org/wiki/Graham_scan

如果你不这样做如果没有凸包,请执行包包装算法以获得包含所有点的凸包(同样非常快)。 en.wikipedia.org/wiki/Gift_wrapping_algorithm

现在,寻找形状上的点,但是不在凸包上。对于这些点的每次运行,从这些点(加上凸包两侧的 2 个点)创建一个新形状。

递归现在是你的朋友:对你刚刚制作的每个子形状执行完全相同的过程。

我已经使用这种技术来测试任意形状内包含的点:即该点必须位于凸包内部(易于测试),但不是任何子形状或它们的子形状或它们的子形状-形状....

You can test for a shape being a convex hull by going round all the edges and checking the next edge is always moving in the same direction (left/right handed). This is a quick and cheap algorithm. There is an implementation of this here: en.wikipedia.org/wiki/Graham_scan

If you don't have a convex hull, perform a package wrapping algorithm to get a convex hull that encompasses all your points (again quite fast). en.wikipedia.org/wiki/Gift_wrapping_algorithm

Now, look for points that are on your shape, but aren't on the convex hull. For each run of these points, create a new shape from these points (plus the 2 either side on the convex hull).

Recursion is now your friend: do the exact same process on each of the sub-shapes you have just made.

I have used this techniques to test for a point being contained inside an arbitrary shape: i.e. the point must be inside the convex hull (easy to test), but not any of the sub-shapes, or their sub-shapes, or their sub-shapes....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文