1

I'm trying to implement Delaunay Triangulation with a simple grid as a test input, and it seems to work up to the third row, in which the triangles then start to overlap.

Rows 1 and 2

Row 1 Row 2

Row 3

Row 3

Final

Final

I'm having trouble understanding exactly what it is that causes this behaviour. Here is some pseudo-code:

for each vertex v
    edgeBuffer = [];
    for each triangle
        if v is in the triangle's circumscribed circle
            for each edge in the triangle
                check if it's already in edgeBuffer
                if not, add it
                otherwise, remove it
            remove triangle
    for each edge in edgeBuffer
        create a new triangle between edge and v

Actual code:

$("#add").click(function () { // User clicks a button to add the next vertex

    currVertIndex++;
    var v = vertList[currVertIndex];
    var edges = [];

    for (var i = 0; i < triangles.length; i++) {
        if (triangles[i].circc.containsVertex(v)) {
            var nextIndex;
            for (var e = 0; e < 3; e++) {
                nextIndex = (e + 1 == 3) ? 0 : e + 1;
                var newEdge = new Edge(triangles[i].v[e], triangles[i].v[nextIndex]);
                edges = addEdgeIfNew(newEdge, edges);
            }
            triangles.splice(i, 1);
            i--;
        }
    }

    for (var i = 0; i < edges.length; i++) {
        triangles.push(new Triangle(
            edges[i].v[0],
            edges[i].v[1],
            v
        ));
    }

});

What is going wrong here? Fiddle

Edit: This is not a problem of duplicate edges not being removed...that was my previous question. That's fixed now. You can compare the images here with the images there to see that.

idlackage
  • 2,715
  • 8
  • 31
  • 52
  • try running that fiddle in Chrome, and you'll find that there are quite a few errors in the JS that need fixing first. – Mike 'Pomax' Kamermans Apr 15 '15 at 22:31
  • possible duplicate of [Duplicate edges not being removed in Delaunay Triangle construction](http://stackoverflow.com/questions/29639924/duplicate-edges-not-being-removed-in-delaunay-triangle-construction) – Micromega Apr 16 '15 at 16:53

1 Answers1

0

If the triangle overlap then there is 4 vertices in the circumsphere of the current triangle. Then you need to remove all 4 vertices.

Micromega
  • 12,486
  • 7
  • 35
  • 72