Esempio n. 1
0
 /**
  * Get the vector with the highest down slope in the plan associated to this triangle.
  *
  * @return return the steepest vector.
  * @throws DelaunayError
  */
 public final DPoint getSteepestVector() throws DelaunayError {
   DPoint normal = getNormalVector();
   if (Math.abs(normal.getX()) < Tools.EPSILON && Math.abs(normal.getY()) < Tools.EPSILON) {
     return new DPoint(0, 0, 0);
   }
   DPoint pente;
   if (Math.abs(normal.getX()) < Tools.EPSILON) {
     pente = new DPoint(0, 1, -normal.getY() / normal.getZ());
   } else if (Math.abs(normal.getY()) < Tools.EPSILON) {
     pente = new DPoint(1, 0, -normal.getX() / normal.getZ());
   } else {
     pente =
         new DPoint(
             normal.getX() / normal.getY(),
             1,
             -1 / normal.getZ() * (normal.getX() * normal.getX() / normal.getY() + normal.getY()));
   }
   // We want the vector to be low-oriented.
   if (pente.getZ() > Tools.EPSILON) {
     pente.setX(-pente.getX());
     pente.setY(-pente.getY());
     pente.setZ(-pente.getZ());
   }
   // We normalize it
   double length = Math.sqrt(pente.squareDistance(new DPoint(0, 0, 0)));
   if (length > Tools.EPSILON) {
     pente.setX(pente.getX() / length);
     pente.setY(pente.getY() / length);
     pente.setZ(pente.getZ() / length);
   }
   return pente;
 }
Esempio n. 2
0
 /**
  * Return the square of the minimal distance between pt and the apex of this triangle.
  *
  * @param pt
  * @return the square of the minimal distance between pt and the apex of this triangle.
  */
 public final double getMinSquareDistance(DPoint pt) {
   double min = Double.POSITIVE_INFINITY;
   for (int i = 0; i < PT_NB; i++) {
     double dist = pt.squareDistance(getPoint(i));
     min = dist < min ? dist : min;
   }
   return min;
 }
Esempio n. 3
0
 /**
  * Get the normal vector to this triangle, of length 1.
  *
  * @return Get the vector normal to the triangle.
  * @throws DelaunayError
  */
 public final DPoint getNormalVector() throws DelaunayError {
   // We first perform a vectorial product between two of the edges
   double dx1 = edges[0].getStartPoint().getX() - edges[0].getEndPoint().getX();
   double dy1 = edges[0].getStartPoint().getY() - edges[0].getEndPoint().getY();
   double dz1 = edges[0].getStartPoint().getZ() - edges[0].getEndPoint().getZ();
   double dx2 = edges[1].getStartPoint().getX() - edges[1].getEndPoint().getX();
   double dy2 = edges[1].getStartPoint().getY() - edges[1].getEndPoint().getY();
   double dz2 = edges[1].getStartPoint().getZ() - edges[1].getEndPoint().getZ();
   DPoint vec = new DPoint(dy1 * dz2 - dz1 * dy2, dz1 * dx2 - dx1 * dz2, dx1 * dy2 - dy1 * dx2);
   double length = Math.sqrt(vec.squareDistance(new DPoint(0, 0, 0)));
   vec.setX(vec.getX() / length);
   vec.setY(vec.getY() / length);
   vec.setZ(vec.getZ() / length);
   return vec;
 }