angles between two vectors

Started by
11 comments, last by apanjocko 20 years, 6 months ago
it works on all of them, just depends on how many dimensions you use. The code that I use has 4 dimensions (yes, that''s x,y,z and that other one w).

but the descrepency that you are getting will still be there, but less unless you use atan2

_angleY = (float) Math.Atan( ( -_terrainNormal.Y + tankNormal.Y ) / tankNormal.Z );

to
_angleY = (float) Math.Atan2( ( -_terrainNormal.Y + tankNormal.Y ) , tankNormal.Z );

should do it.

bascially, the atan2 versions are alot more accurate than atan. It will provide the best accuracy.

when using floating point, atan/acos/asin is accurate to 8 sig figures (when about 1 or 2 degrees off) and atan2 is accurate to its full 20 sig figures.

Fiddle with it
Beer - the love catalystgood ol' homepage
Advertisement
thanks,
yeah i got it working i remember but it wasn''t that easy, just converting it strictly like that over atan2 yielded really strange results... had to change some signs here and there.

but what i meant was Optikal''s solution is less than adequate in this case. I will get an angle that is of no use to me whatsoever.

thanks for all help
no problem
Beer - the love catalystgood ol' homepage

This topic is closed to new replies.

Advertisement