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);
}
Formula for angle between two Vectors The cosine of the angle between two vectors is equal to the sum of the product of the individual constituents of the two vectors, divided by the product of the magnitude of the two vectors. =| A | | B | cosθ.
The equations of the two planes in vector form are r.n1 = d1 and r.n2 = d2 and the equations of the two planes in the cartesian form are A1x + B1y + C1z + D1 = 0 and A2x + B2y + C2z + D2 = 0. Then, the formulas to find the angle between two planes are: cos θ = |(n1 .
Thus, the angle between the vectors a → × b → and b → × a → is 180º.
It's because the first method is correct, while the second method is incorrect.
You may notice that the arccosine function is sometimes written "acos" and sometimes written "cos-1". This is a quirk of mathematical notation: "cos-1" is really the arccosine and NOT the reciprocal of the cosine (which is the secant).
However, if you ever see "cos2", then that's the square of the cosine, and "cos3" is the cube of the cosine. The notation for trigonometric functions is weird this way. Most operators use superscripts to indicate repeated application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With