Exemple #1
0
  /**
   * Getting delaunay triangles out of array of 2D points
   *
   * @return array of triangles, which consist of array of 3 points of IVec2
   */
  public static IVec2[][] getTriangles(IVec2[] pts) {

    if (pts.length == 3) {
      if (isClockwise(pts[0], pts[1], pts[2]))
        return new IVec2[][] {new IVec2[] {pts[0], pts[2], pts[1]}};
      return new IVec2[][] {new IVec2[] {pts[0], pts[1], pts[2]}};
    }

    ArrayList<IVec2[]> triangles = new ArrayList<IVec2[]>();

    // IOut.p("pts.length = "+pts.length); //
    // for(int i=0; i<pts.length; i++) IOut.p("pts["+i+"] = "+ pts[i]); //

    // int[] edgeCount = createEdgeCounter(pts.length);

    for (int i = 0; i < pts.length - 2; i++) {
      // IOut.p((i+1)+"/"+(pts.length-2)); //
      IOut.debug(40, (i + 1) + "/" + (pts.length - 2)); //
      for (int j = i + 1; j < pts.length - 1; j++) {

        if (maxDistToCheck < 0 || maxDistToCheck >= 0 && pts[i].dist(pts[j]) <= maxDistToCheck) {

          for (int k = j + 1; k < pts.length; k++) {

            if (maxDistToCheck < 0
                || maxDistToCheck >= 0 && pts[i].dist(pts[k]) <= maxDistToCheck) {

              boolean anyInside = false;
              for (int l = 0; l < pts.length && !anyInside; l++)
                if (l != i && l != j && l != k) {
                  // IOut.p("<"+i+","+j+","+k+","+l+">"); //
                  if (isInsideCircumcircle(pts[l], pts[i], pts[j], pts[k])) {
                    anyInside = true;
                    // IOut.p(pts[l] + " is inside <"+pts[i]+", "+pts[j]+", "+pts[k]+">"); //
                    // IOut.p("pt["+l+"] is INside pt["+i+"], pt["+j+"], pt["+k+"]"); //
                  } else {
                    // IOut.p(pts[l] + " is outside <"+pts[i]+", "+pts[j]+", "+pts[k]+">"); //
                    // IOut.p("pt["+l+"] is OUTside pt["+i+"], pt["+j+"], pt["+k+"]"); //
                  }
                }
              if (!anyInside) { // nothing is inside
                // IOut.p("<"+i+","+j+","+k+">: triangle is added"); //
                if (isClockwise(pts[i], pts[j], pts[k]))
                  triangles.add(new IVec2[] {pts[i], pts[k], pts[j]});
                else triangles.add(new IVec2[] {pts[i], pts[j], pts[k]});
              }
              // else IOut.p("pt out"); //
            }
          }
        }
      }
    }
    // IOut.p("trinangles.size()="+triangles.size()); //
    return triangles.toArray(new IVec2[triangles.size()][]);
  }
Exemple #2
0
 public static IVec2[] getAdjacentPointsOnEdgeLoop(IVec2[][] edgePts, IVec2 pt) {
   for (int i = 0; i < edgePts.length; i++) {
     for (int j = 0; j < edgePts[i].length; j++) {
       if (edgePts[i][j] == pt) {
         return new IVec2[] {
           edgePts[i][(j - 1 + edgePts[i].length) % edgePts[i].length],
           edgePts[i][(j + 1) % edgePts[i].length]
         };
       }
     }
   }
   IOut.err("no point found in edgePts : pt = " + pt);
   return null;
 }