PDA

Click to See Complete Forum and Search --> : Removing Acos/arccos from logic


SLH
May 26th, 2007, 04:44 AM
In part of my program i need to determine whether an angle between 2 vector is smaller than a constant value. This works, and looks like this:DotProducts[0] = (float)Math.Acos(Vector2.Dot(Vector2.Normalize(PositionDifference[0]), Vector2.Normalize(Position[1] - Position[0])));
DotProducts[1] = (float)Math.Acos(Vector2.Dot(Vector2.Normalize(PositionDifference[1]), Vector2.Normalize(Position[0] - Position[1])));
if ((DotProducts[0] <= (0.3f)) || (DotProducts[1] <= (0.3f)))
However, i'm guessing Acos is pretty slow, and it would be nice if i could remove it from the logic. I initially thought i could pretty easily but i've not been successfull. I tried this, but the logic doesn't work for some reason...
DotProducts[0] = (float)(Vector2.Dot(Vector2.Normalize(PositionDifference[0]), Vector2.Normalize(Position[1] - Position[0])));
DotProducts[1] = (float)(Vector2.Dot(Vector2.Normalize(PositionDifference[1]), Vector2.Normalize(Position[0] - Position[1])));
if ((DotProducts[0] <= Math.Cos(0.3f)) || (DotProducts[1] <= Math.Cos(0.3f)))I thought that since i'm compareing 2 numbers, one of which has an Acos in it, i could just Cos both sides of the comparison to remove it, but is this not the case?