Does atan2 required normalized vectors? Which is better to use acos or atan for angles between vectors?
Asked Answered
A

1

5

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!

Aurelioaurelius answered 5/7, 2019 at 11:51 Comment(2)
atan2 does not require normalised vectorsPrudence
No, atan2() 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 use acos()" 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
S
8

No, atan2 does not require normalized vectors, and if your vectors are not already normalized you shouldn't pre-normalize them as that may slightly reduce precision. The function works correctly for any inputs other than (0,0).

You should never use acos for anything.

Spout answered 5/7, 2019 at 11:59 Comment(2)
Thankyou. atan2 certainly would be more useful in a number of situations for me due to not having to normalise ;)Aurelioaurelius
You may add that atan2 provides a result modulo 2-pi, on the contrary of acos or atan.Prudence

© 2022 - 2024 — McMap. All rights reserved.