C# - Angle between two 2d vectors, diff between two methods?

Posted by Sean Ochoa on Stack Overflow See other posts from Stack Overflow or by Sean Ochoa
Published on 2010-04-18T23:48:22Z Indexed on 2010/04/18 23:53 UTC
Read the original article Hit count: 378

Filed under:
|
|

Hey all. I've got this code snippet, and I'm wondering why the results of the first method differ from the results of the second method, given the same input?

public double AngleBetween_1(vector a, vector b) {
  var dotProd = a.Dot(b);
  var lenProd = Len*b.Len;
  var divOperation = dotProd/lenProd;
  return Math.Acos(divOperation) * (180.0 / Math.PI);
}

public double AngleBetween_2(vector a, vector b) {
  var dotProd = a.Dot(b);
  var lenProd = Len*b.Len;
  var divOperation = dotProd/lenProd;
  return (1/Math.Cos(divOperation)) * (180.0 / Math.PI);
}

© Stack Overflow or respective owner

Related posts about trigonometry

Related posts about vector