Exemple #1
0
  /*
   * (non-Javadoc)
   *
   * @see math.geom2d.Shape2D#signedDistance(math.geom2d.Point2D)
   */
  public double signedDistance(double x, double y) {
    boolean direct = angleExtent >= 0;

    double dist = distance(x, y);
    Point2D point = new Point2D(x, y);

    boolean inside = ellipse.isInside(point);
    if (inside) return angleExtent > 0 ? -dist : dist;

    Point2D p1 = point(startAngle);
    double endAngle = startAngle + angleExtent;
    Point2D p2 = point(endAngle);
    boolean onLeft = (new StraightLine2D(p1, p2)).isInside(point);

    if (direct && !onLeft) return dist;
    if (!direct && onLeft) return -dist;

    Ray2D ray = new Ray2D(p1, -sin(startAngle), cos(startAngle));
    boolean left1 = ray.isInside(point);
    if (direct && !left1) return dist;
    if (!direct && left1) return -dist;

    ray = new Ray2D(p2, -sin(endAngle), cos(endAngle));
    boolean left2 = ray.isInside(point);
    if (direct && !left2) return dist;
    if (!direct && left2) return -dist;

    if (direct) return -dist;
    else return dist;
  }
Exemple #2
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;
      }
    }
  }