Python Program to Convert Cartesian to Polar Coordinate
In mathematics, a Cartesian coordinate system is a coordinate system that specifies each point uniquely in a plane by a set of numeric points.
Cartesian Coordinates is represented by (x,y).
In mathematics, the polar coordinate system is a two-dimensional coordinate system in which each point on a plane is determined by a distance from a reference point known as radius and an angle from a reference direction known as theta or simply angle.
Polar Coordinates system is represented by (r,θ).
Formula to Convert Cartesian to Polar Coordinate
r = √ ( x2 + y2 )
θ = tan-1 ( y / x )
This python programs converts Cartesian Coordinate given by user to Polar Coordinate using Cartesian to Polar Conversion Formula.
Also check: Polar to Cartesian Conversion in Python
Python Source Code: Cartesian to Polar Coordinate Conversion
# Converting Cartesian Coordinate to Polar Coordinate # Importing math library import math # Reading cartesian coordinate x = float(input('Enter value of x: ')) y = float(input('Enter value of y: ')) # Converting cartesian to polar coordinate # Calculating radius radius = math.sqrt( x * x + y * y ) # Calculating angle (theta) in radian theta = math.atan(y/x) # Converting theta from radian to degree theta = 180 * theta/math.pi # Displaying polar coordinates print('Polar coordinate is: (radius = %0.2f,theta = %0.2f)' %(radius, theta))
Python Program Output: Cartesian to Polar Conversion
Enter value of x: 1 Enter value of y: 1 Polar coordinate is: (radius = 1.41,theta = 45.00)