When calculating the angle between two vectors, I have traditionally used acos, but this requires the two vectors to be normalised. atan2 can be used to accomplish the same (specifically atan2(b.y_, b.x_) - atan2(a.y_, a.x_)
), does this require normalised vectors?
If atan2 doesn't require normalised vectors, would this be better to use since normalisation can be costly and 'more' error prone since it requires a sqrt operation?
Then I read that atan2 itself can be more costly than acos, but more accurate? And then I also read other interwebs suggesting the opposite :( lots of conflicting information, unsure what the deal is with using acos or atan for calculating the angle between two vectors.
Which is recommeneded? and what are the benefits/issues for each usage?
Any help would be appreciated, thanks!
atan2
does not require normalised vectors – Prudenceatan2()
does not required any scaling/normalising of inputs, as long as at least one argument is non-zero. Recommended usage depends on how the input values are supplied. Simple minded advice like "never useacos()
" is simply dumb - the skill is picking an appropriate option based on how input data is supplied/calculated, and the form of output required. Sometimes more than one alternative may be appropriate. – Hemitrope