5

To implement a system that will control hardware, I need an interpolation between points on a graph that does never overshoot. By overshooting I mean that between two points there may be no y-result that has a higher value than either of thew two points.

First I thought that "monotone cubic interpolation" might be what I need, however after implementation I found that this isn't always the case. After researching, I found that this only reduces overshooting, doesn't prevent it entirely. That can also be seen here, I think: Implementation of Monotone Cubic Interpolation )

So what other algorithms/formulas could fulfill this requirement?

Kromster
  • 173
  • 5
    Linear interpolation doesn't overshoot. If that doesn't work, please list what additional criteria you need to satisfy. –  Sep 03 '18 at 02:02
  • @Bungo You are right! An additional criteria is needed. Hm, I'm not a matimatician, so simply put I want a curve that's as smooth as possible and also monotone between two points. Maybe the following definition makes sense: The second derivation on the curve shall be overall minimal. Linear interpolation has a very high second derivation at every point where direction changes. – DragonGamer Sep 03 '18 at 02:24
  • 2
    The monotone cubic interpolation that I'm familiar with (the Fritsch-Carlson method) is guaranteed not to overshoot the data. If your implementation does overshoot, either you have implemented something that is not truly monotone, or there is a bug in your implementation. –  Sep 03 '18 at 04:16
  • 1
    There is a method called Barycentric Lagrange interpolation. There are plenty of libraries available for it. –  Sep 03 '18 at 21:00
  • 1
    Indeed there was a dumb implementation mistake x.x Oh well, sorry for wasting your all time! Barycentric Lagrange interpolation sounds interesting too though. – DragonGamer Sep 03 '18 at 21:19

3 Answers3

3

If you can do without the 'strict' interpolation criterion (saying that the curve must pass precisely through the knot points), you can use a b-spline without prefiltering - simply use the knot points you have as the spline's coefficients. The b-spline is bound to the convex hull of it's coefficients, so it can't overshoot the range if it's coefficients aren't ever out-of-bounds. But omitting the prefilter will 'spoil' the interpolation criterion, and the resulting curve will not pass exactly through your data points - it will appear slightly 'smoothed'. Oftentimes, though, this is quite acceptable, and it will never overshoot.

0

One option is use a monotone cubic interpolation but always check the values of the points on both sides, and if the value exceeds one of the two y values, just go with that y value instead.

JoshuaZ
  • 1,802
  • 3
    Thank you for the response. Unfortunately that results in quite a "corner" at the point where it would start to overshoot. "Bungo" u there is right though, I need to specify an idditional criteria. One moment. – DragonGamer Sep 03 '18 at 02:21
0

you want "smoothstep" or "smootherstep" you can derive them from differential equations or function intuition, but basically these shape linear interpolation so that the derivative is 0 at the ends, and concatenating these curves results in continuous first derivatives for smoothstep, and both first and second for smootherstep.

linear: lerp(a, b, t)

smoothstep: lerp(a, b, 3t^2 - 2t^3)

smootherstep: lerp(a, b, 6t^5 - 16t^4 + 10t^3)

lerp being a shorthand for a + (b-a)*t

these do lose some of the nice visual properties of the cubic interpolation - they only sample 2 points, not 4, but they does meet the criteria you specify, never overshooting and being continuous and smooth to first or second order.

jheriko
  • 101
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center. – Community Jun 19 '22 at 23:22