コード例 #1
0
ファイル: Circle2D.java プロジェクト: AidanDelaney/javaGeom-1
  /**
   * 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);
  }
コード例 #2
0
ファイル: EllipseArc2D.java プロジェクト: CKehl/javaGeom
  /* (non-Javadoc)
   * @see math.geom2d.curve.ContinuousCurve2D#asPolyline(int)
   */
  public Polyline2D asPolyline(int n) {

    // compute increment value
    double dt = Math.abs(this.angleExtent) / n;

    // allocate array of points, and compute each value.
    // Computes also value for last point.
    Point2D[] points = new Point2D[n + 1];
    for (int i = 0; i < n + 1; i++) points[i] = this.point(i * dt);

    return new Polyline2D(points);
  }