0

I want to get a list of Y coordinate values from a Bezier curve path that I generated.

But all I got was a straight line, what went wrong?

Here's the code snippet:

private static ArrayList<Integer> ys;

path.moveTo(point0.x, point0.y); //the origin, 0,0
path.cubicTo(point1.x, point1.y, point2.x, point2.y, point3.x, point3.y);//nothing wrong with the coordinates of these points as I checked them repeatedly and used several online websites to verify

PathMeasure pm = new PathMeasure(path, false);

float aCoordinates[] = {0f, 0f};

for (int i = 1;i<=totalNumberOfDots;i++) {
    pm.getPosTan(pm.getLength()*(float)i/totalNumberOfDots, aCoordinates, null);
    ys.add(Math.round(aCoordinates[1]));
}

So instead of give the correct results - y coords that are huddled together in the beginning and the end and more scattered in the middle, I get an incremental series of integers with the increment being constant which suggests it's a straight line. What's wrong?

1 Answers1

0

So apparently to use this cubicPath method, it's better for you to have an 1:1 X yo Y axis ratio instead of an arbitrary one.

That is, picture a solid square where each side is of the same length. Fix all your points P0, P1, P2, P3 onto the sides of this square so you can have a cubic Bezier curve. At the end of the day, your first and last point (P0 and P3) should be either this:

(0,0) (squareLength, squareLength)

or this:

(0,squareLength) (squareLength,0)

I highly advice against using unequal X to Y axis, it WILL cause you a great deal of trouble as the curve will appear rather strange and in my case, my Y axis has a range of 1~1000 while the X axis has a range of only 1~50, the curve was so stretched that if you plot it, it looks like a straight line.