【发布时间】:2017-04-22 00:18:34
【问题描述】:
我有一条样条线,我可以沿着曲线以可变速度移动对象,但我想以恒定速度移动,我该如何实现?
public static class SplineCurve {
public static Vector3 GetPoint (Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t) {
t = Mathf.Clamp01(t);
float oneMinusT = 1f - t;
return
oneMinusT * oneMinusT * oneMinusT * p0 +
3f * oneMinusT * oneMinusT * t * p1 +
3f * oneMinusT * t * t * p2 +
t * t * t * p3;
}
public static Vector3 GetFirstDerivative (Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t) {
t = Mathf.Clamp01(t);
float oneMinusT = 1f - t;
return
3f * oneMinusT * oneMinusT * (p1 - p0) +
6f * oneMinusT * t * (p2 - p1) +
3f * t * t * (p3 - p2);
}
}
我将常量参数 t 发送到该曲线并获取该点,然后将对象移动到该点,但这给了我可变速度。我想以恒定的速度移动我的对象,我该如何实现?
是否有任何方程可以让我求解特定距离的 t?
B(t) = (1 - t)^3 * P0 + 3 * (1 - t)^2 * t * P1 + 3 * (1 - t) * t^2* P2 + t^3* P3
我用过这个公式
【问题讨论】:
-
因为您可以计算导数,所以将步长按因子
(desired speed)/(norm of derivative)缩放。
标签: c# math unity3d bezier spline