L2C/coordinate_conversion.cpp

18 lines
613 B
C++
Raw Permalink Normal View History

2024-09-20 00:57:41 -06:00
#ifndef COORDINATE_CONVERSION_H
#define COORDINATE_CONVERSION_H
#include <cmath>
2024-09-22 20:23:56 -06:00
void polar_to_cartesian(const double RADIUS, const double ANGLE,
double* pXCoordinate, double* pYCoordinate) {
*pXCoordinate = RADIUS * std::cos(ANGLE);
*pYCoordinate = RADIUS * std::sin(ANGLE);
2024-09-20 00:57:41 -06:00
}
2024-09-22 20:23:56 -06:00
void cartesian_to_polar(const double X_COORDINATE, const double Y_COORDINATE,
double* pRadius, double* pAngle) {
*pRadius = std::sqrt(std::pow(X_COORDINATE, 2) + std::pow(Y_COORDINATE, 2));
*pAngle = std::atan(X_COORDINATE / Y_COORDINATE);
2024-09-20 00:57:41 -06:00
}
#endif // COORDINATE_CONVERSION_H