예제 #1
0
파일: Line.java 프로젝트: tofarr/Geomatics
 /**
  * Project the value given along the line segment, where 0 represents A and 1 represents B.
  * Tolerance is used to snap points to A or B if close enough. If u < 0 return A and if u > 1
  * return B and the point is beyond the tolerance, return null
  *
  * @param u
  * @param tolerance tolerance for snapping to end points
  * @param target target vector
  * @throws IllegalArgumentException if u was infinite or NaN
  * @throws NullPointerException if tolerance or target was null
  */
 public void projectClosest(double u, Tolerance tolerance, VectBuilder target)
     throws NullPointerException, IllegalArgumentException {
   double x = (u * (bx - ax)) + ax;
   double y = (u * (by - ay)) + ay;
   if ((u < 0) || tolerance.match(x, y, ax, ay)) {
     getA(target);
   } else if ((u > 1) || tolerance.match(x, y, bx, by)) {
     getB(target);
   } else {
     target.set(x, y);
   }
 }
예제 #2
0
파일: Line.java 프로젝트: tofarr/Geomatics
 static boolean project(
     double ax,
     double ay,
     double bx,
     double by,
     double u,
     Tolerance tolerance,
     VectBuilder target) {
   double x = (u * (bx - ax)) + ax;
   double y = (u * (by - ay)) + ay;
   if (tolerance.match(x, y, ax, ay)) {
     target.set(ax, ay);
     return true;
   } else if (tolerance.match(x, y, bx, by)) {
     target.set(bx, by);
     return true;
   } else {
     target.set(x, y);
     return ((u > 0) && (u < 1));
   }
 }
예제 #3
0
파일: Line.java 프로젝트: tofarr/Geomatics
  static boolean intersectionSegInternal(
      double ax,
      double ay,
      double bx,
      double by,
      double jax,
      double jay,
      double jbx,
      double jby,
      Tolerance tolerance,
      VectBuilder target)
      throws NullPointerException {
    if (Vect.compare(ax, ay, bx, by) > 0) {
      double tmp = ax;
      ax = bx;
      bx = tmp;
      tmp = ay;
      ay = by;
      by = tmp;
    }
    if (Vect.compare(jax, jay, jbx, jby) > 0) {
      double tmp = jax;
      jax = jbx;
      jbx = tmp;
      tmp = jay;
      jay = jby;
      jby = tmp;
    }
    if (compare(ax, ay, bx, by, jax, jay, jbx, jby) > 0) {
      double tmp = ax;
      ax = jax;
      jax = tmp;

      tmp = ay;
      ay = jay;
      jay = tmp;

      tmp = bx;
      bx = jbx;
      jbx = tmp;

      tmp = by;
      by = jby;
      jby = tmp;
    }

    double denom = getDenom(ax, ay, bx, by, jax, jay, jbx, jby);
    if (denom == 0.0) { // Lines are parallel.
      return false;
    }
    double ui =
        ((jbx - jax) * (ay - jay) - (jby - jay) * (ax - jax))
            / denom; // projected distance along i and j
    double uj = ((bx - ax) * (ay - jay) - (by - ay) * (ax - jax)) / denom;

    double x, y;
    if (ax == bx) {
      x = ax;
    } else if (jax == jbx) {
      x = jax;
    } else {
      x = (ui * (bx - ax)) + ax;
    }
    if (ay == by) {
      y = ay;
    } else if (jay == jby) {
      y = jay;
    } else {
      y = (ui * (by - ay)) + ay;
    }

    boolean ia = tolerance.match(x, y, ax, ay);
    boolean ib = tolerance.match(x, y, bx, by);
    boolean i = ia || ib || ((ui >= 0) && (ui <= 1));

    boolean ja = tolerance.match(x, y, jax, jay);
    boolean jb = tolerance.match(x, y, jbx, jby);
    boolean j = ja || jb || ((uj >= 0) && (uj <= 1));

    if (i && j) {
      if (ia) {
        target.set(ax, ay);
      } else if (ib) {
        target.set(bx, by);
      } else if (ja) {
        target.set(jax, jay);
      } else if (jb) {
        target.set(jbx, jby);
      } else {
        target.set(x, y);
      }
      return true;
    }
    return false;
  }
예제 #4
0
파일: Line.java 프로젝트: tofarr/Geomatics
 /**
  * Get the mid point
  *
  * @param target target in which to place mid point
  * @return target
  */
 public VectBuilder getMid(VectBuilder target) {
   return target.set((ax + bx) / 2, (ay + by) / 2);
 }
예제 #5
0
파일: Line.java 프로젝트: tofarr/Geomatics
 /**
  * Get B
  *
  * @param target target in which to place B
  * @return target
  */
 public VectBuilder getB(VectBuilder target) {
   target.set(bx, by);
   return target;
 }
예제 #6
0
파일: Line.java 프로젝트: tofarr/Geomatics
 /**
  * Get A
  *
  * @param target target in which to place A
  * @return target
  */
 public VectBuilder getA(VectBuilder target) {
   target.set(ax, ay);
   return target;
 }