diff --git a/misc/cartesian_to_polar.c b/misc/cartesian_to_polar.c index e7b02128..e0824e19 100644 --- a/misc/cartesian_to_polar.c +++ b/misc/cartesian_to_polar.c @@ -1,8 +1,11 @@ +/** + * @file + * @brief Function to convert a Cartesian co-ordinate to polar form. + */ +#define _USE_MATH_DEFINES /**< required for MS Visual C */ #include #include -const double pi = 3.141592653589793238462643383279502884; - /** give as arguments to the executable two x and y coordinates outputs a polar coordinate @@ -24,15 +27,15 @@ int main() } else if (x < 0 && y > 0) { // Q2 - thetaFinal = theta + pi; + thetaFinal = theta + M_PI; } else if (x < 0 && y < 0) { // Q3 - thetaFinal = theta - pi; + thetaFinal = theta - M_PI; } else if (x > 0 && y < 0) { // Q4 - thetaFinal = 2 * pi - theta; + thetaFinal = 2 * M_PI - theta; } } } @@ -40,11 +43,11 @@ int main() { // exceptions when no actual angle is present if (y > 0) { - thetaFinal = pi / 2; + thetaFinal = M_PI / 2; } else { - thetaFinal = -(pi / 2); + thetaFinal = -(M_PI / 2); } } if (y == 0) @@ -55,7 +58,7 @@ int main() } else { - thetaFinal = -pi; + thetaFinal = -M_PI; } } printf("%.2f %.2f\n", r, atan2(y, x));