【问题标题】:Given Polygon and Fix Points, Find the Triangle Meshes给定多边形和固定点,找到三角形网格
【发布时间】:2010-12-27 07:17:08
【问题描述】:

假设我有一个多边形,我想对它进行网格划分。为了进一步对我得到的网格施加约束,我将提供一个固定点列表(必须位于多边形内),以便它们必须由生成的三角形元素连接。

matlab 的命令是什么?我试过delaunay 命令,但它不能在凹多边形上工作,因为delaunay 命令总是会返回一个包含凸区域的元素列表。

【问题讨论】:

    标签: matlab


    【解决方案1】:

    您要使用的函数是DelaunayTri,您可以按照以下步骤操作:

    • 创建多边形中的边缘点列表。
    • 获取多边形的所有顶点,并将它们与要包含在多边形内的其他固定点结合起来。
    • 创建一个受约束的三角剖分(正如我在其他答案 herehere 中说明的那样)。
    • 正如您所指出的,这将创建凸包的三角剖分(即使您有一个凹多边形),因此您必须使用方法 inOutStatus 删除受约束边之外的三角形(也在答案中说明以上链接)。

    这里有一些示例代码:

    polygonVertices = [0 0;...  %# Concave polygon vertices
                       0 1;...
                       1 1;...
                       0.5 0.5;...
                       1 0];
    polygonEdges = [1 2;...  %# Polygon edges (indices of connected vertices)
                    2 3;...
                    3 4;...
                    4 5;...
                    5 1];
    otherVertices = [0.5.*rand(5,1) rand(5,1)];   %# Additional vertices to be added
                                                  %#   inside the polygon
    vertices = [polygonVertices; otherVertices];  %# Collect all the vertices
    dt = DelaunayTri(vertices,polygonEdges);  %# Create a constrained triangulation
    isInside = inOutStatus(dt);  %# Find the indices of inside triangles
    faces = dt(isInside,:);      %# Get the face indices of the inside triangles
    

    现在变量facesvertices 可以用于plot the meshed polygon


    使用旧版本的 MATLAB...

    查看archived version documentation注意:需要一个 MathWorks 帐户),可以看到DelaunayTri 首次出现在版本 7.8.0 (2009a) 中。在此之前,唯一可用于执行二维 Delaunay 三角剖分的内置功能是 delaunay,它基于 Qhull,因此无法支持受限三角剖分或非凸曲面的三角剖分。

    较新的DelaunayTri 使用CGAL。因此,对于版本早于 7.8.0 的用户,一种选择是 create MEX-files 在 MATLAB 中连接 CGAL 例程。例如,如果您要对凹多边形进行三角剖分,则可以创建一个 MEX 文件来连接convex partitioning routines in CGAL 之一,以便将凹多边形分解为一组凸多边形。然后delaunay 可用于对每个凸多边形进行三角剖分,并将最后一组三角剖分分组为一个更大的凹多边形三角剖分。

    【讨论】:

    • 我的 matlab 版本 (7.6.0) 没有 DelaunayTri 和 inOutStatus 方法。 inOutStatus 有替代品吗?
    • @Ngu Soon Hui:我得四处看看,看看那个版本有什么可用的。如果我找到使用旧功能的方法,我会更新帖子。
    • @Ngu Soon Hui:我在答案中添加了使用旧 MATLAB 版本的最佳建议。希望对您有所帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-24
    • 2010-12-03
    相关资源
    最近更新 更多