Jump to content

  • Log In with Google      Sign In   
  • Create Account

Charles B

Member Since 17 Jan 2002
Offline Last Active Oct 15 2006 04:38 PM

#3002893 Calculating the length of a Bezier curve...

Posted by Charles B on 12 April 2005 - 01:20 PM

The generic formula for a parametric curve length is

Sum[0,1]( sqrt((dx/dt)^2+(dy/dt)^2+(dz/dt)^2)*dt )

BTW, to "verify", for a classical function curve y=f(x), just replace t by x, discard z and you get Sum[xa,xb]( sqrt(1+(dy/dx)^2)*dx )

Since your Bezier spline is of degree 3, dx/dt is of degree 2. (dx/dt)^2 is of degree 4, etc ... All in all you end up with the integration of the square root of a degree 4 polynomial in t.

Then there should be enough litterature on the www for you concerning numerical or formal integration techniques. But this can easilly be solved formally :

Go there http://torte.cs.berkeley.edu:8010/tilu and you'll get the formal answer you need. Select Mathematica as language and type (indefinite integration : finding a primitive):


You'll get (control by differentiating the result, it's easy):

5 4 2 3
sqrt (1/5 a x + 1/4 b x + 1/2 d x + 1/3 c x + e x)

And in fact replace x by 1 since you just integrated between 0 and 1 and this makes 0 at 0.

length = sqrt(1/5a + 1/4b + 1/2d + 1/3c + e)

I hope you understood how to get a, b, c, d and e from your spline.

With a quick SSE or 3DNow sqrt or the "Carmack" sqrt, you can have both precision and speed. Google with Gamedev search engine to know more about quick sqrts.