is there a good (and fast) spline-library around with sourcecode? every splinelib I find is missing the one or other thing like making splines speed-constant or good documentation.. any ideas?
good spline-library
This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.
-
-
What do you mean making splines "speed constant" ?Mr.Mike
Author, Programmer, Brewer, Patriot -
I mean traveling the spline with a constant speed... on normal splines, if you increment the "time" with a constant value, you end up with variable speed while traveling along the spline (best example for constant speed: a train running on a track-spline).
the best description I've found to solve the problem is to subdivide the spline in 1000 line-segments, calculate the length of the different linesegments and calculate a bezier to adjust for different traveled lengths.. (the reply from nils pipenbrink here: devmaster.net/forums/archive/index.php/t-3943.html ) I'm coding that right now...
In game programming gems 4 is an article, too, but the splines used there aren't as flexible as I wish (can't specifiy a tangent per node). -
I see what you are saying - but wouldn't it be much simpler to use spline nodes as nav points, and control the speed of progress completely independantly from those nav points?Mr.Mike
Author, Programmer, Brewer, Patriot -
okay, but I need a way to measure how much I've traveled along the spline to walk with a constant speed. the acceleration between two nodes isn't constant, I think the correct mathematically term for what I need is C^2 (C²). the splines in GPG#4 are C2 (or acceleration constant), but too smooth for my needs.
The post was edited 1 time, last by questor/fused ().
-
If you need that kind of accuracy - check out this paper:
cs.uiowa.edu/~kearney/pubs/CurvesAndSurfacesArcLength.pdfMr.Mike
Author, Programmer, Brewer, Patriot -
I've implemented the idea from edeltorus and here is the working sourcecode. I've used a gpl-math-library, but that can be recoded if gpl is not working for someone.
unseen-academy.de/timeconstSpline.html
pro's of this method: only some additional floats per segment (and not 1000 or something like that) and an additional interpolation per calculation of a point. hope thats helpful for someone out there...
cheers
questor
edit: the math-library is NOT gpl, but public domain...The post was edited 1 time, last by questor/fused ().
-
Questor, it sounds like you are seeking a parametric representation of either a hermite or bezier spline. You can have constant travel along this spline by manipulating a t value between t=0 (start) to t=1 (end)
This code is easy enough to write yourself. Here's my breakdown of it...
//Cubic Hermite Spline...
//The following solution came from the notes of Professor Baoquan Chen at MIT
//The spline gets created by connecting curves with the same slope at the endpoints
//Correction on the derived calculation of a and b coefficients made by Kain Shin
//f(t) = at^3 + bt^2 + ct + d, 0<=t<=1;
//By definition of spline, we deduce the following:
//f(0) = d
//f(1) = a+b+c+d
//f'(0) = c
//f'(1) = 3a + 2b + c
//Since we have four unknowns and four equations, we solve this system
//to obtain...
//a = 2f(0) - 2f(1) + f'(0) + f'(1)
//b = 3f(1) -3f(0) - 2f'(0) - f'(1)
//c = f'(0)
//d = f(0)
f(0) is your start point, when t=0
f(1) is your endpoint, when t=1
f'(0) is a tangent vector to the start point whose magnitude governs the strength of the initial curve. Think of this as initial inertial velocity
f'(1) is a tangent vector to the end point whose magnitude governs the strength of the ending curve, think of this as final inertial velocity
In the case of a 3D vector with xyz, you would basically be calculating x,y,and z independently (as your start/end) to get the overall curve you want.
Traveling along the spline at a constant delta-t should give you constant displacement.
If you prefer to use control points instead of velocities (similar to the curve tool in an artist program), then you can use a Bezier spline.The post was edited 1 time, last by Kain ().
-
Hi Kain,
thanks for your idea, but after thinking a little bit about your solution I don't think that it works.
Let's say we have two straight lines (splines which results in straight lines) with a slope of 1 and a slope of 2 both starting at 0,0. the length between t=0 and t=1 is on the first line sqrt(1*1+1*1) = 1.4 and on the second line sqrt(1*1+2*2) = 2.2. so with const t you do NOT get const length...
what I need is a arc-length-parametrized version of splines, but that's not easy to calculate -
Sorry, fused. I misunderstood the question. I thought you meant that things traveling along the spline would reach the endpoint at the same time.
I'll be back.
-
Share
- Facebook 0
- Twitter 0
- Google Plus 0
- Reddit 0