Interpolate spline with constant speed

Started by
0 comments, last by Tristan85 10 years, 10 months ago

Hi guys,

As hinted at by the topic title, I'm currently trying to move an object along a parameterized curve with constant speed.
Following advice in several older forum posts, I'm using the numerical solution for reparameterization that's presented at page 8 of this paper.
This works great for the simplest case, in which there's only 1 segment.
But when calling GetCurveParameter(curve.length) for a curve with more than 1 segment, it will return a t-value which is much larger than 1 (my chosen tmax).
The solution is most likely described at page 11 ("Handling Multiple Contiguous Curves"), but I'm having trouble understanding the how and why of this approach. For example the comment that says


// We know that LSegment[i-1] <= s < LSegment. 

seems wrong to me, given that earlier code seems to fill the LSegment array with the length of each segment.

If anyone here could help me understand this in any way, I would be much obliged!

Thanks in advance,

Tristan

Advertisement

Hi guys,

Perhaps the problem is somewhere in my current implementation.

Every function in my spline class seems to work fine on it's one, except for the InterpolatePositionByDistance() function.

See below:


public Vector3 InterpolatePositionByDistance(float s)
{
   //Assertions.Assert((s >= 0.0f) && (s <= Length));


   const int n = 20;  // step size

   float t = 0;
   float h = length / n;
   for (int i = 0; i < n; ++i)
   {
       // The divisions here might be a problem if the divisors are
       // nearly zero.
       float k1 = h / InterpolateDerivative(t).magnitude;
       float k2 = h / InterpolateDerivative(t + k1/2).magnitude;
       float k3 = h / InterpolateDerivative(t + k2/2).magnitude;
       float k4 = h / InterpolateDerivative(t + k3).magnitude;


       t += (k1 + 2 * (k2 + k3) + k4) / 6;
   }


   Debug.Log(t); // when s == length, and #segments > 1, t > 1 (for example t == 4.12334)


   return InterpolatePosition(t);
}
 

For full source code, check the Spline class in attachment.

Kind regards,

Tristan

This topic is closed to new replies.

Advertisement