本文整理汇总了Java中java.awt.geom.Path2D.curveTo方法的典型用法代码示例。如果您正苦于以下问题:Java Path2D.curveTo方法的具体用法?Java Path2D.curveTo怎么用?Java Path2D.curveTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.geom.Path2D
的用法示例。
在下文中一共展示了Path2D.curveTo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: renderCurvePath
import java.awt.geom.Path2D; //导入方法依赖的package包/类
private Shape renderCurvePath(int[] xPoints, int[] yPoints) {
Path2D path = new Path2D.Double();
path.moveTo(xPoints[0], yPoints[0]);
int curveIndex;
for (curveIndex = 0; curveIndex <= xPoints.length - 3; curveIndex += 3) {
path.curveTo(xPoints[curveIndex], yPoints[curveIndex], xPoints[curveIndex + 1], yPoints[curveIndex + 1], xPoints[curveIndex + 2], yPoints[curveIndex + 2]);
}
if (xPoints.length >= 3 && xPoints.length - curveIndex == 2) {
path.curveTo(xPoints[xPoints.length - 3], yPoints[xPoints.length - 3], xPoints[xPoints.length - 2], yPoints[xPoints.length - 2], xPoints[xPoints.length - 1], yPoints[xPoints.length - 1]);
} else {
path.lineTo(xPoints[xPoints.length - 1], yPoints[xPoints.length - 1]);
}
return path;
}
示例2: arcToBezier
import java.awt.geom.Path2D; //导入方法依赖的package包/类
/**
* Converts an arc to cubic Bezier segments and records them in p.
*
* @param p The target for the cubic Bezier segments
* @param cx The x coordinate center of the ellipse
* @param cy The y coordinate center of the ellipse
* @param a The radius of the ellipse in the horizontal direction
* @param b The radius of the ellipse in the vertical direction
* @param e1x E(eta1) x coordinate of the starting point of the arc
* @param e1y E(eta2) y coordinate of the starting point of the arc
* @param theta The angle that the ellipse bounding rectangle makes with the horizontal plane
* @param start The start angle of the arc on the ellipse
* @param sweep The angle (positive or negative) of the sweep of the arc on the ellipse
*/
private static void arcToBezier(Path2D p, double cx, double cy, double a,
double b, double e1x, double e1y, double theta, double start,
double sweep) {
// Taken from equations at:
// http://spaceroots.org/documents/ellipse/node8.html
// and http://www.spaceroots.org/documents/ellipse/node22.html
// Maximum of 45 degrees per cubic Bezier segment
int numSegments = Math.abs((int) Math.ceil(sweep * 4 / Math.PI));
double eta1 = start;
double cosTheta = Math.cos(theta);
double sinTheta = Math.sin(theta);
double cosEta1 = Math.cos(eta1);
double sinEta1 = Math.sin(eta1);
double ep1x = (-a * cosTheta * sinEta1) - (b * sinTheta * cosEta1);
double ep1y = (-a * sinTheta * sinEta1) + (b * cosTheta * cosEta1);
double anglePerSegment = sweep / numSegments;
for (int i = 0; i < numSegments; i++) {
double eta2 = eta1 + anglePerSegment;
double sinEta2 = Math.sin(eta2);
double cosEta2 = Math.cos(eta2);
double e2x = cx + (a * cosTheta * cosEta2)
- (b * sinTheta * sinEta2);
double e2y = cy + (a * sinTheta * cosEta2)
+ (b * cosTheta * sinEta2);
double ep2x = -a * cosTheta * sinEta2 - b * sinTheta * cosEta2;
double ep2y = -a * sinTheta * sinEta2 + b * cosTheta * cosEta2;
double tanDiff2 = Math.tan((eta2 - eta1) / 2);
double alpha = Math.sin(eta2 - eta1)
* (Math.sqrt(4 + (3 * tanDiff2 * tanDiff2)) - 1) / 3;
double q1x = e1x + alpha * ep1x;
double q1y = e1y + alpha * ep1y;
double q2x = e2x - alpha * ep2x;
double q2y = e2y - alpha * ep2y;
p.curveTo((float) q1x, (float) q1y, (float) q2x, (float) q2y,
(float) e2x, (float) e2y);
eta1 = eta2;
e1x = e2x;
e1y = e2y;
ep1x = ep2x;
ep1y = ep2y;
}
}
示例3: addCubics
import java.awt.geom.Path2D; //导入方法依赖的package包/类
static Path2D addCubics(Path2D p2d) {
for (int i = 0; i < 10; i++) {
p2d.curveTo(1.1 * i, 1.2 * i, 1.3 * i, 1.4 * i, 1.5 * i, 1.6 * i);
}
return p2d;
}
示例4: addCubic
import java.awt.geom.Path2D; //导入方法依赖的package包/类
static void addCubic(Path2D p2d, int i) {
p2d.curveTo(1.1 * i, 1.2 * i, 1.3 * i, 1.4 * i, 1.5 * i, 1.6 * i);
}