gpt4 book ai didi

c - vector 线性插值与线性外插相同吗?

转载 作者:行者123 更新时间:2023-12-01 14:17:25 25 4
gpt4 key购买 nike

具有如下所示的线性插值 (lerp) 函数:

/// 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;
}

这里通过线性外推,我的意思是在线上找到一个位置(见图)
enter image description here

它是否适用于线性外推(比如提供 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] 范围内)并在线上某处获得一个唯一点。

    关于c - vector 线性插值与线性外插相同吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15408153/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com