登录论坛

查看完整版本 : 给定多边形和固定点,找到三角形网格


poster
2019-12-10, 20:48
假设我有一个多边形,并且想对其进行网格化。为了进一步限制我得到的网格,我将提供一个固定点列表(必须位于多边形内),以便它们必须通过生成的三角形元素进行连接。

matlab命令可以做什么?我尝试了delaunay (http://www.mathworks.com/help/techdoc/ref/delaunay.html)命令,但是它不适用于凹面多边形,因为delaunay命令将始终向我返回包含凸面区域的元素列表。



回答:

您要使用的函数是DelaunayTri (http://www.mathworks.com/help/techdoc/ref/delaunaytri.html) ,您将按照以下步骤操作:


创建多边形中的边点列表。
取多边形的所有顶点,并将它们与要包含在多边形内的其他固定点合并。
创建约束三角剖分(如我在此处 (https://stackoverflow.com/questions/1700522/matlab-create-delaunay-triangulation-with-opening/1701496#1701496)和此处的 (https://stackoverflow.com/questions/4391186/how-can-i-create-a-filled-polygon-from-unordered-edge-data-in-matlab/4392611#4392611)其他答案所示)。
如您所述,这将创建凸包的三角剖分(即使您具有凹多边形),因此您将必须使用inOutStatus (http://www.mathworks.com/help/techdoc/ref/delaunaytri.inoutstatus.html)方法(在上面的答案中也进行了说明)删除受约束的边缘之外的三角形。
这是一些示例代码:

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 现在,可以使用变量faces和vertices来绘制网格多边形 (http://www.mathworks.com/help/techdoc/ref/patch.html) 。




使用旧版本的MATLAB ...

查看存档的版本文档 (http://www.mathworks.com/help/doc-archives.html) ( 注意:需要使用MathWorks帐户),可以看到DelaunayTri (http://www.mathworks.com/help/techdoc/ref/delaunaytri.html)首次出现在版本7.8.0(2009a)中。在此之前,唯一可用于执行二维Delaunay三角剖分的内置功能是delaunay (http://www.mathworks.com/help/techdoc/ref/delaunay.html) ,它基于Qhull (http://www.qhull.org/) ,因此无法支持约束三角剖分或非凸曲面的三角剖分。

较新的DelaunayTri (http://www.mathworks.com/help/techdoc/ref/delaunaytri.html)使用CGAL (http://www.cgal.org/) 。因此,对于版本低于7.8.0的用户,一种选择是创建MEX文件 (http://www.mathworks.com/support/tech-notes/1600/1605.html)以在MATLAB中连接CGAL例程。例如,如果您要对一个凹面多边形进行三角剖分,则可以创建一个MEX文件来连接CGAL (http://www.cgal.org/Manual/3.2/doc_html/cgal_manual/Partition_2/Chapter_main.html#Section_9.3)中的一个凸面分区例程 (http://www.cgal.org/Manual/3.2/doc_html/cgal_manual/Partition_2/Chapter_main.html#Section_9.3) ,以便将凹面多边形分解为一组凸面多边形。然后可以使用delaunay (http://www.mathworks.com/help/techdoc/ref/delaunay.html)对每个凸多边形进行三角剖分,并将最终的三角剖分分组为一个更大的凹多边形三角剖分。



更多&回答... (https://stackoverflow.com/questions/4537167)