如何对两点之间的 x、y 和 z 进行线性插值?

How to linear interpolate the x, y, and z between two points?

假设在开始时间 0s 我有 point_1(10,20,35),在结束时间 10s 我有 point_2(20,40,50)

我将如何使用线性插值法找到一个点在 5 秒时的位置?

我想在不使用任何 python 库的情况下手动执行此操作。我正在尝试了解如何对 x、y 和 z 平面使用线性插值。

我知道我会从这个开始

start_time = 0
start_x = 10
start_y = 20
start_z = 35

end_time = 10
end_x = 20
end_y = 40
end_z = 50

# I want the point at time 5s
time = 5
def interpolate():
    pass

x1x2之间进行插值的公式是(1 - t) * x1 + t * x2,其中t的范围是0到1。我们需要将t放入这个范围优先:

def interpolate(v1, v2, start_time, end_time, t):
    t = (t - start_time) / (end_time - start_time)
    return tuple((1 - t) * x1 + t * x2 for x1, x2 in zip(v1, v2))

示例:

>>> interpolate((10, 20, 35), (20, 40, 50), 0, 10, 5)
(15.0, 30.0, 42.5)