Interpolation recurrence relation limit

71 Views Asked by At

I'm dealing with a problem (background at the end) where I'm using linear interpolation. I'm trying to figure out number of steps required to get within a specified limit, and the interpolation factor required.

To formalize, I have the following relation:

Given $a$ and $b$ as limits, and an interpolation factor $s$:

$$x_{0} = a$$ $$x_{n} = x_{n-1} + s(b - x_{n-1})$$

I'd like to know the value of $s$ such that $x_{m}$ for some $m$ is within a small difference of $b$ (not a huge issue how far, but lets just say within range $[0.99b, b]$, although ideally I would like to specify some value $c <= b$).

So far I've been able to rewrite the relation as (I think...):

$$x_{n} = a(1-s)^n + sb\sum_{i=1}^n\binom{n}{i}(-1)^{i-1}s^i$$

But from here I can't get that last step on how to compute the appropriate $s$ for a given $m$ and $c$.

So to explain some background, I'm working on a simulation where I need to precisely interpolate between 2 positions (and smoothly too, so can't just use fixed step interpolation). The positions will vary a lot, and the constraint is a time factor, hence there is a required number of steps. The location just needs to be within a small range of the target value within that number of steps (the range may vary).

I have added a code stub here as well just to illustrate the problem:

Vector3 currentPosition;
Vector3 targetPosition;

// the time taken at each interpolation step
float dt;

// the time limit
float limit;

// the allowed error
float error;

// need to calculate s such that I can interpolate correctly
float s;

Vector3 newPosition = currentPosition + s * (targetPosition - currentPosition);

Any help would be appreciated and please let me know if you need more information!

1

There are 1 best solutions below

1
On BEST ANSWER

If you have $$x_{n} = x_{n-1} + s(b - x_{n-1})\qquad \text{with} \qquad x_0=a$$ the usual method gives $$x_n=b+(a-b) (1-s)^n$$ while what you wrote is

$$x_n=(1-s)^n (a-b s)+b s$$ which is not correct.

So, if you want $$x_m=k b\implies s=1-\left(\frac{b (k-1)}{a-b}\right)^{\frac{1}{m}}$$