Interpolation over more than 2 points

167 Views Asked by At

Suppose I have 2 points $A$ and $B$. Doing an interpolation $Lerp(A,B,t)$ is pretty easy:

$$Lerp(A,B,t) = A + (B-A)t$$

My question is: given I have $n$ points $P_1, P_2, \dots, P_n$, how would I interpolate between them? The behaviour I expect is to always move in segments from $P_i$ to $P_{i+1}$ (without curves like Beziers). For simplicity one can consider that two adjacent points $P_i$ to $P_{i+1}$ have the same distance between them, although the points are randomly disposed.

enter image description here

1

There are 1 best solutions below

0
On BEST ANSWER

While $[a,b]\subset \mathbb{R}$, let's define $[n]\subset \mathbb{N}$ such that $[n] = \{1,2,\ldots, n\}$. This is a common shorthand in combinatorics, and useful in this context.

Define function:

$$L: [0,1] \to [n]$$

$$L(t) = 1+\lfloor (n-1)t \rfloor$$

$$R: [0,1] \to [n]$$

$$R(t) = 1+\lceil (n-1)t \rceil$$

Then, I am pretty sure you can define your interpolation function as:

$$Lerp(\{P_1,\ldots, P_n\},t) = P_{L(t)} + (P_{R(t)}-P_{L(t)})\left(1+(n-1)t-L(t)\right)$$