L2C/coordinate_conversion.cpp

17 lines
535 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 / yCoordinate);
}
#endif // COORDINATE_CONVERSION_H