public java.awt.geom.GeneralPath appendPath(java.awt.geom.GeneralPath path) { double cot = cos(theta); double sit = sin(theta); double cost, sint; if (direct) { // Counter-clockwise circle for (double t = .1; t < PI * 2; t += .1) { cost = cos(t); sint = sin(t); path.lineTo( (float) (xc + r * cost * cot - r * sint * sit), (float) (yc + r * cost * sit + r * sint * cot)); } } else { // Clockwise circle for (double t = .1; t < PI * 2; t += .1) { cost = cos(t); sint = sin(t); path.lineTo( (float) (xc + r * cost * cot + r * sint * sit), (float) (yc + r * cost * sit - r * sint * cot)); } } // line to first point path.lineTo((float) (xc + r * cot), (float) (yc + r * sit)); return path; }
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; }
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; }