Sign in to follow this  

Convert from cartesian to polar

This topic is 4825 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

I guess I should have looked elsewhere first, but for the benefit of others, here's what I found:

Polar from Cartesian:

R = Sqrt(x2 + y2);
Theta = ArcTan(Y / X);

Cartesian From Polar:

X = R * cos(Theta)
Y = R * sin(Theta)

Any comments on optimizing for speed? Ie, can that atan() be changed?

[edited by grhodes_at_work to put the "2"'s in superscripts for the R equation]

[Edited by - grhodes_at_work on October 1, 2004 4:23:27 PM]

Share this post


Link to post
Share on other sites
If you're using c/c++, Make sure you use atan2() and not atan().
atan() returns an angle in the interval 0 <= theta <= pi/2. You probably want an angle in the interval 0 <= theta <= 2*pi. Use atan2() to get that. If you're using a programming language like Visual Basic yiu'll have to transform the angle yourself based on the signs of x and y.

If your X and Y are always greater than 0 you can ignore this post ;)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Pre-calculated look up table would probably give you enough accuracy

Share this post


Link to post
Share on other sites
Quote:
Original post by griminventions
Hmm, the Visual C++ help says that atan2 returns the arctangent of y/x in the range –ð to ð radians.


Yep. That's your correct angle. If you want a range 0 to PI, then simply add 2PI when the result of atan2 is negative and leave it alone when zero or positive. You already have the equation for R in your second post!

Share this post


Link to post
Share on other sites

This topic is 4825 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this