1

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.

Pendo826
  • 139

1 Answers1

1

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

Vector3 crossProduct = Vector3.Cross(rateOfSpin, rateOfSpin);

will give you $\text{crossProduct} = (0,0,0)$.

Then dotProduct and lengthOfDotProduct will also be zero. Then, this line of code

Vector3 magnusVector = crossProduct/lengthOfDotProduct;

will be calculating $0/0$, which will give you NaN.

By the way, NaN and null are two very different things.

bubba
  • 43,483
  • 3
  • 61
  • 122
  • What does NaN stand for ? I was told it was null today :( Im not really sure what the cross product is supposed to do in the formula as im just following it im supposed to get the cross product of RxVa and divide it by the length of the cross product :S – Pendo826 Mar 07 '14 at 23:27
  • You were misinformed. NaN stands for "Not a Number". It is a special "double" value that represents the result of various invalid numerical operations, like 0/0. Null is a pointer that has no value (in the sense that it is uninitialized and doesn't point to any real memory location). – bubba Mar 07 '14 at 23:34
  • Oh i see thanks for that information as today was the first time i seen "NaN" – Pendo826 Mar 07 '14 at 23:35
  • > im supposed to get the cross product of RxVa and divide it by the length of the cross product Well, that's not what your code is doing. You computed RxR, not RxVa. – bubba Mar 07 '14 at 23:36
  • Thanks at least i know now that its not casting problems :) – Pendo826 Mar 07 '14 at 23:37