Accuracy of Lagrange polynomial

526 Views Asked by At

I'm sampling positions of an object on its trajectory in 2D. The trajectory can look anyhow - it's mouse movement on the pc screen. The problem I'm solving is that sometimes I need to upsample the points of the trajectory which I sampled before. So I needed to interpolate the existing points. I looked for something easy to understand and found Lagrange polynomial (I used the wikipedia equations).

I always took three points and tried to compute a new point in between them. But as I checked the results, there were quite lots of errors also in basic scenarios.

For example there was a circle like trajectory (part of a circle), consisting of three points: [-364, -60], [-361, 40], [-329, 127]. I tried to compute point value on -345. By looking at the given points, one would say the value will be somewhere in the middle between 40 and 127. But the value according to lagrange polynomial was 307.4, which really is not a part of this circle.

So my question is, is lagrange really so inaccurate or this isn't a use case where it should be used? (In the second case what would be a better option here?)