A survey boat's autopilot and its navigation code disagree about angles.
- The compass convention, used by the crew: degrees,
0is north, angles grow clockwise, so90is east,180south and270west. A compass heading is always in [0, 360). - The maths convention, used by the code: radians,
0is east (the world's +x axis; +y is north), angles grow counter-clockwise, so north is \pi/2. A maths heading is always wrapped to (-\pi, \pi]; west is written as +\pi, never -\pi.
Write convert_heading(value, to):
to == "math":valueis a compass heading in degrees; return the same direction as a maths heading in radians, in (-\pi, \pi].to == "compass":valueis a maths heading in radians; return the compass heading in degrees, in [0, 360).
Examples
Input: value = 135, to = "math"
Output: -0.7853981633974483
Explanation: 135 on the compass is south-east, 45 degrees clockwise of east: -pi/4.
Input: value = 270, to = "math"
Output: 3.141592653589793
Explanation: due west is pi (not -pi).
Input: value = 3.141592653589793, to = "compass"
Output: 270.0
Constraints
- answers are compared with a tolerance of
1e-6; do not round
Goals
- Translate between a compass heading and the maths angle convention
- Convert between degrees and radians in the right place
- Wrap the result into the range each convention uses