Advertisement

Vector to degrees

Started by June 25, 2002 03:20 AM
4 comments, last by VanKurt 22 years, 7 months ago
Hi! I''ve got a (hopefully) simple question: How can I convert a unified 2D Vector into a single degree-value? e.g. (just estimated) 0,1 -> 0 1,1 -> 45 1,0 -> 90 1,-1 -> 135 0,-1 -> 180 ...... Do you have any ideas? Thanks!!!!!!!!!!!!!!!!!
inverse tan
Advertisement
use arctan(), which converts x/y values into degrees. This should be standard in your compiler''s math library.

------------------------------------------------
The wind shear alone from a pink golfball can take the head off a 90-pound midget from 300 yards.

-Six String Samurai
_________________________________________________________________________________The wind shear alone from a pink golfball can take the head off a 90-pound midget from 300 yards.-Six String Samurai
In C, atan2(x,y) works better than atan(x/y) : no singularities and it covers all four quadrants. Results are in radians not degrees.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
This might also help:

if v is your vector and & the angle from initial position

sin& = y/|v|
and
cos& = x/|v|

since your vector is a unit

sin& = y
cos& = x

Usually, however, there are ways to avoid trig if you are using vectors.


"Free advice is seldom cheap."
Whats the application ?
If you say what it is for, maybe we can help you avoid trig altogether.
~V'lionBugle4d

This topic is closed to new replies.

Advertisement