2
$\begingroup$

I need to give a bit of a background first, so please bare with me. I have a set of values that represent servo motor position values. By default I end up with a large set of values and I'd like to simply it.

Here's a test plot of the positions and the moving average "local extrema" points marked with white boxes:

Servo ZeroX

The two graphs are for the two servos used in this particular test.

I'm currently happy with the points extracted and would like to interpolate between these. I can use linear interpolation, but the motion looks robotic and I'd like to preserve the nice easing that was recorded. I would like to use some sort of bezier interpolation to get smoother/more organic results regarding motion, but here's where I'm stuck.

I don't a strong mathematical background, so this is difficult for me. I've looked on Wikipedia at the Bezier curve equation and Hermite curve which look like what I might need.

For any 2 'keyframes'/key servo positions (marked with white) I can use the start and end points for a cubic equation, but I need to find out the 'anchor' points/other two members of the equation so I can compute a smooth interpolated value.

Can someone please explain ('dumbed down' for me if possible) how I can find 2 members of a bezier equation knowing the other two ?

Any other ideas/suggestions are welcome and I can provide more explanations and (Processing)code if needed.

  • 0
    I would probably suggest, like @MUD, that cubic splines will be easier for you to approximate your functions.2012-08-29

3 Answers 3

2

I suggest that instead of Bézier splines, you use interpolating cubic splines.

For cubic splines, you give the points that you want the curve to pass through, and the method finds a nice smooth piecewise-cubic curve that passes through those points.

  • 0
    https://secure.wikimedia.org/wikipedia/en/wiki/Cubic_Hermite_spline#Interpolation_on_.28xk.2C_xk.2B1.292012-08-28
1

If you white dots are local extrema, the tangent is horizontal there. You might want to just put a half a sine wave between them, as it comes with the zero slope. If $(x_1,y_1)$ and $(x_2,y_2)$ are successive dots, so one is a minimum and one is a maximum, the half wavelength is $x_2-x_1$ and the full amplitude is $y_2-y_1$. Your interpolating function is then $y=y_1+\frac 12(y_2-y_1)\left(1-\cos (\frac {x-x_1}{x_2-x_1}\pi)\right)$

1

You don't really need Bezier curves because you are graphing a function, not drawing a curve. You want $y = f(x)$ (which is the graph of a function) rather than $P(t) = (x(t),y(t))$ (which is a 2D curve).

But you can use what mathematicians call "real-valued" Bezier curves.

Suppose you have a data point at $(x_1, y_1)$ and the next one is at $(x_2, y_2)$. We want a smooth curve between these two points. And you say that each data point is a "turning point" (either a maximum or a minimum), so we know we want the curve to have horizontal tangents at the two points. The magic formula for the "ramp" function is:

$ y(x) = y_1 + \frac{(x - x_1)^2 (3 x_2 - x_1 - 2x) (y_2 - y_1)}{(x_2 - x_1)^3}$

The idea here is much the same as in Ross Millikan's answer, but I'm using a diffent ramp function that's more closely related to Bezier curves.

You can easily confirm that $y(x_1) = y_1$, $y(x_2) = y_2$, $y'(x_1) = 0$, and $y'(x_2) = 0$.

In a sense, this is a Bezier curve. If we let $h = (x_2 - x_1)/3$, then the four control points of the curve are $(x_1,y_1)$, $(x_1 + h,y_1)$, $(x_2 - h,y_2)$, $(x_2,y_2)$. The middle two of these are the ones you were missing.