У меня проблема с реализацией кода для рисования кривой Безье, которая отлично работает в iOS.
Я хочу этот эффект. , но с Touch Points.
Но я что-то не так делаю.
Проблема в этой строке
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");
}
}