Exemplo n.º 1
0
  public java.awt.geom.GeneralPath appendPath(java.awt.geom.GeneralPath path) {
    // number of curves to approximate the arc
    int nSeg = (int) ceil(abs(angleExtent) / (PI / 2));
    nSeg = min(nSeg, 4);

    // angular extent of each curve
    double ext = angleExtent / nSeg;

    // compute coefficient
    double k = btan(abs(ext));

    for (int i = 0; i < nSeg; i++) {
      // position of the two extremities
      double ti0 = abs(i * ext);
      double ti1 = abs((i + 1) * ext);

      // extremity points
      Point2D p1 = this.point(ti0);
      Point2D p2 = this.point(ti1);

      // tangent vectors, multiplied by appropriate coefficient
      Vector2D v1 = this.tangent(ti0).times(k);
      Vector2D v2 = this.tangent(ti1).times(k);

      // append a cubic curve to the path
      path.curveTo(
          p1.x() + v1.x(), p1.y() + v1.y(), p2.x() - v2.x(), p2.y() - v2.y(), p2.x(), p2.y());
    }
    return path;
  }
Exemplo 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);
  }
Exemplo 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);
  }
Exemplo n.º 4
0
  public Box2D boundingBox() {

    // first get ending points
    Point2D p0 = firstPoint();
    Point2D p1 = lastPoint();

    // get coordinate of ending points
    double x0 = p0.x();
    double y0 = p0.y();
    double x1 = p1.x();
    double y1 = p1.y();

    // initialize min and max coords
    double xmin = min(x0, x1);
    double xmax = max(x0, x1);
    double ymin = min(y0, y1);
    double ymax = max(y0, y1);

    // precomputes some values
    Point2D center = ellipse.center();
    double xc = center.x();
    double yc = center.y();
    double endAngle = startAngle + angleExtent;
    boolean direct = angleExtent >= 0;

    // check cases arc contains one maximum
    if (Angle2D.containsAngle(startAngle, endAngle, PI / 2 + ellipse.theta, direct))
      ymax = max(ymax, yc + ellipse.r1);
    if (Angle2D.containsAngle(startAngle, endAngle, 3 * PI / 2 + ellipse.theta, direct))
      ymin = min(ymin, yc - ellipse.r1);
    if (Angle2D.containsAngle(startAngle, endAngle, ellipse.theta, direct))
      xmax = max(xmax, xc + ellipse.r2);
    if (Angle2D.containsAngle(startAngle, endAngle, PI + ellipse.theta, direct))
      xmin = min(xmin, xc - ellipse.r2);

    // return a bounding with computed limits
    return new Box2D(xmin, xmax, ymin, ymax);
  }
Exemplo n.º 5
0
 @Override
 public String toString() {
   Point2D center = ellipse.center();
   return String.format(
       Locale.US,
       "EllipseArc2D(%7.2f,%7.2f,%7.2f,%7.2f,%7.5f,%7.5f,%7.5f)",
       center.x(),
       center.y(),
       ellipse.r1,
       ellipse.r2,
       ellipse.theta,
       startAngle,
       angleExtent);
 }
Exemplo n.º 6
0
  public java.awt.geom.GeneralPath getGeneralPath() {
    // create new path
    java.awt.geom.GeneralPath path = new java.awt.geom.GeneralPath();

    // move to the first point
    Point2D point = this.firstPoint();
    path.moveTo((float) point.x(), (float) point.y());

    // append the curve
    path = this.appendPath(path);

    // return the final path
    return path;
  }
Exemplo n.º 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);
 }
Exemplo n.º 8
0
 public double signedDistance(Point2D point) {
   return signedDistance(point.x(), point.y());
 }
Exemplo n.º 9
0
 /**
  * Test whether the point is inside the circle. The test is performed by translating the point,
  * and re-scaling it such that its coordinates are expressed in unit circle basis.
  */
 public boolean isInside(Point2D point) {
   double xp = (point.x() - this.xc) / this.r;
   double yp = (point.y() - this.yc) / this.r;
   return (xp * xp + yp * yp < 1) ^ !direct;
 }
Exemplo n.º 10
0
 /** Create a new circle with specified center, radius and orientation */
 public Circle2D(Point2D center, double radius, boolean direct) {
   this(center.x(), center.y(), radius, direct);
 }
Exemplo n.º 11
0
 /** Create a new circle with specified point center and radius */
 public Circle2D(Point2D center, double radius) {
   this(center.x(), center.y(), radius, true);
 }
Exemplo n.º 12
0
 public double signedDistance(Point2D p) {
   return signedDistance(p.x(), p.y());
 }
Exemplo n.º 13
0
 /*
  * (non-Javadoc)
  *
  * @see java.awt.Shape#contains(Point2D)
  */
 public boolean contains(Point2D point) {
   return contains(point.x(), point.y());
 }
Exemplo n.º 14
0
 /*
  * (non-Javadoc)
  *
  * @see math.geom2d.Shape2D#distance(math.geom2d.Point2D)
  */
 public double distance(Point2D point) {
   return distance(point.x(), point.y());
 }
Exemplo n.º 15
0
 public double distance(Point2D point) {
   return abs(Point2D.distance(xc, yc, point.x(), point.y()) - r);
 }
Exemplo n.º 16
0
 /** Returns true if the point p lies on the ellipse, with precision given by Shape2D.ACCURACY. */
 public boolean contains(Point2D p) {
   return contains(p.x(), p.y());
 }
Exemplo n.º 17
0
 public boolean isInside(Point2D p) {
   return signedDistance(p.x(), p.y()) < 0;
 }