Hey i didnt know whether to come here or stack overflow as i have a programming problem for a mathematics equation. Im getting a null value back when calculating the magnus force(spin). Im using XNA so that i can represent the data graphically and i have a few debugs to show the values. The value that this function is returning is NaN. Here is what i have got:
private Vector3 getMagnusForce()
{
float VapparentLength = (float)Math.Sqrt((double)Vector3.Dot(Vapparent,Vapparent));
float radiusSquared = (float)(Math.Pow(radius, 2));
float VapparentSquared = (float)(Math.Pow(VapparentLength, 2));
//Find omega(Angular Velocity) by getting the length of R(Rate of Spin).
float omega = (float)Math.Sqrt((double)Vector3.Dot(rateOfSpin,rateOfSpin));
//Find cl by multiplying radius times omega then dividing it by the VapparentLength.
float cl = (float)radius * omega / VapparentLength;
Vector3 crossProduct = Vector3.Cross(rateOfSpin, rateOfSpin);
float dotProduct = Vector3.Dot(crossProduct, crossProduct);
float lengthOfDotProduct = (float)Math.Sqrt(dotProduct);
Vector3 magnusVector = crossProduct/lengthOfDotProduct;
float magnusPI = (float)Math.PI / 2 ;
float magnusEffect = magnusPI *density * radiusSquared * cl * VapparentSquared;
this.forceOfMagnusEffect = magnusEffect * magnusVector;//forceOfMagnus is a Vector3
return forceOfMagnusEffect;
}
The formula that i am using is PI/2 * row(density) * r^2(radius of a sphere squared) * CL * the apparent velocity squared * by the cross procduct of R*Va / the length of the cross product of R*Va.
I hope i explained it correctly if not dont hesitate to ask as im happy to give more information.
I don't understand the overall picture, but here are some possible sources of problems:
The cross product of a vector with itself is always the zero vector. So this line of code
will give you $\text{crossProduct} = (0,0,0)$.
Then dotProduct and lengthOfDotProduct will also be zero. Then, this line of code
will be calculating $0/0$, which will give you NaN.
By the way, NaN and null are two very different things.