コード例 #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
ファイル: 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());
 }