This question already has an answer here:

Lets say I'm using atan2 to get the angle between two vectors.

atan2 gives a value in radians. I convert it to degrees using a built in function in Java. This gives me a value between 0 and 180 degrees or between 0 and -180 (the nature of atan2).

Is there a way to convert the value received with this function (after it's been converted to degrees), to the standard 360-degree-system, without changing the angle - only the way it's written? It would make it easier for me to work with.



marked as duplicate by Tim Holt, msell, MichaelHouse Feb 1 '14 at 7:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ Four atan2 questions in a row; you might want to head to chat or a similar discussion site and figure out what you don't understand about this. \$\endgroup\$ – MichaelHouse Feb 1 '14 at 7:12
  • \$\begingroup\$ Just do this -> angle = (angle + 720) % 360; \$\endgroup\$ – wolfdawn Feb 1 '14 at 9:08

You can multiply the result by (180/pi) to convert the magnitude to degrees. If it's negative then you would have to add 360 to it afterwards (assuming you want a range of 0 to 360.)

For example, -pi/2 becomes -90 after the multiplication, and adding that to 360 results in 270, which gives you the amount of degrees to rotate counter-clockwise from the positive x-direction to reach the point (which is what you're looking for I think.)

  • \$\begingroup\$ Thanks. Please see my edit. If I converted the value in radians given by atan2, to degrees, and only then I want to convert that value (in degrees), to the 360-degree-system. What can I do? \$\endgroup\$ – user3150201 Feb 1 '14 at 2:08
  • 1
    \$\begingroup\$ As I said in my answer, you want to add 360 to your value if it's negative. Otherwise (i.e. if it's positive) there is nothing further to do. \$\endgroup\$ – Ryan Feb 1 '14 at 2:12
  • \$\begingroup\$ If this doesn't answer your question, can you please clarify with an example of the functionality you're looking for (i.e. input/output) because I'm not sure I understand otherwise. \$\endgroup\$ – Ryan Feb 1 '14 at 2:28

You can add 180 to your converted result to give a range of 0 to 360.

  • 1
    \$\begingroup\$ Most likely not what you want, as it changes the origin of angles - 0 degrees would be at the negative x axis instead of the positive x axis. \$\endgroup\$ – Nathan Reed Feb 1 '14 at 2:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.