我想在贝塞尔曲线路径上从上到下移动图像,但我不知道如何计算该路径的 x/y 点和斜率。该路径如下图所示:
我有起点、终点和两个控制点。
Path path = new Path();
Point s = new Point(150, 5);
Point cp1 = new Point(140, 125);
Point cp2 = new Point(145, 150);
Point e = new Point(200, 250);
path.moveTo(s.x, s.y);
path.cubicTo(cp1.x, cp1.y, cp2.x, cp2.y, e.x, e.y);
Android 为您提供了 API 来完成您想要的任务。使用名为 android.graphics.PathMeasure 的类。您会发现有两种有用的方法:getLength(),用于检索路径的总长度(以像素为单位);getPosTan(),用于检索曲线上指定距离处的点的 X,Y 位置(以及该位置的切线。)
例如,如果 getLength() 返回 200,并且您想知道曲线中间点的 X、Y 位置,请使用距离=100 调用 getPosTan()。
更多信息:http://developer.android.com/reference/android/graphics/PathMeasure.html http://developer.android.com/reference/android/graphics/PathMeasure.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)