Advertisement

Catmull-Rom B-Splines in OpenGL

Started by December 16, 2002 01:54 PM
9 comments, last by NeXius 22 years, 1 month ago
Hi. I''m trying to draw Catmull-Rom B-Splines using the OpenGL evaluator functions, but since these functions use only a bezier basis, I have to convert the control points I generate for a catmull-rom b-spline into bezier... How would I do this??
MSN: stupidbackup@hotmail.com (not actual e-mail)ICQ: 26469254(my site)
As far as I know they are differant subsets of all cubic space curves. I suppose it is possible that they are the same subset, but it seems unlikely. Proving whether they are the same subset or not is a bit beyond me.

You can calculate the tangent vector to the catmull-rom spline at the points corresponding to 0 and 1. That at least gives you the direction the control points need to be in. It seems like the curvature would provide you a means to determine how far in that direction the control points should be.

Alternatively it seems like you could use linear algebra to find the best fit bezier. I think you can straight-up solve it with just two points. You have six unknowns and two points basically gives you six equations, i.e. three components times two points. That isn''t going to be very close except by pure blind luck. It seems like ten or eleven would be reasonably close though. I''ve never tried it so there may be some obstical to using best fit to find a bezier specifically rather than just a cubic.
Keys to success: Ability, ambition and opportunity.
Advertisement
Thanks for the reply

But is that the only way? I thought there would be an easier solution...

If that is the case, I might as well just write my own culling/LOD code instead of taking advantage of the evaluator functions
MSN: stupidbackup@hotmail.com (not actual e-mail)ICQ: 26469254(my site)
Sorry, not that I can think of, but my knowledge is pretty limited. I think I would first try the simplest approach which would be to approximate the tangent, i.e. (r(h)-r(0))/h and (r(1-h)-r(1))/h. Keep halving h until two successive vectors have reasonably close directions and magnitudes. Then plot a catmull-rom with an interface that lets you overlay a bezier with the control points multiplies of the tangent vectors. Plot all the control points. After you do a few you may find there is a simple approximation that is reasonably close. Particularly you may find that all the catmull-roms you used do not fall into a special case where you get a totally screwed up result. Just intuitively it seems a bezier could produce a more extreme curve than a catmull-rom could. Particularly it seems more difficult to produce a loop in the segment of the catmull-rom that you are drawing. You can, but it seems like the requirements to do so are more extreme.
Keys to success: Ability, ambition and opportunity.
They are exactly the same set of curves (cubic curves).
After a quick internet search (http://www.mvps.org/directx/articles/catmull/), the Catmull Rom Matrix is

1/2 *
0 2 0 0
-1 0 1 0
2 -5 4 -1
-1 3 -3 1

And the bezier matrix is ( I think ...)

1 -3 3 -1
-3 6 -3 0
3 -3 0 0
-1 0 0 0

Thus to convert from catmull-rom to bezier, you can invert one matrix and multiply by the other.


"Math is hard" -Barbie
"Math is hard" -Barbie
How do you arrive at them being the same set? They are subsets of the same set, i.e. cubics. Clearly the set of all catmull-roms is not equal to the set of all cubics since you can only get 12 of the infinite number of cubics that pass through four points. The bezier is a bit harder since it only passes through two points and there are an infinite number of beziers passing through those two points. I''m not saying you are wrong, but rather just asking how you arrive at that conclusion.
Keys to success: Ability, ambition and opportunity.
Advertisement
I don''t see how it''s "clear" that catmull rom splines are not the whole set of cubics. Write out the formula for a catmull rom spline with arbitrary control points (P1 P2 P3 P4). Write out the formula for a general cubic curve (Ax^3 + Bx^2 + Cx + D). Put an equals sign between them, and try to solve for P1..P4. It will come down to a matrix inversion, and the matrix will be invertible. Thus you can rewrite a general cubic as a catmull rom spline.

"Math is hard" -Barbie
"Math is hard" -Barbie
Ok, I see one mistake I made. That being that there are only 12 catmull-roms going through a set of four points as the control points, but there are other catmull-roms going through those points when they are not the control points.

Now I have a bit of a problem with the idea that you can just stick equals between anything and find a non-empty solution. Clearly there is a general form for any catmull-rom. It is a cubic. It still isn''t clear that there is a catmull-rom form for any cubic. Certainly a matrix inversion and multiplication is a bit short of actually finding it if it exists. The catmull-rom equation is starts a scalar times a matrix times a sum of vectors as near as I can tell. I might be wrong there, but that seems like a matrix times a vector of vectors is the matrix times the sum of those vectors. You also have a vector in there representing the parameters and those are in two differant forms. If there is a solution it seems there must be an infinite number of solutions, but it isn''t clear there is a solution.
Keys to success: Ability, ambition and opportunity.
quote:
Original post by LilBudyWizer It still isn''t clear that there is a catmull-rom form for any cubic. Certainly a matrix inversion and multiplication is a bit short of actually finding it if it exists.


Actually, it will find the unique solution, and it does exist, and there is only one. That is exactly what this technique does. The reason it works is because both the matrices you are working with are invertible.

"Math is hard" -Barbie
"Math is hard" -Barbie
The equations are:


  // Catmull-Rom//[ -P0 + 3*P1 - 3*P2 + P3]T * [t^3]//[2*P0 - 5*P1 + 4*P2 - P3]    [t^2]//[ -P0          + P2     ]    [t]//[       2*P1            ]    [1]//General cubic//[A]T * [t^3]//    [t^2]<br></font><br><font color="gray">//[C]    [t]<br></font><br><font color="gray">//[D]    [1]<br></font><br>  </pre></DIV><!–ENDSCRIPT–><br><br>Admittedly you have to use your imagination a bit to make that into a 3x4 times a 4x1. Clearly given P0, P1, P2 and P3 I can find A, B, C and D. That doesn't require any inversion. Given A, B, C and D though there seems a few difficulties in find P0, P1, P2 and P3. Specifically you have 12 unknowns and &#111;nly four equations.<br><br>Now concievably there is a general solution providing the conditions P0, P1, P2 and P3 must meet. It isn't clear that those conditions can always be met for any choice in vectors A, B, C and D.<br><br><SPAN CLASS=editedby>[edited by - LilBudyWizer &#111;n December 24, 2002 11:14:27 AM]</SPAN>    
Keys to success: Ability, ambition and opportunity.

This topic is closed to new replies.

Advertisement