Is there any Bezier-like spline that is explicit function?

55 Views Asked by At

What I actually need is to allow users to generate 1D data array (actually, MIDI CC values) through some control points on GUI. The Bezier curves has a very good property that the tangent on end points are directly controlled by the "control" points, that is easier to be used by end user.

However, Bezier curves on 2D space are defined in implicit function like $P = QuadraticBezier(P0,P1,P2,r)$ or $P = CubicBezier(P0,P1,P2,P3,r)$. I tried to unfold the quadratic Bezier function into explicit style $y = ExplicitQuadraticBezier(P0, P1, P2,x)$, and found that for each calculation on an input $x$, you actually need to recalculate the root of an quadratic equation:

float bezier_interpo( point p0, point p1, point p2, float x)
{
    // calculate implicit function input r from x
    // by solve equation a*r^2 + b*r + c = 0
    float a = p0.x - 2 * p1.x + p2.x;
    float b = 2 * p1.x - p0.x;
    float c = p0.x - x;
    float r = ( -b + sqrt( b * b - 4 * a * c ) ) / ( 2 * a );

    // interpolate output y from r
    float one_minus_r = 1 - r;
    float ym0 = p0.y * one_minus_r + p1.y * r;
    float ym1 = p1.y * one_minus_r + p2.y * r;
    float y = ym0 * one_minus_r + ym1 * r;
    return y;
}

This procedure contains many times of float-point multiply and one time of square root, so it is quite expensive in CPU time when you are going to calculate a series of 1D data array. And I believe it would be more expensive for the cubic one.

So my question is: is there any other curve interpolation function, that still has explicit control on the tangent direction on end point, but is much more simple for calculation to spawn an 1D array?

1

There are 1 best solutions below

0
On BEST ANSWER

Try the function $$ y(x) = (2x^3 - 3x^2 + 1)y_0 + (x^3 - 2x^2 + x)s_0 + (3x^2 - 2x^3)y_1 + (x^3 - x^2)s_1$$ Its start and end values are $y(0) = y_0$ and $y(1)=y_1$. It’s start and end slopes are $y’(0) = s_0$ and $y’(1)=s_1$. You can let your users adjust these four quantities. This thing is called a Hermite cubic interpolant.