예제 #1
0
  // Return number of occupied DPoints Modified
  public int getOccupiedDPoints() {
    int occupiedNumber = 0;
    for (DPoint p : dockingPoints) {
      if (p.isOccupied()) occupiedNumber++;
    }

    return occupiedNumber;
  }
예제 #2
0
 void setDistributor(EventDistributor d) {
   touchScreen.addDistributorLinks(d);
   cardReader.addDistributorLinks(d);
   keyReader.addDistributorLinks(d);
   for (DPoint dp : dockingPoints) {
     dp.setDistributor(d);
   }
 }
예제 #3
0
 void setCollector(EventCollector c) {
   touchScreen.setCollector(c);
   cardReader.setCollector(c);
   keyIssuer.setCollector(c);
   for (DPoint dp : dockingPoints) {
     dp.setCollector(c);
   }
 }
예제 #4
0
  /**
   * Display the triangle in a JPanel Must be used only when using package drawing
   *
   * @param g
   * @param decalageX
   * @param decalageY
   * @param minX
   * @param minY
   * @param scaleX
   * @param scaleY
   */
  public final void displayObject(
      Graphics g,
      int decalageX,
      int decalageY,
      double minX,
      double minY,
      double scaleX,
      double scaleY) {
    int[] xPoints, yPoints;
    xPoints = new int[PT_NB];
    yPoints = new int[PT_NB];
    DPoint p1, p2, pptNb;
    p1 = getPoint(0);
    p2 = getPoint(1);
    pptNb = getPoint(2);

    xPoints[0] = (int) ((p1.getX() - minX) * scaleX + decalageX);
    xPoints[1] = (int) ((p2.getX() - minX) * scaleX + decalageX);
    xPoints[2] = (int) ((pptNb.getX() - minX) * scaleX + decalageX);

    yPoints[0] = (int) ((p1.getY() - minY) * scaleY + decalageY);
    yPoints[1] = (int) ((p2.getY() - minY) * scaleY + decalageY);
    yPoints[2] = (int) ((pptNb.getY() - minY) * scaleY + decalageY);

    setColor(g);
    g.fillPolygon(xPoints, yPoints, PT_NB);

    for (int i = 0; i < PT_NB; i++) {
      edges[i].displayObject(g, decalageX, decalageY, minX, minY, scaleX, scaleY);
    }
  }
예제 #5
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;
 }
예제 #6
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;
 }
예제 #7
0
  /**
   * Check if the aPoint is in or on the circumcircle of this triangle.
   *
   * @param aPoint
   * @return position : <br>
   *     * 0 = outside <br>
   *     * 1 = inside <br>
   *     * 2 = on the circle
   */
  public final int inCircle(DPoint aPoint) {
    // default is outside the circle
    int returnedValue = 0;

    double ux = aPoint.getX() - xCenter;
    double uy = aPoint.getY() - yCenter;
    double distance = ux * ux + uy * uy;
    if (distance < radius - Tools.EPSILON2) {
      returnedValue = 1;
    } else if (distance < radius + Tools.EPSILON2) {
      returnedValue = 2;
    }

    return returnedValue;
  }
예제 #8
0
  /**
   * Get the barycenter of the triangle as a DPoint
   *
   * @return isFlat
   * @throws DelaunayError
   */
  public final DPoint getBarycenter() throws DelaunayError {
    double x = 0, y = 0, z = 0;
    DPoint aPoint;
    for (int i = 0; i < PT_NB; i++) {
      aPoint = getPoint(i);

      x += aPoint.getX();
      y += aPoint.getY();
      z += aPoint.getZ();
    }
    x /= (double) PT_NB;
    y /= (double) PT_NB;
    z /= (double) PT_NB;

    return new DPoint(x, y, z);
  }
예제 #9
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;
  }
예제 #10
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;
 }
예제 #11
0
 /**
  * Implements the Comparable interface. The triangles will be sorted according the middle of their
  * bounding box. As we work on a triangulation where triangles' intersection can only be an edge,
  * a point or void, the Bounding boxes are unique.
  *
  * <p>BE CAREFUL : this method is not consistent with equals ! We are making a comparison on the
  * bounding box of two triangles, they could be equal even if the triangle are different !!!
  *
  * @param t
  * @return -1, 0 or 1, using the point comparison on the center of the bounding boxes
  */
 @Override
 public final int compareTo(DTriangle t) {
   try {
     DPoint midT = getBoundingBox().getMiddle();
     DPoint midO = t.getBoundingBox().getMiddle();
     int c = midT.compareTo(midO);
     if (c == 0) {
       try {
         c = getBarycenter().compareTo(t.getBarycenter());
       } catch (DelaunayError ex) {
         Logger.getLogger(DTriangle.class.getName()).log(Level.WARNING, null, ex);
       }
     }
     return c;
   } catch (DelaunayError e) {
     throw new IllegalArgumentException(e.getLocalizedMessage(), e);
   }
 }
예제 #12
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;
 }
예제 #13
0
 /**
  * Compute the azimut of the triangle in degrees between north and steeepest vector. Aspect is
  * measured clockwise in degrees from 0, due north, to 360, again due north, coming full circle.
  *
  * @return the aspect of the slope of this triangle.
  * @throws DelaunayError
  */
 public final double getSlopeAspect() throws DelaunayError {
   double orientationPente;
   DPoint c1 = new DPoint(0.0, 0.0, 0.0);
   DPoint c2 = getSteepestVector();
   if (c2.getZ() > 0.0) {
     c2.setX(-c2.getX());
     c2.setY(-c2.getY());
     c2.setZ(-c2.getZ());
   }
   // l'ordre des coordonnees correspond a l'orientation de l'arc
   // "sommet haut vers sommet bas"
   double angleAxeXrad = Tools.angle(c1, c2);
   // on considere que l'axe nord correspond a l'axe Y positif
   double angleAxeNordrad = Tools.PI_OVER_2 - angleAxeXrad;
   double angleAxeNorddeg = Math.toDegrees(angleAxeNordrad);
   // on renvoie toujours une valeur d'angle >= 0
   orientationPente = angleAxeNorddeg < 0.0 ? 360.0 + angleAxeNorddeg : angleAxeNorddeg;
   return orientationPente;
 }
예제 #14
0
 /**
  * Compute the intersection point according to the vector opposite to the steepest vector. If dp
  * is outside the triangle, we return null.
  *
  * @param dp
  * @return The point pt of the triangle's boundary for which (dp pt) is colinear to the steepest
  *     vector.
  * @throws DelaunayError
  */
 public final DPoint getCounterSteepestIntersection(DPoint dp) throws DelaunayError {
   if (isInside(dp) || isOnAnEdge(dp)) {
     for (DEdge ed : edges) {
       if (!isTopoOrientedToEdge(ed)) {
         DPoint counterSteep = getSteepestVector();
         counterSteep.setX(-counterSteep.getX());
         counterSteep.setY(-counterSteep.getY());
         counterSteep.setZ(-counterSteep.getZ());
         DPoint pt =
             Tools.computeIntersection(
                 ed.getStartPoint(), ed.getDirectionVector(), dp, counterSteep);
         if (ed.contains(pt)) {
           return pt;
         }
       }
     }
   }
   return null;
 }
예제 #15
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;
  }
예제 #16
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;
  }
예제 #17
0
 public void setHub(HubInterface h) {
   this.hub = h;
   for (DPoint dp : dockingPoints) {
     dp.setInterface(this, hub);
   }
 }
예제 #18
0
 /**
  * Get the leftmost point of this triangle.
  *
  * @return the leftmost point of this triangle.
  */
 public final DPoint getLeftMost() {
   DPoint p1 = edges[0].getPointLeft();
   DPoint p2 = edges[1].getPointLeft();
   return p1.compareTo(p2) < 1 ? p1 : p2;
 }
예제 #19
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;
    }
  }
예제 #20
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;
 }
예제 #21
0
  /**
   * Retrieve the angle, in degrees, at vertex number k.
   *
   * @param k
   * @return The angle at the ith point.
   */
  public final double getAngle(int k) {
    int k1 = (k + 1) % PT_NB;
    int k2 = (k1 + 1) % PT_NB;
    final double degreesPI = 180d;

    DPoint p1 = this.getPoint(k);
    DPoint p2 = this.getPoint(k1);
    DPoint pptNb = this.getPoint(k2);

    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 dp = ux * vx + uy * vy;

    return Math.acos(Math.sqrt(((dp * dp)) / ((ux * ux + uy * uy) * (vx * vx + vy * vy))))
        * (degreesPI / Math.PI);
  }
예제 #22
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;
  }
예제 #23
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;
  }