Before starting with the program, let’s see the basics of Polar Coordinates and then use Python’s cmath and abs module to convert it. Polar coordinates are just a different way of representing Cartesian coordinates or Complex Numbers. A complex number z is defined as :
![]()
It is completely determined by its real part x and imaginary part y. Here, j is the imaginary unit.
The polar coordinates (r , φ) is completely determined by modulus r and phase angle φ.
Where,
- r: Distance from z to origin, i.e.,
![]()
- φ: Counterclockwise angle measured from the positive x-axis to the line segment that joins z to the origin.
The conversion of complex numbers to polar co-ordinates are explained below with examples.
Using cmath module
Python’s cmath module provides access to the mathematical functions for complex numbers. It contains several functions that are used for converting coordinates from one domain to another.
Out of them, some are explained as-
1. cmath.polar(x):
Return the representation of x in polar coordinates. cmath.polar() function is used to convert a complex number to polar coordinates.
Python3
# Python code to implement # the polar()function # importing "cmath" # for mathematical operations import cmath # using cmath.polar() method num = cmath.polar(1) print(num) |
(1.0, 0.0)
2. cmath.phase (z): This method returns the phase of complex number z(also known as the argument of z).
Python3
import cmath x = -1.0y = 0.0z = complex(x,y); # printing phase of a complex number using phase() print ("The phase of complex number is : ",end="") print (cmath.phase(z)) |
The phase of complex number is : 3.141592653589793
Using abs()
abs(): This method returns the modulus (absolute value) of complex number z.
Python3
num1 = 3 + 4jprint('Absolute value of 3 + 4j is:', abs(num1)) |
Absolute value of 3 + 4j is: 5.0
You are given a complex number z and your task is to convert it to polar coordinates.
Let us consider a complex number as 1+5j, and we need to convert it to Polar coordinates.
Python3
import cmath c = complex(1+5j) print(abs(c)) |
5.0990195135927845
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- matplotlib.pyplot.polar() in Python
- Python - cmath.polar() function
- Plotting polar curves in Python
- Polar Charts using Plotly in Python
- How to make Wind Rose and Polar Bar Charts in Plotly - Python?
- Python | Convert location coordinates to tuple
- Python program for addition and subtraction of complex numbers
- Complex Numbers in Python | Set 1 (Introduction)
- Complex Numbers in Python | Set 2 (Important Functions and Constants)
- Complex Numbers in Python | Set 3 (Trigonometric and Hyperbolic Functions)
- Multiply matrices of complex numbers using NumPy in Python
- Python program for multiplication and division of complex number
- Python | Calculate geographic coordinates of places using google geocoding API
- Python | Reverse Geocoding to get location on a map using geographic coordinates
- Python - Adjacent Coordinates in N dimension
- Python - Group Adjacent Coordinates
- Python - Character coordinates in Matrix
- Displaying the coordinates of the points clicked on the image using Python-OpenCV
- Parallel Coordinates Plot using Plotly in Python
- Extracting the real and imaginary parts of an NumPy array of complex numbers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

