Ejemplo n.º 1
0
 /** Returns a new CircleArc2D. t0 and t1 are position on circle. */
 public CircleArc2D subCurve(double t0, double t1) {
   double startAngle, extent;
   if (this.direct) {
     startAngle = t0;
     extent = Angle2D.formatAngle(t1 - t0);
   } else {
     extent = -Angle2D.formatAngle(t1 - t0);
     startAngle = Angle2D.formatAngle(-t0);
   }
   return new CircleArc2D(this, startAngle, extent);
 }
Ejemplo n.º 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);
  }
Ejemplo n.º 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);
  }
Ejemplo n.º 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;
  }
Ejemplo n.º 5
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;
  }
Ejemplo n.º 6
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);
 }