我正在尝试从Unity中的点列表生成Catmull-Rom曲线。由于我不想在曲线点之间存储点,因此我选择使用可以根据时间计算Catmull-Rom曲线中位置的解决方案。有一些例子,here和here,但是,它们都没有显示如何实现alpha。
我想实现alpha的原因是我能够在向心,弦和均匀的Catmull-Rom曲线之间进行更改。
private Vector3 GetCatmullRomPosition(float t, Vector3 p0, Vector3 p1,
Vector3 p2, Vector3 p3, float alpha)
{
Vector3 a = 2f * p1;
Vector3 b = p2 - p0;
Vector3 c = 2f * p0 - 5f * p1 + 4f * p2 - p3;
Vector3 d = -p0 + 3f * p1 - 3f * p2 + p3;
return 0.5f * (a + (b * t) + (c * t * t) + (d * t * t * t));
}
答案 0 :(得分:1)
对于任何来到这里的人来说,答案实际上来自原始问题的一个链接中的数学。这是来自SO问题answer的Catmull-rom curve with no cusps and no self-intersections 。因此归功于cfh。
在我的原始问题中发布的代码是计算均匀Catmull-Rom样条曲线中的点的好方法,但是,它没有考虑alpha。因此,它不能用于弦,或向心(或其间的任何东西)Catmull-Rom样条。下面的代码确实考虑了alpha,因此支持chordal和centripetal Catmull-Rom样条。
不用多说,这里是移植到Unity的C#代码。
session.auto_start = 1