Beispiel #1
0
  /*
   * (non-Javadoc)
   *
   * @see math.geom2d.OrientedCurve2D#windingAngle(math.geom2d.Point2D)
   */
  public double windingAngle(Point2D point) {
    Point2D p1 = point(0);
    Point2D p2 = point(abs(angleExtent));

    // compute angle of point with extreme points
    double angle1 = Angle2D.horizontalAngle(point, p1);
    double angle2 = Angle2D.horizontalAngle(point, p2);

    // test on which 'side' of the arc the point lie
    boolean b1 = (new StraightLine2D(p1, p2)).isInside(point);
    boolean b2 = ellipse.isInside(point);

    if (angleExtent > 0) {
      if (b1 || b2) { // inside of ellipse arc
        if (angle2 > angle1) return angle2 - angle1;
        else return 2 * PI - angle1 + angle2;
      } else { // outside of ellipse arc
        if (angle2 > angle1) return angle2 - angle1 - 2 * PI;
        else return angle2 - angle1;
      }
    } else {
      if (!b1 || b2) {
        if (angle1 > angle2) return angle2 - angle1;
        else return angle2 - angle1 - 2 * PI;
      } else {
        if (angle1 > angle2) return angle2 - angle1 + 2 * PI;
        else return angle2 - angle1;
      }
    }
  }
Beispiel #2
0
  /**
   * Computes the projection position of the point on the circle, by computing angle with
   * horizonrtal
   */
  public double project(Point2D point) {
    double xp = point.x() - this.xc;
    double yp = point.y() - this.yc;

    // compute angle
    return Angle2D.horizontalAngle(xp, yp);
  }
Beispiel #3
0
  /**
   * Computes the radical axis of the two circles.
   *
   * @since 0.11.1
   * @return the radical axis of the two circles.
   * @throws IllegalArgumentException if the two circles have same center
   */
  public static StraightLine2D radicalAxis(Circle2D circle1, Circle2D circle2) {

    // extract center and radius of each circle
    double r1 = circle1.radius();
    double r2 = circle2.radius();
    Point2D p1 = circle1.center();
    Point2D p2 = circle2.center();

    // compute horizontal angle of joining line
    double angle = Angle2D.horizontalAngle(p1, p2);

    // distance between centers
    double dist = p1.distance(p2);
    if (dist < Shape2D.ACCURACY) {
      throw new IllegalArgumentException("Input circles must have distinct centers");
    }

    // position of the radical axis on the joining line
    double d = (dist * dist + r1 * r1 - r2 * r2) * .5 / dist;

    // pre-compute trigonometric functions
    double cot = Math.cos(angle);
    double sit = Math.sin(angle);

    // compute parameters of the line
    double x0 = p1.x() + d * cot;
    double y0 = p1.y() + d * sit;
    double dx = -sit;
    double dy = cot;

    // update state of current line
    return new StraightLine2D(x0, y0, dx, dy);
  }
Beispiel #4
0
  /** @deprecated replaced by circlesIntersections(Circle2D, Circle2D) (0.11.1) */
  @Deprecated
  public static Collection<Point2D> getIntersections(Circle2D circle1, Circle2D circle2) {
    ArrayList<Point2D> intersections = new ArrayList<Point2D>(2);

    // extract center and radius of each circle
    Point2D center1 = circle1.center();
    Point2D center2 = circle2.center();
    double r1 = circle1.radius();
    double r2 = circle2.radius();

    double d = Point2D.distance(center1, center2);

    // case of no intersection
    if (d < abs(r1 - r2) || d > (r1 + r2)) return intersections;

    // Angle of line from center1 to center2
    double angle = Angle2D.horizontalAngle(center1, center2);

    // position of intermediate point
    double d1 = d / 2 + (r1 * r1 - r2 * r2) / (2 * d);
    Point2D tmp = Point2D.createPolar(center1, d1, angle);

    // Add the 2 intersection points
    double h = sqrt(r1 * r1 - d1 * d1);
    intersections.add(Point2D.createPolar(tmp, h, angle + PI / 2));
    intersections.add(Point2D.createPolar(tmp, h, angle - PI / 2));

    return intersections;
  }
Beispiel #5
0
  /*
   * (non-Javadoc)
   *
   * @see math.geom2d.Curve2D#position(math.geom2d.Point2D)
   */
  public double position(Point2D point) {
    double angle = Angle2D.horizontalAngle(ellipse.center(), point);
    if (this.containsAngle(angle))
      if (angleExtent > 0) return Angle2D.formatAngle(angle - startAngle);
      else return Angle2D.formatAngle(startAngle - angle);

    // If the point is not contained in the arc, return NaN.
    return Double.NaN;
  }
Beispiel #6
0
  /**
   * Computes the intersections points between two circles or circular shapes.
   *
   * @param circle1 an instance of circle or circle arc
   * @param circle2 an instance of circle or circle arc
   * @return a collection of 0, 1 or 2 intersection points
   */
  public static Collection<Point2D> circlesIntersections(Circle2D circle1, Circle2D circle2) {
    // extract center and radius of each circle
    Point2D center1 = circle1.center();
    Point2D center2 = circle2.center();
    double r1 = circle1.radius();
    double r2 = circle2.radius();

    double d = Point2D.distance(center1, center2);

    // case of no intersection
    if (d < abs(r1 - r2) || d > (r1 + r2)) return new ArrayList<Point2D>(0);

    // Angle of line from center1 to center2
    double angle = Angle2D.horizontalAngle(center1, center2);

    if (d == abs(r1 - r2) || d == (r1 + r2)) {
      Collection<Point2D> r = new ArrayList<>(1);
      r.add(Point2D.createPolar(center1, r1, angle));
      return r;
    }

    // position of intermediate point
    double d1 = d / 2 + (r1 * r1 - r2 * r2) / (2 * d);
    Point2D tmp = Point2D.createPolar(center1, d1, angle);

    // distance between intermediate point and each intersection
    double h = sqrt(r1 * r1 - d1 * d1);

    // create empty array
    ArrayList<Point2D> intersections = new ArrayList<Point2D>(2);

    // Add the 2 intersection points
    Point2D p1 = Point2D.createPolar(tmp, h, angle + PI / 2);
    intersections.add(p1);
    Point2D p2 = Point2D.createPolar(tmp, h, angle - PI / 2);
    intersections.add(p2);

    return intersections;
  }
Beispiel #7
0
 public double position(Point2D point) {
   double angle = Angle2D.horizontalAngle(xc, yc, point.x(), point.y());
   if (direct) return Angle2D.formatAngle(angle - theta);
   else return Angle2D.formatAngle(theta - angle);
 }