I have been using this function to generate points on a curve using the Bezier quadratic equation:
D3DXVECTOR3 BezierQuadratic(D3DXVECTOR3 InputA,D3DXVECTOR3 InputB,D3DXVECTOR3 InputC,float T)
{
//Explaination:
//http://www.gamedev.net/reference/programming/features/curvessurfaces/
D3DXVECTOR3 Solution;
float A = 1-T;
float B = T;
float A_2 = A*A;
float AB2 = A*B*2;
float B_2 = B*B;
Solution.x = InputA.x*A_2 + InputB.x*AB2 + InputC.x*B_2;
Solution.y = InputA.y*A_2 + InputB.y*AB2 + InputC.y*B_2;
Solution.z = InputA.z*A_2 + InputB.z*AB2 + InputC.z*B_2;
return Solution;
}
It seems to work nicely =). But now I need to find the length of this same curve:
long double LengthOfBezierQuadratic(D3DXVECTOR3 InputA,D3DXVECTOR3 InputB,D3DXVECTOR3 InputC)
{
//http://tutorial.math.lamar.edu/Classes/CalcII/ParaArcLength.aspx
/*
x(T) =(p1.x)A^2+(p2.x)2AB+(p3.x)B^2
A=1-T
B=T
x(T) = (p1.x)(1-T)^2
+ (p2.x)(1-T)(T)
+ (p3.x)(T)^2
x(T) = (p1.x)(1-T)*(1-T)
+ (p2.x)(T-T^2)
+ (p3.x)(T^2)
x(T) = (p1.x)(1-2T+T^2)
+ (p2.x)(T-T^2)
+ (p3.x)(T^2)
dx/dt = -2T(p2.x)+(p2.x)+2(P1.x)(T-1)+2(p3.x)T
Length = integrate(0,1){ sqrt( (dx/dt)^2 +
(dy/dt)^2 +
(dz/dt)^2 )
*/
}
Now the formula is starting to get a bit long:
http://www.algebrahelp.com/calculators/equation/simplifying/calc.do?equation=%28-2TB%2BB%2B2A%28T-1%29%2B2CT%29%28-2TB%2BB%2B2A%28T-1%29%2B2CT%29%3DP
A = p1.x;
B = p2.x;
C = p3.x;
(dx/dt)^2= -4AB +
12ABT +
-8ABTT +
-8ACT +
8ACTT +
4AA +
-8AAT +
4AATT +
4BCT +
-8BCTT +
BB +
-4BBT +
4BBTT +
4CCTT ;
A = p1.y;
B = p2.y;
C = p3.y;
(dy/dt)^2= -4AB +
12ABT +
-8ABTT +
-8ACT +
8ACTT +
4AA +
-8AAT +
4AATT +
4BCT +
-8BCTT +
BB +
-4BBT +
4BBTT +
4CCTT ;
A = p1.z;
B = p2.z;
C = p3.z;
(dz/dt)^2= -4AB +
12ABT +
-8ABTT +
-8ACT +
8ACTT +
4AA +
-8AAT +
4AATT +
4BCT +
-8BCTT +
BB +
-4BBT +
4BBTT +
4CCTT ;
Not to mention the integral of the square root of all this... Am i going about this wrong? Is there a simpler way to calculate the length of this curve? I will not be firing this function very much but it seems like it might start to eat up some cpu time.
Thank you guys in advance :) all help is greatly appreciated.
edit: im still working on it:
the antiderivative of one of the (dx/dt)^2 sections is:
(-2TB+B+2A(T-1)+2Cx)^3/6(A-B+C)
[Edited by - jchmack on October 26, 2009 3:08:27 AM]