#### Archived

This topic is now archived and is closed to further replies.

# Angle from Positive X Axis?

This topic is 5371 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Does anyone know how i can get the angle from the positive x-axis if i have the x and y coords? i tried tan-1 but it''s only if for the first 180 then the angle resets to 0. i need it to do the whole 360.

##### Share on other sites
In fact the angle always IS <= 180° as long as you don´t add an orientation to the angle like "it should be counter-clockwise from the first vector to the 2nd vector". If you want that just try case branching.

##### Share on other sites
quote:
If you want that just try case branching.

if ((0 == x) && (y > 0)) {    angle = 90;}else if ((0 == x) && (y < 0)) {    angle = 270;}else {    angle = 57.29577950 * atan(y/x);    if (y < 0) angle += 360;}

Edit: Assuming C. Adapt as necessary.

[edited by - Geoff the Medio on October 6, 2003 6:25:06 PM]

##### Share on other sites
oh man! thanks, sorry that was my studpiest question ever

• 17
• 11
• 14
• 9
• 49
• ### Forum Statistics

• Total Topics
631393
• Total Posts
2999763
×