• the spline is a function p(u) where u is the parameter/time value
• let's define a function f(u) that returns the squared distance between the ray and the spline
• let's define a function f(u) that returns the squared distance between the ray and the spline
remember how to find out where a function is 0?
this is called root solving, where you usually pull out some formulas for your quadratic equations to find the roots
however, this function is way more complex than a simple quadratic polynomial :c
so, what do we do?
this is called root solving, where you usually pull out some formulas for your quadratic equations to find the roots
however, this function is way more complex than a simple quadratic polynomial :c
so, what do we do?
we use a numeric method!
one such method is the newton-rhapson method, where you start with an initial guess, and iteratively refine the search several times
it's actually pretty simple! given an initial guess of x, the new value of x is:
x - f(x)/f'(x)
one such method is the newton-rhapson method, where you start with an initial guess, and iteratively refine the search several times
it's actually pretty simple! given an initial guess of x, the new value of x is:
x - f(x)/f'(x)
now remember, we don't want to find the roots of the distance function (where distance is 0), but rather the root of the *derivative* of the distance function (where distance is at a local extrema)
so, all we need is a few iterations of this:
u = u - f'(u)/f''(u)
so, all we need is a few iterations of this:
u = u - f'(u)/f''(u)
anyway that's it! the cool thing about this method is that it actually converges very quickly, the .gif up top has 4 initial guesses per curve segment, and just 4 newton-rhapson iterations 🎉
here's the distance function and its derivative visualized!
Loading suggestions...