我在实现用于绘制贝塞尔曲线的代码时遇到问题,该曲线在 iOS 中运行良好。
我想要这个效果。但有接触点。
但我搞错了。这条线的问题
previousCenterPoint = CenterPointOf(new PointF(points.get(0).x,points.get(0).y), previousPoint);
在 iOS 中,使用 currentPoint 我们可以获得当前点。
请建议我如何获得路径的当前轮廓点....
这是我的代码..
public void makeBezierCurve(ArrayList<PointF> points) {
if (points.size() > 0) {
if (points.size() < 3) {
switch (points.size()) {
case 1:
lineTo(points.get(0).x, points.get(0).y);
case 2:
lineTo(points.get(1).x, points.get(1).y);
default:
break;
}
} else {
PointF previousPoint = new PointF(0, 0);
PointF previousCenterPoint = new PointF(0, 0);
PointF centerPoint = new PointF(0, 0);
double centerPointDistance = 0;
double obliqueAngle = 0;
PointF previousControlPoint1 = new PointF(0, 0);
PointF previousControlPoint2 = new PointF(0, 0);
PointF controlPoint1 = new PointF(0, 0);
float contractionFactor = 0.7f;
for (int i = 0; i < points.size(); i++) {
PointF pointI = points.get(i);
if (i > 0) {
previousCenterPoint = CenterPointOf(new PointF(points.get(0).x, points.get(0).y), previousPoint);
centerPoint = CenterPointOf(previousPoint, pointI);
centerPointDistance = DistanceBetween(previousCenterPoint, centerPoint);
obliqueAngle = ObliqueAngleOfStraightThrough(centerPoint, previousCenterPoint);
previousControlPoint2 = new PointF((float) (previousPoint.x - 0.5 * contractionFactor * centerPointDistance * Math.cos(obliqueAngle)), (float) (previousPoint.y - 0.5 * contractionFactor * centerPointDistance * Math.sin(obliqueAngle)));
controlPoint1 = new PointF((float) (previousPoint.x + 0.5 * contractionFactor * centerPointDistance * Math.cos(obliqueAngle)), (float) (previousPoint.y + 0.5 * contractionFactor * centerPointDistance * Math.sin(obliqueAngle)));
}
if (i == 1) {
quadTo(previousControlPoint2.x, previousControlPoint2.y, previousPoint.x, previousPoint.y);
} else if (i >= 2 && i < points.size() - 1) {
cubicTo(previousControlPoint1.x, previousControlPoint1.y, previousControlPoint2.x, previousControlPoint2.y, previousPoint.x, previousPoint.y);
} else if (i == points.size() - 1) {
cubicTo(previousControlPoint1.x, previousControlPoint1.y, previousControlPoint2.x, previousControlPoint2.y, previousPoint.x, previousPoint.y);
quadTo(controlPoint1.x, controlPoint1.y, pointI.x, pointI.y);
}
previousControlPoint1.set(controlPoint1);
previousPoint.set(pointI);
}
}
} else {
logger.e("BezierHelper", "makeBezierCurve: error");
}
}