如何在 MATLAB 中从无序边缘数据创建填充多边形?
我想使用无序的边缘数据(边缘每个点的 X,Y 坐标)创建一个多边形,并且我想用某种颜色填充该多边形。
有什么建议我可以如何实现这一点吗?
I want to create a polygon using edge data (X,Y coordinates of each point of edge) that is unordered, and I want to fill that polygon with some color.
Any suggestions how I can accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的多边形是凸,您可以使用函数 CONVHULL 并使用绘图函数 补丁。例如:
如果您的多边形是凹的,那就会变得更加棘手。您必须通过比较边缘线的端点并以顺时针或逆时针方式对它们进行排序来自行重新排序边缘线。
...但是如果这听起来编码工作量太大,您可以通过创建 顶点的约束 Delaunay 三角剖分,找到约束边内侧的三角形,然后使用 补丁。例如:
上面将显示多边形,并在形成它的每个子三角形周围显示边缘线。如果您只想在整个多边形的外部显示一条边缘线,您可以添加以下内容:
If your polygon is convex, you can just compute the convex hull from the vertices using the function CONVHULL and plot the polygon using the plotting function PATCH. For example:
If your polygon is instead concave, that becomes trickier. You would have to reorder the edge lines yourself by comparing their end points and ordering them in either a clockwise or counterclockwise fashion.
...but if that sounds like too much work to code up, you can sidestep the issue by creating a constrained Delaunay triangulation of the vertex points, find the triangles on the inside of the constrained edges, then plot these individual triangles that form the polygon using PATCH. For example:
The above will display the polygon with edge lines around each sub-triangle that forms it. If you just want an edge line shown around the outside of the entire polygon, you can add the following:
我认为您正在寻找
patch()
< /a> 函数。您可以用它制作 2-D 和 3-D 多边形。I think you're looking for the
patch()
function. You can do 2-D and 3-D polygons with it.