0

我想从我生成的贝塞尔曲线路径中获取 Y 坐标值的列表。

但我得到的只是一条直线,出了什么问题?

这是代码片段:

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]));
}

因此,我没有给出正确的结果 - y 坐标在开始和结束时挤在一起,而在中间更分散,我得到了一个增量整数系列,增量是恒定的,这表明它是一条直线。怎么了?

4

1 回答 1

0

所以显然要使用这种cubicPath方法,最好有一个1:1的X yo Y轴比而不是任意一个。

也就是说,想象一个实心正方形,其中每边的长度相同。将所有点 P0、P1、P2、P3 固定到这个正方形的边上,这样就可以得到三次贝塞尔曲线。在一天结束时,您的第一个和最后一个点(P0 和 P3)应该是这样的:

(0,0) (squareLength, squareLength)

或这个:

(0,squareLength) (squareLength,0)

我强烈建议不要使用不相等的 X 到 Y 轴,这会给你带来很多麻烦,因为曲线会显得很奇怪,在我的情况下,我的 Y 轴的范围为 1~1000 而 X 轴的范围为只有1~50,曲线被拉得很长,如果你把它画出来,它看起来就像一条直线。

于 2019-01-26T10:35:38.087 回答