How to interpret situations where Math.Acos() reports invalid input?

Posted by Sean Ochoa on Stack Overflow See other posts from Stack Overflow or by Sean Ochoa
Published on 2010-04-19T00:02:37Z Indexed on 2010/04/19 0:13 UTC
Read the original article Hit count: 185

Filed under:
|
|
|
|

Hey all. I'm computing the angle between two vectors, and sometimes Math.Acos() returns NaN when it's input is out of bounds (-1 > input && input > 1) for a cosine. What does that mean, exactly? Would someone be able to explain what's happening? Any help is appreciated!

Here's me method:

 public double AngleBetween(vector b)
    {
        var dotProd = this.Dot(b);
        var lenProd = this.Len*b.Len;
        var divOperation = dotProd/lenProd;

        //  http://msdn.microsoft.com/en-us/library/system.math.acos.aspx
        return Math.Acos(divOperation) * (180.0 / Math.PI);
    }

© Stack Overflow or respective owner

Related posts about vector

Related posts about c#