C Program to Convert Polar Coordinate to Cartesian Coordinates

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 Polar Coordinate to Cartesian Coordinate

To convert from Polar Coordinates (r,θ) to Cartesian Coordinates (x,y) :
x = r × cos( θ )
y = r × sin( θ )

Polar to Cartesian C Program


#define PI 3.141592

int main()
	 float x, y, r, theta;
	 printf("Enter radius of polar coordinate (r): ");
	 scanf("%f", &r);
	 printf("Enter angle of polar coordinate in degree (theta): ");
	 scanf("%f", &theta);
	 /* Converting theta from degree to radian */
	 theta = theta * PI/180.0;
	 /* Calculating cartesian coordinate x */
	 x = r * cos(theta);
	 /* Calculating cartesian coordinate y */
	 y = r * sin(theta);
	 printf("Cartesian coordinates is: (%0.3f, %0.3f)", x, y);

Output of the above program :

Enter radius of polar coordinate (r): 1.4142 ↲
Enter angle of polar coordinate in degree (theta): 45 ↲
Cartesian coordinates is: (1.000, 1.000)

Note: ↲ indicates ENTER is pressed.