L2C/coordinate_conversion.cpp
2024-09-20 00:57:41 -06:00

17 lines
521 B
C++

#ifndef COORDINATE_CONVERSION_H
#define COORDINATE_CONVERSION_H
#include <cmath>
void polar_to_cartesian(double radius, double angle, double *xCoordinate,
double *yCoordinate) {
*xCoordinate = radius * std::cos(angle);
*yCoordinate = radius * std::sin(angle);
}
void cartesian_to_polar(double xCoordinate, double yCoordinate, double *radius,
double *angle) {
*radius = std::sqrt(std::pow(xCoordinate, 2) + std::pow(yCoordinate, 2));
*angle = std::atan(xCoordinate);
}
#endif // COORDINATE_CONVERSION_H