0

I am trying to implement the algorithm given in (1) for get a Delaunay Triangulation of a set of points, but I get stuck when I try it to handle degenerated cases. First at all, I implement an approach presented by Glenn Eguchi at The 6.838 Computational Geometry October 11, 2001 since this procedure use three starting point instead of the two proposed in the book and is more easy to handle the searching over the directed acyclic graph that stores the triangles. On the other hand, the explanation given in the book about how to handle the points belonging to the additional triangles is a little tricky and I don't understand at all.

Well, the problem is that according to this approach at the start of the procedure it is necessary to handle such case that has as vertices of the triangle any of the bounding points added to the original set of points given as result four degenerated cases:

Case 1) Indices i and j are both negative.

  • (pi,pj) is an edge of the bounding triangle
  • (pi,pj) is legal, want to preserve edges of bounding triangle

Case 2) Indices i, j, k, and l are all positive.

  • This is the normal case.
  • (pi,pj) is illegal iff pl lies inside the circumcircle of (pi,pj,pk)

Case 3) Exactly one of i, j, k, l is negative

  • We don’t want our bounding triangle to destroy any Delaunay edges.
  • If i or j is negative, pipj is illegal.
  • Otherwise, pipj is legal.

Case 4) Exactly two of i, j, k, l are negative.

  • k and l cannot both be negative (either pk or pl must be pr)
  • i and j cannot both be negative
  • One of i or j and one of k or l must be negative
  • If negative index of i and j is smaller than negative index of k and l, (pi,pj) is legal.
  • Otherwise (pi,pj) is illegal.

Case 4 representation

The three starting points proposed are:

  • p-1 = (3M, 0)
  • p-2 = (0, 3M)
  • p-3 = (-3M, -3M)

M = maximum absolute value of any coordinate of a point in P

More additional help could be found here

References:

(1) De Berg, M., Van Kreveld, M., Overmars, M., & Schwarzkopf, O. C. (2000).Computational geometry (pp. 1-17). Springer Berlin Heidelberg.

I give you a simple test cases that don't behave properly if I put case 4 at the algorithm. The reason is that if I include such case then when I only have two points added from the set of points no is possible to find an edge that hold any of the legal parts of the above cases after it find an illegal edge due to case 4. For now, I remove this case of my implementation and the algorithm works, but I suppose that the algorithm is not finished if I not include this case because is important for some set of points. I still working in find it:

3 
0 0
4 0
0 4

First line, the number of points given. Then, the x and y coordinates of each point per line. The order of the inserted points (this is important, since in this approach the points are inserted randomly) is the following (0,4) -> (0,0) -> (4,0).

This is the function legalizeEdge that I have implemented, the lines commented belong to case 4:

/* Take into account that the symbolical points at the bounding triangle
* could be part of the edges to legalize */
void legalizeEdge(point pr, seg s) {
    bool ill = 0;
    int fn = 0, sn = 0;
    pair<int, int> adj = Q[s];
    point pl =
            contain(nodes[adj.first].t, pr) ?
                    getPoint(nodes[adj.second].t, s) :
                    getPoint(nodes[adj.first].t, s);

    if (s.first == p_1 || s.first == p_2 || s.first == p_3) {
        fn = s.first == p_3 ? -3 : s.first == p_1 ? -1 : -2;
        if (s.second == p_1 || s.second == p_2 || s.second == p_3) {
            return; // Case 1: is always legal
        }
    }

    if (s.second == p_1 || s.second == p_2 || s.second == p_3) {
        fn = s.first == p_3 ? -3 : s.first == p_1 ? -1 : -2;
    }

    if (pl == p_1 || pl == p_2 || pl == p_3) {
        // Case 4: both either(i,j) and l must be negative
        /*sn = pl == p_1 ? -3 : pl == p_1 ? -1 : -2;
        if(!fn) {
            return; // Case 3: is legal only when i or j are not negative
        }
        else if (fn < sn)
            return; // if min(i,j) < l
        else
            ill = 1;*/
        return;
    } else if(fn) {
        ill = 1; // Case 3 read above
    }

    if (ill || inCircle(pr, s.first, s.second, pl)) { // is illegal
        // Case 2 or illegal Case 3
        seg news;
        int firstt, secondd;
        pair<int, int> nadj;
        point pj = s.first, pi = s.second;

        // replace s(pj,pi) with s(pr,pl) flip edge!!!

        firstt = contain(nodes[adj.first].t,pl) ? adj.first:adj.second;
        secondd = firstt == adj.first ? adj.second:adj.first;

        Q.erase(s);
        news = getSeg(pr,pl);
        insTrang(pr, pj, pl), nadj.first = IDX,
        nodes[adj.first].son.push_back(IDX), nodes[adj.second].son.push_back(
        IDX);

        updateMap(pl,pj,firstt);
        updateMap(pr,pj,secondd);

        insTrang(pr, pl, pi), nadj.second = IDX,
        nodes[adj.first].son.push_back(IDX), nodes[adj.second].son.push_back(
        IDX);

        updateMap(pi,pr,secondd);
        updateMap(pi,pl,firstt);

        Q[news] = nadj;

        seg sa = getSeg(pi,pl);
        legalizeEdge(pr, sa);

        seg sb = getSeg(pj,pl);
        legalizeEdge(pr, sb);
    }
}

Thanks in advance.

monk
  • 134
  • 1
  • 7
  • 1
    Asking to find an error in 500+ lines of code that deal with stuff that most people never heard about is a bit too much and you are a very lucky person if you find someone who doesn't mind doing that. I believe you were better off trying to track your variable's values with a debugger to find where weird stuff starts happening. I like how your question is structured though, in a very organized way. You could apply that skill to reduce the size of your main function ;) – SlySherZ Nov 28 '14 at 16:29
  • Well, you have absolute right but I try to put all the code that I have. Now I see that this is not the most proper way to get an answer. I think that the code is not pretty well structured and I try to be more specific in my question right now. Thanks for the advice. – monk Nov 28 '14 at 17:16
  • I reduced the amount of code present in my question. I need to know if anyone has trying to implement a similar approach to build a Delaunay triangulation that can help me with this issue. – monk Nov 30 '14 at 20:35
  • 1
    @monk:Did you tried a simple bowyer-watson and your example? – Micromega Nov 30 '14 at 20:35
  • @Phpdna: Actually this is a more advanced approach of such algorithm but there is no doubt that the bowyer-watson algorithm was the base of this incremental approach. I already try it with the pseudo-code given at the [Wikipedia](http://en.wikipedia.org/wiki/Bowyer%E2%80%93Watson_algorithm) but I think that the approach treated in the book is more correctly structured and is more optimal than the simple bowyer-watson proposal. – monk Dec 01 '14 at 20:46
  • @monk:You can try my implementation @ phpclasses.org? – Micromega Dec 01 '14 at 20:51
  • @Phpdna: Is [this](http://www.phpclasses.org/package/8172-PHP-Perform-Delaunay-triangulation-for-a-set-of-points.html#information) your implementation? – monk Dec 01 '14 at 21:27
  • @monk:Yes,but you need to register. You can also try codeplex. – Micromega Dec 01 '14 at 21:49
  • @monk:Did you tried it? Does it work? – Micromega Dec 04 '14 at 12:49

0 Answers0