MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   给定多边形和固定点,找到三角形网格 (https://www.labfans.com/bbs/showthread.php?t=24265)

poster 2019-12-10 20:48

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

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



[B]回答:[/B]

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

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来[URL="http://www.mathworks.com/help/techdoc/ref/patch.html"]绘制网格多边形[/URL] 。




[B]使用旧版本的MATLAB ... [/B]

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

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



[url=https://stackoverflow.com/questions/4537167]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 16:08

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.