Ejemplo n.º 1
0
  /**
   * Check if the point is an apex of the triangle
   *
   * @param aPoint
   * @return belongs
   */
  public final boolean belongsTo(DPoint aPoint) {
    boolean belongs = false;
    DEdge anEdge = this.getEdge(0);
    if (anEdge.getStartPoint().equals(aPoint)) {
      belongs = true;
    } else if (anEdge.getEndPoint().equals(aPoint)) {
      belongs = true;
    } else {
      anEdge = this.getEdge(1);
      if (anEdge.getStartPoint().equals(aPoint)) {
        belongs = true;
      } else if (anEdge.getEndPoint().equals(aPoint)) {
        belongs = true;
      }
    }

    return belongs;
  }
Ejemplo n.º 2
0
  /**
   * Create a new triangle with the three given edges as a basis.
   *
   * <p>An integrity check is processed while building the triangle. This constructor is the best
   * way to ensure that already existing edges will be linked to the good triangles, and that ther
   * won't be any edge duplication in the data structures.
   *
   * @param e1
   * @param e2
   * @param e3
   * @throws DelaunayError If there is at least two edges that don't share exactly a point.
   */
  public DTriangle(DEdge e1, DEdge e2, DEdge e3) throws DelaunayError {
    super();
    init();

    // We check the integrity of the edges given to build this triangle
    boolean integrityE1E2 =
        (e1.isExtremity(e2.getStartPoint()) && !e3.isExtremity((e2.getStartPoint())))
            || (e1.isExtremity(e2.getEndPoint()) && !e3.isExtremity(e2.getEndPoint()));
    boolean integrityE1EptNb =
        (e1.isExtremity(e3.getStartPoint()) && !e2.isExtremity((e3.getStartPoint())))
            || (e1.isExtremity(e3.getEndPoint()) && !e2.isExtremity(e3.getEndPoint()));
    boolean integrityEptNbE2 =
        (e2.isExtremity(e3.getStartPoint()) && !e1.isExtremity((e3.getStartPoint())))
            || (e2.isExtremity(e3.getEndPoint()) && !e1.isExtremity(e3.getEndPoint()));

    if (integrityE1E2 && integrityE1EptNb && integrityEptNbE2) {
      edges[0] = e1;
      edges[1] = e2;
      edges[2] = e3;

      connectEdges();
      computeCenter();
      radius = e1.getStartPoint().squareDistance2D(xCenter, yCenter);
    } else {
      throw new DelaunayError(
          "Problem while generating the Triangle : "
              + integrityE1E2
              + " "
              + integrityE1EptNb
              + " "
              + integrityEptNbE2);
    }
  }
Ejemplo n.º 3
0
  /**
   * Get the edge of the triangle that includes the two point
   *
   * @param p1
   * @param p2
   * @return alterEdge
   */
  protected final DEdge getEdgeFromPoints(DPoint p1, DPoint p2) {
    DEdge alterEdge = null;
    DPoint test1, test2;
    int i = 0;
    while (i < PT_NB && alterEdge == null) {
      DEdge testEdge = edges[i];
      test1 = testEdge.getStartPoint();
      test2 = testEdge.getEndPoint();
      if ((test1.equals(p1)) && (test2.equals(p2))) {
        alterEdge = testEdge;
      } else if ((test1.equals(p2)) && (test2.equals(p1))) {
        alterEdge = testEdge;
      } else {
        i++;
      }
    }

    return alterEdge;
  }
Ejemplo n.º 4
0
  /**
   * Returns true if the triangle is turned toward the edge ed.
   *
   * @param ed
   * @return true if this is pouring into ed.
   * @throws org.jdelaunay.delaunay.error.DelaunayError
   */
  public final boolean isTopoOrientedToEdge(DEdge ed) throws DelaunayError {
    // on determine les sommets A,B et C du triangle et on calle AB (ou BA)
    // sur e
    DPoint a = ed.getStartPoint();
    DPoint b = ed.getEndPoint();
    if (!this.belongsTo(a) || !belongsTo(b)) {
      throw new DelaunayError(DelaunayError.DELAUNAY_ERROR_OUTSIDE_TRIANGLE);
    }

    DPoint c = getOppositePoint(ed);
    DPoint ab = Tools.vectorialDiff(b, a);
    DPoint ac = Tools.vectorialDiff(c, a);
    // orientation CCW
    if (Tools.vectorProduct(ab, ac).getZ() < 0) {
      // echange A et B
      DPoint d = a;
      a = b;
      b = d;
      ab = Tools.vectorialDiff(b, a);
    }
    // test d'intersection entre AB et P
    DPoint p = getSteepestVector();
    return Tools.vectorProduct(ab, p).getZ() < 0;
  }
Ejemplo n.º 5
0
 /**
  * Get the point of the triangle that does not belong to the edge
  *
  * @param ed
  * @return alterPoint
  */
 public final DPoint getOppositePoint(DEdge ed) {
   DPoint start = ed.getStartPoint();
   DPoint end = ed.getEndPoint();
   return getAlterPoint(start, end);
 }