catmull-rom length

Started by
16 comments, last by DonTzzy 10 years, 9 months ago

I understand some about catmull-rom, but I now need to understand how to get the total length of the spline. The only approach I have come up with is to take samples at regular intervals along the spline and add up each consecutive distance. This seems a bit time consuming and clunky. I would like to know if there is a math formula that can get this more accurately.....

Advertisement

The math formula for the length of a cubic is an integral that doesn't seem to be expressible in terms of common functions (at least Mathematica and I don't know how to do it), so you need a numerical method anyway. If your sum of distances is precise enough and fast enough for your purpose, just go with it, because it is simple.

It's simple and easy to understand, but it ultimately is only an approximation. Looking at http://en.wikipedia.org/wiki/Arc_length , I have come to the conclusion that, without some complicated math formula, the approximation (which is the only thing I could understand in the article) is the only way to go. This poses a problem because my splines are HUGE and therefore would have to have a lot of samples to get it really close. I would have to generate a table of angles and lengths with several variations. Each of these variations could in theory be scaled for and approximately matched up with each spline I generate in-game. Perhaps I could do these calculations on-the-fly, but with hundreds of ships all potentially moving at the same time, this might be too much......


It's simple and easy to understand, but it ultimately is only an approximation.

You shouldn't obsess about this. Virtually all the calculations we perform in a computer are only approximations. The art is in finding approximations that are precise enough and fast enough for what we are doing.

When you say that your splines are HUGE, what do you mean? Is it that they have MANY nodes?

No. It only has 5 total points to define each one. HUGE means they are physically large--each vector (point) can be very far away from the next. The biggest problem with this is when you try to move along the spline in very short time increments the math gets fuzzy and there is "gitter" from point to point. This is not going to be a problem because the camera is moving so fast and I have taken that into account (for now).....

So wait...

Are you trying to find the length of the spline? That is one set of calculations for arc length of an ellipse.

Or are you trying to make something move a constant linear velocity across a spline? That is a totally different problem. There are many good interpolation-based solutions for it.

What's the difference between a cubic spline and a catmull-rom? Arc length doesn't work that effectively because the spline sometimes shows as a parabola.

A cubic spline is a spline defined by a cubic polynomial. You've seen those, ax^3+bx^2+cx+d. The formula y=x^3 will draw a simple 2d cubic spline.

A cubic Hermite spline is a matrix representation of the cubic spline. Just like you can express rotations in terms of angles and also in terms of a matrix. Lots of types of curves can be expressed as cubic Hermite splines, but not all cubic Hermite splines can be represented with cubic polynomial equations. Instead of a simple polynomial it is a 4x4 matrix. You can multiply the 4x4 spline matrix against the control points and then by the distance along the spline with simple matrix multiply operations. They are really easy for mathematicians and speedy for programers.

A Catmull-Rom spline is a specific set of numbers for the cubic Hermite spline. It is one out of infinitely many potential cubic Hermite splines. Those specific numbers can be used to append splines continuously and their integrals are continuous (meaning it smoothly moves from one to the next).

Hopefully that clears up the relationships between them.

As for the arc length, there are two options. Some cubic Hermite splines can have their segments expressed as cubic polynomial, like the one at the top of this post. If you are able to convert it to such a form then simple integration will find the length; repeat for each segment and take their sum. If you cannot convert the cubic Hermite spline into a simple polynomial, it will remain an elliptic curve; that requires a numeric integration rather than symbolic integration. The best numeric integration approach to that problem is called Hermite integration. Charles Hermite explored a lot of this kind of math, so you've got Hermite functions, Hermite splines, Hermite integration, and a few others all named after him.



But again, do you need the actual computed length of a spline? Or are you actually trying to get an interpolation with approximately smooth linear velocity? Because the two are very different problems.

I'm not sure finding the length of a cubic is a simple integration.

The length of the curve f(x) = x3 is integral(sqrt(1 + (3x2)2)) = integral(sqrt(1 + 9x4)) which wolfram alpha tells me evaluates to (deep breath):

http://www.wolframalpha.com/input/?i=integral%28sqrt%281%2B9x^4%29%29

which also involves an elliptic integral of the first kind. (difficult I expect, and I have a degree in maths).

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
@frob: I am trying to get “smooth linear velocity”. Well, the ship will be speeding up/slowing down depending on its starting velocity….. I have a lot to look up with respect to cubic hermite…. Does anyone have a simple example of how to use it in C++? @Paradigm Shifter: Can you tell me what that means? Can you convert that into C++?????

This topic is closed to new replies.

Advertisement