Length of a Spline

Started by
3 comments, last by jollyjeffers 22 years, 5 months ago
hi, I appreciate that this is probably quite a complicated topic, but any help I can get is really really appreciated. The Situation: I have a set of cars (well, dots) following a 2D track using waypoints. (one on each corner etc...), the waypoints are joined up using hermite splines (or catmull-rom splines). The Problem: The waypoints aren''t uniformly spaced out, and as they''re parametric equations, I just use (similiar to) a given 100 "steps" between each waypoint. Now the problem is that on the longer straights the cars wizz around, great. on the corners they slow down, because there''s more iterations over a smaller distance. But, sometimes it''s necessary to have a waypoint in the middle of a straight: so it appears on screen as if the car goes fast, slows down and goes fast again (or combinations thereof). What I want to do is to calculate (or approximate) how many iterations I should do, based upon the distance (on the spline) between the waypoints (100 for a large distance, 10 for a short distance)... Does anyone know how I could go about this? many thanks, Jack;

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Advertisement
Well, the arc length is the intergral from 0 to t of the magnitude of the derivative of the function. That would be viewing it as a vector function, i.e. r(t)=(x(t),y(t),z(t)). If you can derive that and solve the resulting equation for t then you can substitute that back into the original function. That is called reparameterizing the function in terms of the arc length, i.e. equal changes in the parameter generate points equal distance appart along the curve. You are seldom so lucky as to have that be practical. Instead you usually get an intergral that you can only evaluate numerically.

If you curve is reasonable behaved you can use the straight line distance between points. It sounds like that would be better than what you are doing now. You just calculate the straight line distance from where the car is now to where the car would be using your default parameter step. If the straight line distance is greater than the speed you cut the step in half and try again. If it is lower then you double it. You basically do a binary search for the right value. That could be time consuming so it might not be a bad idea to precalculate the points or if you are worried about space at least the default step size for a segment just to minimize the number of iterations.
Keys to success: Ability, ambition and opportunity.
thanks for the help - but I think thats a little over my head at the moment :o - I''m not quite upto Degree mathematics (I''m at the stage before it!)...

my spline is "reasonably well behaved" so I think I''ll approximate with the straight line distance calculation.

thanks again.
Jack;

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Also, you could try calculating the straight line distance, then split the line into 2 and calculate the straight line distance, then do it into 3 and calculate straight line distance. Then using those 3 values, approximate the curve and see where it would converge.... although, precalculation would be a lot better

Trying is the first step towards failure.
Trying is the first step towards failure.
That''s pretty much what I did yesterday

I calculate 3 points on the spline (+ start & finish) and made 4 lines between them, and then summated the lengths of these 4 lines... and used that as my approximation... which worked quite well...

Jack;

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

This topic is closed to new replies.

Advertisement