Angle between two 2d vectors, diff between two methods?
- by Sean Ochoa
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 = a.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 = a.Len*b.Len;
var divOperation = dotProd/lenProd;
return (1/Math.Cos(divOperation)) * (180.0 / Math.PI);
}