artem-ogre / CDT

Constrained Delaunay Triangulation (C++)
https://artem-ogre.github.io/CDT/
Mozilla Public License 2.0
947 stars 125 forks source link

Generate some degenerate triangles #169

Closed wangkeke1800 closed 3 months ago

wangkeke1800 commented 3 months ago

I conducted a simple test using your code. There is a triangle with vertices 0, 1, and 2. The two points on its edges are 3 and 4. The generated results are as follows: 132, 423, 103, 043. Triangle 103 is a degenerate triangle and does not comply with the Delaunay rule. I tested it using other open-source code and obtained the correct result: 123, 034, 324. See as https://github.com/bl4ckb0ne/delaunay-triangulation.git

/***************************
........................0
...................../...|
................../..... |
................/....... |
.............3...........4
.........../.............|
......../................|
.....1...................2
*****************************/

Here is the test code:

    std::vector<CDT::V2d<double>>delaunay_points2D;
    delaunay_points2D.emplace_back(CDT::V2d<double>::make(0,200));
    delaunay_points2D.emplace_back(CDT::V2d<double>::make(200,0));
    delaunay_points2D.emplace_back(CDT::V2d<double>::make(0,0));
    delaunay_points2D.emplace_back(CDT::V2d<double>::make(99.7665 ,100.233));
    delaunay_points2D.emplace_back(CDT::V2d<double>::make(0, 76.5881));

    std::vector<CDT::Edge>edges;
    edges.emplace_back(3,4);

    CDT::Triangulation<double> cdt;
    cdt.insertVertices(delaunay_points2D);
    cdt.insertEdges(edges);
    cdt.eraseSuperTriangle();

    auto tris = cdt.triangles;
artem-ogre commented 3 months ago

Point (99.7665 ,100.233) is not exactly on the line (0, 0) -> (200, 200). An example of a point exactly on the line is (100, 100). CDT uses numerically robust orient2d predicate and is pedantic like that. The triangle is a almost flat but not degenerate according to the mathematical definition (all points exactly on the same line). I hope this answers your question.

artem-ogre commented 3 months ago

I am closing the issue but feel free to comment in here and I will re-open if needed.