コード例 #1
0
ファイル: EllipseArc2D.java プロジェクト: CKehl/javaGeom
  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;
  }
コード例 #2
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);
  }
コード例 #3
0
ファイル: Circle2D.java プロジェクト: AidanDelaney/javaGeom-1
  /**
   * 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);
  }
コード例 #4
0
 /**
  * Draws the point set on the specified Graphics2D, by filling a disc with a given radius.
  *
  * @param g2 the graphics to draw the point set
  */
 public void draw(Graphics2D g2, double r) {
   double x, y;
   double w = 2 * r;
   for (Point2D point : points) {
     x = point.x();
     y = point.y();
     g2.fill(new java.awt.geom.Ellipse2D.Double(x - r, y - r, w, w));
   }
 }
コード例 #5
0
  public Box2D boundingBox() {
    // init with max values in each direction
    double xmin = Double.MAX_VALUE;
    double ymin = Double.MAX_VALUE;
    double xmax = Double.MIN_VALUE;
    double ymax = Double.MIN_VALUE;

    // update max values with each point
    for (Point2D point : points) {
      xmin = Math.min(xmin, point.x());
      ymin = Math.min(ymin, point.y());
      xmax = Math.max(xmax, point.x());
      ymax = Math.max(ymax, point.y());
    }

    // create the bounding box
    return new Box2D(xmin, xmax, ymin, ymax);
  }
コード例 #6
0
ファイル: EllipseArc2D.java プロジェクト: CKehl/javaGeom
  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);
  }
コード例 #7
0
ファイル: EllipseArc2D.java プロジェクト: CKehl/javaGeom
 @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);
 }
コード例 #8
0
ファイル: EllipseArc2D.java プロジェクト: CKehl/javaGeom
  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;
  }
コード例 #9
0
  /**
   * Write streetlight objects in dsf file.
   *
   * @param osmPolygon osm road polygon
   */
  public void writeStreetLightToDsf(OsmPolygon osmPolygon) {
    // init d'un entier pour modulo densité street lights
    Integer densityIndex = 0;
    if (XplaneOptionsHelper.getOptions().getLightsDensity() == 0) {
      densityIndex = 10;
    } else {
      if (XplaneOptionsHelper.getOptions().getLightsDensity() == 1) {
        densityIndex = 5;
      } else {
        if (XplaneOptionsHelper.getOptions().getLightsDensity() == 2) densityIndex = 3;
      }
    }
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < osmPolygon.getPolygon().getVertices().size(); i++) {
      if ((i % densityIndex) == 0) {
        Point2D lightLoc = osmPolygon.getPolygon().getVertex(i);
        lightLoc.x = lightLoc.x + 0.0001;
        lightLoc.y = lightLoc.y + 0.0001;
        if (GeomUtils.compareCoordinates(lightLoc, currentTile)) {
          Random randomGenerator = new Random();
          int orientation = randomGenerator.nextInt(360);
          sb.append(
              "OBJECT "
                  + dsfObjectsProvider.getRandomStreetLightObject()
                  + " "
                  + (lightLoc.y)
                  + " "
                  + (lightLoc.x)
                  + " "
                  + orientation);
          sb.append(System.getProperty("line.separator"));
          // stats
          StatsHelper.addStreetLight(stats);
        }
      }
    }

    writer.write(sb.toString());
  }
コード例 #10
0
 /** Return distance to the closest point of the collection */
 public double distance(Point2D p) {
   return distance(p.x(), p.y());
 }
コード例 #11
0
ファイル: Circle2D.java プロジェクト: AidanDelaney/javaGeom-1
 public double signedDistance(Point2D point) {
   return signedDistance(point.x(), point.y());
 }
コード例 #12
0
ファイル: Circle2D.java プロジェクト: AidanDelaney/javaGeom-1
 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);
 }
コード例 #13
0
ファイル: Circle2D.java プロジェクト: AidanDelaney/javaGeom-1
 /** 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);
 }
コード例 #14
0
ファイル: Circle2D.java プロジェクト: AidanDelaney/javaGeom-1
 /**
  * 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;
 }
コード例 #15
0
ファイル: Ray2D.java プロジェクト: adelancy/java-Geom-android
 /**
  * Creates a new Ray2D, originating from point <code>point<\code>, and going
  * in the direction specified by <code>vector<\code>.
  */
 public Ray2D(Point2D point, Vector2D vector) {
   this(point.x(), point.y(), vector.x(), vector.y());
 }
コード例 #16
0
ファイル: Circle2D.java プロジェクト: AidanDelaney/javaGeom-1
 /** Create a new circle with specified point center and radius */
 public Circle2D(Point2D center, double radius) {
   this(center.x(), center.y(), radius, true);
 }
コード例 #17
0
ファイル: Ray2D.java プロジェクト: adelancy/java-Geom-android
 /**
  * Creates a new Ray2D, originating from
  * <code>point1<\code>, and going in the
  * direction of <code>point2<\code>.
  */
 public Ray2D(Point2D point1, Point2D point2) {
   this(point1.x(), point1.y(), point2.x() - point1.x(), point2.y() - point1.y());
 }
コード例 #18
0
ファイル: EllipseArc2D.java プロジェクト: CKehl/javaGeom
 public boolean isInside(Point2D p) {
   return signedDistance(p.x(), p.y()) < 0;
 }
コード例 #19
0
ファイル: Ray2D.java プロジェクト: adelancy/java-Geom-android
 /**
  * Creates a new Ray2D, originating from point <code>point<\code>, and going
  * in the direction specified by <code>angle<\code> (in radians).
  */
 public Ray2D(Point2D point, double angle) {
   this(point.x(), point.y(), Math.cos(angle), Math.sin(angle));
 }
コード例 #20
0
ファイル: Ray2D.java プロジェクト: adelancy/java-Geom-android
 /**
  * Creates a new Ray2D, originating from point <code>point<\code>, and going
  * in the direction defined by vector <code>(dx,dy)<\code>.
  */
 public Ray2D(Point2D point, double dx, double dy) {
   this(point.x(), point.y(), dx, dy);
 }
コード例 #21
0
ファイル: Circle2D.java プロジェクト: AidanDelaney/javaGeom-1
 public double distance(Point2D point) {
   return abs(Point2D.distance(xc, yc, point.x(), point.y()) - r);
 }
コード例 #22
0
ファイル: EllipseArc2D.java プロジェクト: CKehl/javaGeom
 /*
  * (non-Javadoc)
  *
  * @see math.geom2d.Shape2D#distance(math.geom2d.Point2D)
  */
 public double distance(Point2D point) {
   return distance(point.x(), point.y());
 }
コード例 #23
0
ファイル: EllipseArc2D.java プロジェクト: CKehl/javaGeom
 public double signedDistance(Point2D p) {
   return signedDistance(p.x(), p.y());
 }
コード例 #24
0
ファイル: Circle2D.java プロジェクト: AidanDelaney/javaGeom-1
 /** 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());
 }
コード例 #25
0
ファイル: EllipseArc2D.java プロジェクト: CKehl/javaGeom
 /*
  * (non-Javadoc)
  *
  * @see java.awt.Shape#contains(Point2D)
  */
 public boolean contains(Point2D point) {
   return contains(point.x(), point.y());
 }