【问题标题】:Has anyone already used the Triangle/Triangle++ library in a C++ project ? (delaunay triangulation)有没有人在 C++ 项目中使用过 Triangle/Triangle++ 库? (德劳内三角剖分)
【发布时间】:2013-11-21 22:24:05
【问题描述】:

我正在使用 SFML,我想对一组随机点进行 delaunay 三角剖分。

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

我正在使用 triangle++,一个 c++ 包装器

http://www.compgeom.com/~piyush/scripts/triangle/

我添加了那些#defines

#define REDUCED  
#define ANSI_DECLARATORS  
#define TRILIBRARY  
#define CDT_ONLY  
#define NO_TIMER  
#define CYGWIN  

这个编译,它运行良好,但现在它计算了这些东西,我如何得到顶点之间的边缘?

【问题讨论】:

    标签: c++ visual-c++ triangulation delaunay


    【解决方案1】:

    使用 numberoftriangles、trianglelist、pointlist。对于每个三角形,您在 trianglelist 中有 3 个数字,它们是三角形 3 个角的 pointlist 内的索引。它们不会直接给你顶点,但你可以很容易地从那里得到它们。

    如果还不清楚,请告诉我。

    for (int i = 0; i < numberoftriangles; ++i) {
       int point1Index = trianglelist[i * 3 + 0];
       int point2Index = trianglelist[i * 3 + 1];
       int point3Index = trianglelist[i * 3 + 2];
    
       REAL point1X = pointlist[2 * point1Index + 0];
       REAL point1Y = pointlist[2 * point1Index + 1];
       ... etc
    }
    
    /*  `trianglelist':  An array of triangle corners.  The first triangle's     */
    /*    first corner is at index [0], followed by its other two corners in     */
    /*    counterclockwise order, followed by any other nodes if the triangle    */
    /*    represents a nonlinear element.  Each triangle occupies                */
    /*    `numberofcorners' ints.                                                */
    
    /*  `pointlist':  An array of point coordinates.  The first point's x        */
    /*    coordinate is at index [0] and its y coordinate at index [1], followed */
    /*    by the coordinates of the remaining points.  Each point occupies two   */
    /*    REALs.  
    

    【讨论】:

    • 我忘了说我使用的是 C++ 包装三角形++
    【解决方案2】:

    这不是很清楚,但是fiterator意味着面迭代器,而面是三角形。 Org、Dest 和 Apex 是这些顶点的索引。

    for(Delaunay::fIterator fit  = delobject.fbegin(); 
                            fit != delobject.fend(); 
                          ++fit)
    {
        cout << " Org " <<  delobject.Org(fit)  << ", " 
             << " Dest " << delobject.Dest(fit) << ", " 
             << " Apex " << delobject.Apex(fit) << //" \t: Area = " 
    }
    

    别忘了,Triangle++ 并不需要你输入实际的 Triangle.c 代码,所以它真的很容易使用。

    【讨论】:

      猜你喜欢
      • 2012-04-27
      • 1970-01-01
      • 1970-01-01
      • 2022-01-09
      • 2020-05-12
      • 2012-05-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多