Applying Newton-Raphson method for Bézier curve

317 Views Asked by At

I would like to sort out why in the most browsers, part of algorithm doesn't correspond to Newton-Raphson method.

Ok, take a look at this opensource code This code calculates y's coordinate (time easing function)

Part about I say, it is:

for (t2 = x, i = 0; i < 8; i++) {
    x2 = sampleCurveX(t2) - x;
    if (fabs (x2) < epsilon)
        return t2;
    d2 = sampleCurveDerivativeX(t2);
    if (fabs(d2) < 1e-6)
        break;
    t2 = t2 - x2 / d2;
}

Again look at the follow string: x2 = sampleCurveX(t2) - x; it will be used in the next formula as the f(xn):

enter image description here

But there is the problem and my confusion. I don't understand for why we do need - x2 = sampleCurveX(t2) - x; I mean -x because it is not pure function of bezier and it doesn't correspond to upper formula of Newton-Raphson

P.S If you did not understand something, let me know, I'll give requirely extra information

1

There are 1 best solutions below

1
On

You want to solve $x=C(t)$ for $t$, $C$ standing for the curve component. Thus your function is $f(t)=C(t)-x$ with $f'(t)=C'(t)$, as $x$ is a constant in this context.

The initial value $t=x$ could be problematic, in general there is no direct relation between domain and range. I would use a secant root or some value obtained from a finer-grained reverse interpolation.

Reading the code, the Bezier curve is normalized in that module, both $x$ and $y$ component of the curve map the interval $[0,1]$ to itself. So taking $t=x$ as initial value is valid and corresponds to the mentioned secant root.