Curve distance equation

Blitz3D Forums/Blitz3D Programming/Curve distance equation

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Using the information you have supplied above I think you are saying you have this situation:

You know the coordinates of both point A, point B and the angle that the curve makes with the horizontal at point A (in other words the gradient at A).

That is 3 pieces of information. If you are using a cubic spline you need one more piece of information, the angle the curve makes at point B as well. But you have not specified that so I assume you have only 3 pieces of information which means we can use a quadratic rather than a cubic spline.

So we set up the following:

y = y (x) - ie our y coordinate is some function of x.

we know the following:

Coordinates of A we shall write as (0,A) - ie x=0, y=A
Coordinates of B we shall write as (L,B) - ie X=L, y=B
Angle curve makes at A is Theta => Gradient at this point = Tan(Theta).

So:

Y(0)=A
Y(L)=B
Y'(0)=Tan(Theta) - which we will just call "C"
so Y'(0)=C

then, since we have 3 points and are using a quadratic to fit the curve we do this:

Y(x) = ax^2+bx+c (a,b,c not the same as A,B,C)

Y(0)=A = a*0^2 + b*0 + c, therefore c=A
Y(L)=B = a*L^2 + b*L + A
Y'(0) = C = b, therefore b=C

then solving for "a" we get this:

a = (B-CL-A)/(L^2)

Okay so our equation for your curve that passes through the points and with the initial angle as specified is:

Y(x)=((B-CL-A)/(L^2))*x^2 + Cx + A

Now use this equation for Y and calculate the length of the line using the method I outlined above.

I will write it anyway:

Okay - you now want to find the length of the curve I specified:

Length = Integrate Between X=0 and X=L the following function:

(Square Root of (1 + Y'(X)^2)) dX

You could do this analytically but it would probably be just as easy and not too inaccurate to do so with a numerical technique ranging from something simple like the midpoint method to something more complex like the Runge Kutta method