How to Convert Rectangular to Polar in Python: atan2, Degrees and Radians
Convert rectangular to polar in Python with math.hypot and math.atan2. Get r and theta in degrees and radians, with a complete function and worked examples.
To convert rectangular to polar in Python, use math.hypot(x, y) for the radius and math.atan2(y, x) for the angle. The two lines are r = math.hypot(x, y) and theta = math.atan2(y, x). The radius is the straight line distance from the origin, and the angle is measured counterclockwise from the positive x axis, in radians. Use math.degrees(theta) when you want the angle in degrees.

You can check any answer instantly with our interactive rectangular to polar converter or learn the math behind it in our rectangular to polar formula guide.
The Two Core Formulas in Python
The conversion uses the same two formulas you use by hand, written in Python form.
In Python, math.hypot(x, y) computes the square root of in a way that stays accurate for very large and very small numbers. math.atan2(y, x) takes the y value first and the x value second, and it returns the correct angle for all four quadrants, in radians, from to .
import math
r = math.hypot(x, y)
theta_rad = math.atan2(y, x)
theta_deg = math.degrees(theta_rad)
Do not use math.atan(y / x) for this job. It cannot tell Quadrant I from Quadrant III, or Quadrant II from Quadrant IV, because it loses the sign of x and y when you divide them. It also fails when x is zero. math.atan2 keeps both signs, so it gives the right quadrant every time.
Complete Function: rect_to_polar(x, y)
This function returns the radius, the angle in radians, and the angle in degrees, all in one call.
import math
def rect_to_polar(x, y):
"""Convert rectangular coordinates (x, y) to polar coordinates.
Returns (r, theta_rad, theta_deg).
Theta is in the range -pi to pi radians, or -180 to 180 degrees.
The origin (0, 0) returns r = 0 and theta = 0 by convention,
because the angle at the origin is mathematically undefined.
"""
r = math.hypot(x, y)
theta_rad = math.atan2(y, x)
theta_deg = math.degrees(theta_rad)
return r, theta_rad, theta_deg
print(rect_to_polar(3, 4))
# (5.0, 0.9272952180016122, 53.13010235415598)
print(rect_to_polar(-5, 12))
# (13.0, 1.965587446494658, 112.61986494804043)
If you want the angle in the range 0 to 360 degrees instead of -180 to 180 degrees, add 360 to any negative degree value. For example, -126.87 degrees becomes 233.13 degrees. Do the same in radians by adding to a negative radian value.
def rect_to_polar_360(x, y):
r, theta_rad, theta_deg = rect_to_polar(x, y)
if theta_deg < 0:
theta_deg += 360
return r, theta_deg
print(rect_to_polar_360(-3, -4))
# (5.0, 233.13010235415598)
Worked Examples, Checked in Python
Every answer below was run in Python, so the radius, radians and degrees agree with each other.
Example 1: (3, 4), First Quadrant
rect_to_polar(3, 4)
# (5.0, 0.9272952180016122, 53.13010235415598)
- Radius:
- Angle: radians degrees
- Polar form:
This is the classic 3, 4, 5 triangle, and it is a good first test for any function you write.
Example 2: (-5, 12), Second Quadrant
rect_to_polar(-5, 12)
# (13.0, 1.965587446494658, 112.61986494804043)
- Radius:
- Angle: radians degrees
- Polar form:
Note that the plain arctangent of gives -67.38 degrees, which is wrong by 180 degrees. math.atan2 fixes this by using the negative x value.
Example 3: (-3, -4), Third Quadrant
rect_to_polar(-3, -4)
# (5.0, -2.214297435588181, -126.86989764584402)
- Radius:
- Angle: radians degrees
- Polar form: , which is the same direction as
Example 4: (0, 0), The Origin Edge Case
rect_to_polar(0, 0)
# (0.0, 0.0, 0.0)
The radius is 0, and Python returns an angle of 0. Mathematically, the angle at the origin is undefined, because a point with no distance from the origin has no direction. In code, 0 is the usual convention, and you should test for r == 0 in your own programs if the angle matters, rather than trusting the returned 0 as a real direction.
How to Convert a List of Points
Use a list comprehension to convert many points at once. This is the pattern you want for plotting, robotics paths and signal data.
points = [(3, 4), (-5, 12), (-3, -4), (0, 0)]
polar_points = [rect_to_polar(x, y) for x, y in points]
print(polar_points)
# [(5.0, 0.9272952180016122, 53.13010235415598),
# (13.0, 1.965587446494658, 112.61986494804043),
# (5.0, -2.214297435588181, -126.86989764584402),
# (0.0, 0.0, 0.0)]
For large arrays, use NumPy instead of a loop. numpy.hypot and numpy.arctan2 work on whole arrays at once and return arrays of the same shape.
import numpy as np
x = np.array([3, -5, -3])
y = np.array([4, 12, -4])
r = np.hypot(x, y)
theta = np.arctan2(y, x)
print(r)
# [ 5. 13. 5.]
print(np.degrees(theta))
# [ 53.13010235 112.61986495 -126.86989765]
How to Convert Polar Back to Rectangular in Python
The reverse conversion uses cosine and sine. This is useful for checking your work and for drawing polar data on a normal x, y plot.
import math
def polar_to_rect(r, theta_deg):
theta_rad = math.radians(theta_deg)
x = r * math.cos(theta_rad)
y = r * math.sin(theta_rad)
return x, y
print(polar_to_rect(5, 53.13010235415598))
# (3.0000000000000004, 3.9999999999999996)
The tiny difference from exactly (3, 4) is floating point rounding, not a mistake in the formula. Round to a sensible number of decimal places when you display results.
Common Mistakes
Using math.atan Instead of math.atan2
math.atan(y / x) gives an angle between -90 and 90 degrees only. It puts a second quadrant point in the fourth quadrant and a third quadrant point in the first quadrant. Always use math.atan2(y, x), with y first.
Mixing Degrees and Radians
math.atan2 returns radians. math.sin, math.cos and math.tan also expect radians. If you pass degrees into them, or print radians and call them degrees, every answer after that is wrong. Convert with math.degrees() for display and math.radians() before you use an angle in a trig function.
Swapping the atan2 Arguments
math.atan2(y, x) is y first, x second. math.atan2(x, y) gives a different angle, measured from the y axis instead of the x axis. If your angles look 90 degrees off, check the argument order first.
Forgetting the Origin
At (0, 0), the radius is 0 and the angle has no meaning. Code that divides by r, or that uses theta as a direction, should check for the origin first.
Rounding Too Early
Keep full precision through the calculation and round only for display. Rounding theta to 53 degrees before you convert back to rectangular coordinates will move the point by a visible amount.
Where It Is Used
Rectangular to polar conversion in Python shows up in real code far more often than in textbook exercises. In robotics, a robot’s position is often measured in x and y, while its steering uses distance and heading, which are r and theta. In computer graphics, rotating a point around the origin is easier in polar form, where rotation is just adding to theta. In navigation, a bearing and a distance are the natural polar pair for a waypoint. In signal processing, a complex number has magnitude and phase, which are exactly r and theta, and Python’s abs() and cmath.phase() give the same values as math.hypot and math.atan2 for a complex input.
For the same conversion in other tools, see our guides on how to convert rectangular to polar in MATLAB, how to convert rectangular to polar in a TI-84, and how to convert rectangular to polar in a Casio calculator. For the quadrant rules behind atan2, read understanding quadrants and atan2 in coordinate conversion.
Frequently Asked Questions (FAQ)
How do I convert rectangular to polar in Python?
Use math.hypot(x, y) for the radius and math.atan2(y, x) for the angle in radians, then math.degrees() for degrees. For example, rect_to_polar(3, 4) returns r equal to 5 and theta equal to 53.13 degrees.
Should I use math.atan2 or math.atan in Python?
Use math.atan2(y, x). It returns the correct angle in all four quadrants. math.atan(y / x) only returns angles between -90 and 90 degrees, so it gives the wrong quadrant when x is negative, and it fails when x is zero.
How do I get theta in degrees instead of radians in Python?
Call math.degrees(theta_rad) on the radian value from math.atan2. For (3, 4), math.atan2(4, 3) returns 0.9273 radians, and math.degrees(0.9273) returns 53.13 degrees.
What does Python return for the point (0, 0)?
Python returns r equal to 0 and theta equal to 0. Mathematically, the angle at the origin is undefined, because a point with no distance has no direction. Treat 0 as a convention and check for the origin in your code when direction matters.
How do I convert a list of points to polar form in Python?
Use a list comprehension with your conversion function, for example [rect_to_polar(x, y) for x, y in points]. For large data sets, use NumPy with np.hypot(x, y) and np.arctan2(y, x) on whole arrays.
Can I convert polar back to rectangular in Python?
Yes. With r and theta in degrees, use x = r * math.cos(math.radians(theta)) and y = r * math.sin(math.radians(theta)). For r equal to 5 and theta equal to 53.13 degrees, this returns x close to 3 and y close to 4, with a tiny floating point rounding difference.