矢量线性插值与线性插值相同吗?
问题描述:
具有线性插值(线性插值)函数看起来像:矢量线性插值与线性插值相同吗?
/// Performs a linear interpolation between two vectors. (@p v1 toward @p v2)
/// @param[out] dest The result vector. [(x, y, x)]
/// @param[in] v1 The starting vector.
/// @param[in] v2 The destination vector.
/// @param[in] t The interpolation factor. [Limits: 0 <= value <= 1.0]
inline void dtVlerp(float* dest, const float* v1, const float* v2, const float t)
{
dest[0] = v1[0]+(v2[0]-v1[0])*t;
dest[1] = v1[1]+(v2[1]-v1[1])*t;
dest[2] = v1[2]+(v2[2]-v1[2])*t;
}
这里由我的意思是寻找上线的位置(参见图)
将它用于线性外推的工作线性外推(比方说提供coef > 1
或小于0
)?
答
是的,外推法与插值法相同(至少在此情况下)。
如果从高中几何记得,任何线由以下形式的公式定义:
y = mx + c
其中m
是梯度和c
是一个偏移量(即,y轴截距) 。如果你看看上面的代码,你会看到每个维度都有一个等式:
dest = v1 + (v2-v1)*t
这是一样的!我们简单地取代如下:
y <-- dest
x <-- t
m <-- (v2-v1)
c <-- v1
,您可以设置t
为任意值(不只是在区间[0, 1]),并获得一个独特的点在线上。
是的,线性插值和线性插值的唯一区别在于,插值时,您可以估计已知数据点之间的值,并且在外推中估计已知范围之外的值。 – 2013-03-14 11:39:26