【发布时间】:2017-07-18 22:11:24
【问题描述】:
我正在尝试使用 Hermite 样条在 4 个点之间进行插值。然而,我的样条曲线似乎总是从第二个点开始,并且只插入到第三个点。我已经尝试了几种不同的计算并得到相同的结果。
谁能告诉我这方面的见解?这是我的代码。
public ControlPoint Get(float t)
{
//speed multiplyer
//t = t * 10;
return new ControlPoint(
new Vector3(Hermite(points[0].pos.x, points[1].pos.x, points[2].pos.x, points[3].pos.x, t)
, Hermite(points[0].pos.y, points[1].pos.y, points[2].pos.y, points[3].pos.y, t)
, Hermite(points[0].pos.z, points[1].pos.z, points[2].pos.z, points[3].pos.z, t)
),
new Quaternion(Hermite(points[0].rot.x, points[1].rot.x, points[2].rot.x, points[3].rot.x, t)
, Hermite(points[0].rot.y, points[1].rot.y, points[2].rot.y, points[3].rot.y, t)
, Hermite(points[0].rot.z, points[1].rot.z, points[2].rot.z, points[3].rot.z, t)
, Hermite(points[0].rot.w, points[1].rot.w, points[2].rot.w, points[3].rot.w, t)
)
);
}
float Hermite(
float y0, float y1,
float y2, float y3,
float mu,
float tension = 0,
float bias = 0)
{
float m0, m1, mu2, mu3;
float a0, a1, a2, a3;
mu2 = mu * mu;
mu3 = mu2 * mu;
m0 = (y1 - y0) * (1 + bias) * (1 - tension) / 2;
m0 += (y2 - y1) * (1 - bias) * (1 - tension) / 2;
m1 = (y2 - y1) * (1 + bias) * (1 - tension) / 2;
m1 += (y3 - y2) * (1 - bias) * (1 - tension) / 2;
a0 = 2 * mu3 - 3 * mu2 + 1;
a1 = mu3 - 2 * mu2 + mu;
a2 = mu3 - mu2;
a3 = -2 * mu3 + 3 * mu2;
return (a0 * y1 + a1 * m0 + a2 * m1 + a3 * y2);
}
【问题讨论】: