三角测量算法
我决定创建一个简单的演示,将多边形划分为三角形集。到目前为止,我得到的是:
给出了一个顺序顶点列表(P1),形成多边形边缘(多边形在大多数情况下不是凸的);需要一个三角形集合
循环遍历多边形P1内的所有顶点并找到一个(v),它将满足下一个子句:
从多边形中删除v并将新的保存到P2< /em> v 的前一个顶点 连接到下一个形成 a 不与任何 P2 相交的线 边
v 不在 P2 内
如果满足这些条件,我们可以将 P1 替换为 (P2 + triangle( prev(v), v, next(v)) )并重复此操作,直到 P1 包含超过 3 个顶点。
那么,问题是:这个算法是否正确?如何使用 C / C++ 以最明显和最简单的方式实现它?
I've decided to create a simple demo, dividing a polygon into triangle set. Here what i've got so far:
A sequential vertex list is given (P1) forming polygon edges (polygon is not convex in most cases); a triangle set is needed
Loop through all the vertices within the polygon P1 and find the one (v), which will satisfy next clauses:
remove v from polygon and save the new one to P2 previous vertex to v
connected to its next one form a
line which do not cross any of P2
edgesv is not inside P2
If these are satisfied, we can replace P1 with (P2 + triangle( prev(v), v, next(v)) ) and repeat this action until P1 contains more than 3 vertices.
So, the questions are: is this algorithm correct and how it could be implemented using C / C++ using the most obvious and simple way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您正在描述耳朵修剪方法。该方法的代码位于 http://cs.smith.edu/~orourke/ books/ftp.html ;这是Computational Geometry in C一书中描述的代码。
I think you're describing the ear clipping method. There's code for that method at http://cs.smith.edu/~orourke/books/ftp.html ; it's the code described in the book Computational Geometry in C.
看来我已经完成了这个算法的实现。请某人验证一下。谢谢!
Seems that i'm done with this algorithm implementation. Please, verify it someone. Thanks!
下面一行代码有错误。该行位于类的 push() 函数的 for 循环中:
您没有传递推送的 Point,而是一个空元素向量本身。我将线路更改为
并且有效。
The code has an error on the line below. The line is in the for loop in the push() function of your class:
You are not passing the pushed Point, but an empty element of the vector itself. I changed the line to
and it worked.