Triangulation (reprint)

Transfer: https://blog.csdn.net/cloudqiu/article/details/78877311

Write a summary of the triangle, actually it dragged on for three years. This is the longest I dragged an article summarized. Do not write, maybe not this aspect of the future, there is no chance. At the beginning into the project team, the project has just entered the initial stage, we do not have enough urgency is not so high, so I was allowed to have some time to read grid-related materials, paper of a 70, a booklet Polygon Mesh Processing. At that time still very painful, there is no experience in this area.

CAD program, a very basic, important function is to carry out Planar Graphic grid. And among the various mesh, triangular mesh is particularly important. So, that must be mastered triangulation algorithm. In the game, the programmer need only a general 3D model making art (substantially triangular Mesh) introduced to the scene, there are some cases need to be treated again in the game grid engine. So, it is best to be familiar with some triangulation process. Very much want to put a Planar Graphic split into multiple triangles, split ways. Not to mention the case of new fixed-point or other parameters, then split the way even more. Our most commonly used Delaunay triangulation algorithm. Algorithm lib C / C ++ are many. If you use Python, scipy package provides a Delaunay triangulation algorithm, which is one of the most widely used triangulation algorithm, so scipy only provides this one. It is simple to use, but if you want to own for the first time algorithm to achieve this, there is no estimate can be completed one week.

Using an algorithm library, we can quickly realize the function touches, but the business layer for the data structure is definitely unique requirements. Most of the time we estimate the project is part of the business process and the related. As for the algorithm, I do not have time to realize the. Can only get an idea, you learn to use. scipy.spatial.Delaunay only the most simple function, did not see the control line cam angle, side length, overall uniformity, whether the control points in a like function, but C / C ++ lib, such as CGAL, Triangle and others have achieve. triangle course, there are Python Wrapper, can be downloaded here. The next program uses this lib. Reference chapt3 / triangulation.py program, we can quickly achieve triangulation program.

01


Triangulation process, we generally have several common needs:

Graphics in the hole

Drawing a triangle vertex line or curve must be generated fall on this line.

Some areas requiring high pattern density of some triangular, some areas require low values ​​of density.

Angle triangle generated, side length, uniformity, if required by the new control points.

Of course, the real demand may be more complicated than this. In the middle of planar grpahic buckle a few holes this demand too common, such as a wall with windows, doors, there are hollow on clothes. Since it is a hole, it is certainly not participate in the triangulation. Triangulation algorithm accepts most important parameter is the number of discrete vertices. If you want to graph buckle a hole, this hole can only be described by the vertex information.


02


For example figure, the intermediate hollow quadrangle, and requires the use of four sides of the quadrilateral to specify an arbitrary point inside, and the four sides may be described by the vertex pairs. Red cross is an example of a point below the hollow portion. In fact, this process is very simple, Firstly, the entire graphic triangulation, then the portion of the hollow eaten it. python version of the data structure triangle lib entered in the document to explain too little, people talking. As long as output at triangle.get_data ( 'face.1'), we will be able to do a shining example. Control algorithms rely mainly on a triangle lib string passed into the function, such as B = triangle.triangulate (A, 'pqa0.015c'), the meaning of each character of the string can only see the document, as long as the read , or very good use. The following is an example of a graphical triangulation calculation perforated. Please refer to chapt3 / complicateTriangulation.py


03


Easier to determine than the apex of the triangle position on the triangle patches, easier to use. For example, we hope that the fabric on a straight line segment row Buniu buckle. Another example is a fabric such as a straight line segment and suturing the fabric and the other to attend the physical simulation, only the line segment is sutured at the sides of a triangle in order to ensure smooth analog comparator. Similarly, the line segment by only two vertices of said triangle limits if maximum area and minimum acute angle, it can also limit the length of sides of the triangle, then the line segment will be split according to this limitation. As shown below


04


For rendering and simulation, we all want a dense mesh in some places some few sparse in some places, mainly to reduce computational and resource usage. Handled properly, one or two orders of magnitude reduction is not difficult. So, the need is obvious. A method of directly increasing the input vertex, in the second method is given by Constraint region, implemented within the algorithm. Obviously, the first is much simpler.


05


We now focus on technology research and development program is cloth simulation, in fact, may be regarded as a kind cloth simulation finite element analysis. We have some requirements for the grid: there is not such a small acute angle (as far as possible like a regular triangle), to a uniform size. Other estimates of finite element analysis may have more stringent restrictions on the grid. Or need to mesh three-dimensional space, the difficulty that the problem would rise up a level. General development work is also out of the reach.

我们的项目一直在使用C语言版本的triangle 这个lib来做三角化。非常小巧,简单,只有一个入口函数,一个函数就可以完成三角化的工作。

void triangulate(char *, struct triangulateio *, struct triangulateio *, struct triangulateio *);

算法本身可能很复杂,但是lib的使用还算比较简单。第一个参数是字符串,控制了“三角形内角大小,边长,均匀程度”等参数,第二个参数是输入,第三个参数是三角化输出,第四个参数是voronoi输出,一般置为NULL即可。这里要提一下,为什么有voronoi这个参数呢?是因为voronoi tessellation和 delaunay triangulation是对偶的,相当于同一个计算结果换了一种描述而已。但是,每一个参数本身是非常复杂的,定义如下:

struct triangulateio {
    REAL *pointlist; /* In / out */
    REAL *pointattributelist; /* In / out */
    int *pointmarkerlist; /* In / out */
    int numberofpoints; /* In / out */
    int numberofpointattributes; /* In / out */
    
    int *trianglelist; /* In / out */
    REAL *triangleattributelist; /* In / out */
    REAL *trianglearealist; /* In only */
    int *neighborlist; /* Out only */
    int numberoftriangles; /* In / out */
    int numberofcorners; /* In / out */
    int numberoftriangleattributes; /* In / out */
    
    int *segmentlist; /* In / out */
    int *segmentmarkerlist; /* In / out */
    int numberofsegments; /* In / out */
    
    REAL *holelist; /* In / pointer to array copied out */
    int numberofholes; /* In / copied out */
    
    REAL *regionlist; /* In / pointer to array copied out */
    int numberofregions; /* In / copied out */
    
    int *edgelist; /* Out only */
    int *edgemarkerlist; /* Not used with Voronoi diagram; out only */
    REAL *normlist; /* Used only with Voronoi diagram; out only */
    int numberofedges; /* Out only */
};

其实,总结一下,也只有:三角化的顶点(及个数),顶点属性,三角形(输出),线段,洞,区域属性,三角形边(输出),只有四五个是有效的。其中,只有pointlist才是必需的,不用担心很复杂。上面几个图例对应的python调用函数的参数为:A = dict(vertices=vertices, segments=segments, holes=holeMarkerPos),三个二维数组罢了。

  Youtube上有视频对算法的过程做了动画讲解,看起来就直观多了。

http://www.cs.cmu.edu/~quake/triangle.html

http://dzhelil.info/triangle/index.html  triangle python wrapper

https://people.eecs.berkeley.edu/~jrs/papers/imrtalk.pdf

https://people.eecs.berkeley.edu/~jrs/papers/triangle.pdf

————————————————

Guess you like

Origin www.cnblogs.com/gispathfinder/p/12501214.html