#include "math.h" #include "turret.h" double degToRad(double deg) { return deg * M_PI / 180.0; } double radToDeg(double rad) { return rad * 180.0 / M_PI; } void angleToStep(Turret::StepRatio stepRatio, vec2 angle, vec2 &step) { step.x = angle.x * stepRatio.x; step.y = angle.y * stepRatio.y; } void cartesianToPolar(Turret::StepRatio stepRatio, Turret::Offset offset, vec2 zero, vec3 position, vec2 &step) { // x = -x; // natural axis direction position.y = -position.y; // natural axis direction double dX = position.x + offset.x; double dY = position.y + offset.y; double dZ = position.z + offset.z; vec2 angle( atan2(dZ, dY) - M_PI / 2, atan2(dZ, dX) - M_PI / 2 ); angleToStep(stepRatio, angle, step); }