예제 #1
0
  /**
   * Computes the 3D area of a triangle based on the same approach of JTS
   *
   * @return
   */
  public final double getArea3D() {
    DPoint p1, p2, pptNb;
    p1 = edges[0].getStartPoint();
    p2 = edges[0].getEndPoint();
    pptNb = edges[1].getStartPoint();
    if ((pptNb.equals(p1)) || (pptNb.equals(p2))) {
      pptNb = edges[1].getEndPoint();
    }
    /**
     * Uses the formula 1/2 * | u x v | where u,v are the side vectors of the triangle x is the
     * vector cross-product
     */
    // side vectors u and v
    double ux = p2.getX() - p1.getX();
    double uy = p2.getY() - p1.getY();
    double uz = p2.getZ() - p1.getZ();

    double vx = pptNb.getX() - p1.getX();
    double vy = pptNb.getY() - p1.getY();
    double vz = pptNb.getZ() - p1.getZ();

    // cross-product = u x v
    double crossx = uy * vz - uz * vy;
    double crossy = uz * vx - ux * vz;
    double crossz = ux * vy - uy * vx;

    // tri area = 1/2 * | u x v |
    double absSq = crossx * crossx + crossy * crossy + crossz * crossz;
    return Math.sqrt(absSq) / 2;
  }
예제 #2
0
  /**
   * Get Z value of a specific point in the triangle
   *
   * @param aPoint
   * @return ZValue
   */
  public final double interpolateZ(DPoint aPoint) {
    double zValue = 0;

    DPoint p1, p2, p3;
    p1 = edges[0].getStartPoint();
    p2 = edges[0].getEndPoint();
    p3 = edges[1].getStartPoint();
    if ((p3.equals(p1)) || (p3.equals(p2))) {
      p3 = edges[1].getEndPoint();
    }

    double ux = p2.getX() - p1.getX();
    double uy = p2.getY() - p1.getY();
    double uz = p2.getZ() - p1.getZ();
    double vx = p3.getX() - p1.getX();
    double vy = p3.getY() - p1.getY();
    double vz = p3.getZ() - p1.getZ();

    double a = uy * vz - uz * vy;
    double b = uz * vx - ux * vz;
    double c = ux * vy - uy * vx;
    double d = -a * p1.getX() - b * p1.getY() - c * p1.getZ();

    if (Math.abs(c) > Tools.EPSILON) {
      // Non vertical triangle
      zValue = (-a * aPoint.getX() - b * aPoint.getY() - d) / c;
    }

    return zValue;
  }
예제 #3
0
 /**
  * Get the point of the triangle that is not one of the 2 points given in argument. If one of
  * these argument is not part of this triangle, this method will return null.
  *
  * @param p1
  * @param p2
  * @return alterPoint
  */
 public final DPoint getAlterPoint(DPoint p1, DPoint p2) {
   DPoint t1 = getPoint(0);
   DPoint t2 = getPoint(1);
   DPoint t3 = getPoint(2);
   if (p1.equals(t1)) {
     if (p2.equals(t2)) {
       return t3;
     } else if (p2.equals(t3)) {
       return t2;
     }
   } else if (p1.equals(t2)) {
     if (p2.equals(t1)) {
       return t3;
     } else if (p2.equals(t3)) {
       return t1;
     }
   } else if (p1.equals(t3)) {
     if (p2.equals(t1)) {
       return t2;
     } else if (p2.equals(t2)) {
       return t1;
     }
   }
   return null;
 }
예제 #4
0
 /**
  * Get the ith point. i must be equal to 0, 1 or 2.
  *
  * <p>This method is consistent with getPoints, ie getPoints().get(i)==getPoint(i).
  *
  * @param i
  * @return aPoint On of the apex if i = 0, 1 or 2, null otherwise.
  */
 public final DPoint getPoint(int i) {
   DPoint p = null;
   if (i == 0) {
     p = edges[0].getStartPoint();
   } else if (i == 1) {
     p = edges[0].getEndPoint();
   } else if (i == 2) {
     p = edges[1].getStartPoint();
     if ((p.equals(edges[0].getStartPoint())) || (p.equals(edges[0].getEndPoint()))) {
       p = edges[1].getEndPoint();
     }
   }
   return p;
 }
예제 #5
0
  /**
   * Compute triangle area
   *
   * @return area
   */
  public final double getArea() {
    DPoint p1, p2, pptNb;
    p1 = edges[0].getStartPoint();
    p2 = edges[0].getEndPoint();
    pptNb = edges[1].getStartPoint();
    if ((pptNb.equals(p1)) || (pptNb.equals(p2))) {
      pptNb = edges[1].getEndPoint();
    }

    double area =
        ((pptNb.getX() - p1.getX()) * (p2.getY() - p1.getY())
                - (p2.getX() - p1.getX()) * (pptNb.getY() - p1.getY()))
            / 2;

    return area < 0 ? -area : area;
  }
예제 #6
0
  @Override
  public final BoundaryBox getBoundingBox() throws DelaunayError {
    BoundaryBox aBox = new BoundaryBox();

    DPoint p1, p2, pptNb;
    p1 = edges[0].getStartPoint();
    p2 = edges[0].getEndPoint();
    pptNb = edges[1].getStartPoint();
    if ((pptNb.equals(p1)) || (pptNb.equals(p2))) {
      pptNb = edges[1].getEndPoint();
    }
    aBox.alterBox(p1);
    aBox.alterBox(p2);
    aBox.alterBox(pptNb);

    return aBox;
  }
예제 #7
0
  /**
   * Recompute the center of the circle that joins the ptNb points : the CircumCenter
   *
   * @throws DelaunayError
   */
  public final void computeCenter() throws DelaunayError {
    DPoint p1, p2, pptNb;
    p1 = edges[0].getStartPoint();
    p2 = edges[0].getEndPoint();
    pptNb = edges[1].getStartPoint();
    if ((pptNb.equals(p1)) || (pptNb.equals(p2))) {
      pptNb = edges[1].getEndPoint();
    }

    double p1Sq = p1.getX() * p1.getX() + p1.getY() * p1.getY();
    double p2Sq = p2.getX() * p2.getX() + p2.getY() * p2.getY();
    double pptNbSq = pptNb.getX() * pptNb.getX() + pptNb.getY() * pptNb.getY();

    double ux = p2.getX() - p1.getX();
    double uy = p2.getY() - p1.getY();
    double vx = pptNb.getX() - p1.getX();
    double vy = pptNb.getY() - p1.getY();

    double cp = ux * vy - uy * vx;
    double cx, cy;

    if (cp != 0) {
      cx =
          (p1Sq * (p2.getY() - pptNb.getY())
                  + p2Sq * (pptNb.getY() - p1.getY())
                  + pptNbSq * (p1.getY() - p2.getY()))
              / (2.0 * cp);
      cy =
          (p1Sq * (pptNb.getX() - p2.getX())
                  + p2Sq * (p1.getX() - pptNb.getX())
                  + pptNbSq * (p2.getX() - p1.getX()))
              / (2.0 * cp);

      xCenter = cx;
      yCenter = cy;
      zCenter = interpolateZ(new DPoint(cx, cy, 0));

      radius = p1.squareDistance2D(xCenter, yCenter);
    } else {
      xCenter = 0.0;
      yCenter = 0.0;
      radius = -1;
    }
  }
예제 #8
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;
  }