Beispiel #1
0
  // calc angle between vectors A-B and C-B
  // angle in range [0, pi]
  @Override
  public void compute() {

    GeoPoint2 A = (GeoPoint2) An;
    GeoPoint2 B = (GeoPoint2) Bn;
    GeoPoint2 C = (GeoPoint2) Cn;

    if (!A.isFinite() || !B.isFinite() || !C.isFinite()) {
      angle.setUndefined(); // undefined
      return;
    }

    // get vectors v=BA and w=BC
    bx = B.inhomX;
    by = B.inhomY;
    vx = A.inhomX - bx;
    vy = A.inhomY - by;
    wx = C.inhomX - bx;
    wy = C.inhomY - by;

    if (Kernel.isZero(vx) && Kernel.isZero(vy) || Kernel.isZero(wx) && Kernel.isZero(wy)) {
      angle.setUndefined();
      return;
    }

    // |v| * |w| * sin(alpha) = det(v, w)
    // cos(alpha) = v . w / (|v| * |w|)
    // tan(alpha) = sin(alpha) / cos(alpha)
    // => tan(alpha) = det(v, w) / v . w
    double det = vx * wy - vy * wx;
    double prod = vx * wx + vy * wy;
    double value = Math.atan2(det, prod);

    angle.setValue(value);
  }
Beispiel #2
0
  public final void compute() {
    // Check if the points are aligned

    double x1 = -A.inhomX;
    double y1 = -A.inhomY;
    double x2 = -B.inhomX;
    double y2 = -B.inhomY;
    double x3 = -C.inhomX;
    double y3 = -C.inhomY;

    double det = (-x2 + x3) * (y1 - y3) + (x1 - x3) * (y2 - y3);
    if (Kernel.isZero(det)) {
      poly.setUndefined();
    } else {
      ycoef[0].setValue((x3 - x2) / det);
      xcoef[0].setValue((y2 - y3) / det);
      constant[0].setValue(((x3 - x2) * y3 + (y2 - y3) * x3) / det);
      ycoef[1].setValue((x1 - x3) / det);
      xcoef[1].setValue((y3 - y1) / det);
      constant[1].setValue(((x1 - x3) * y1 + (y3 - y1) * x1) / det);
      ycoef[2].setValue((x2 - x1) / det);
      xcoef[2].setValue((y1 - y2) / det);
      constant[2].setValue(((x2 - x1) * y2 + (y1 - y2) * x2) / det);
      dd.update();
      poly.update();
    }
  }