• Advertisement

Archived

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

Angle from Positive X Axis?

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
Share on other sites

  • Advertisement