Search code examples
pythoncoordinatesangle

Map N,S,E,W Angle system System to 360° Angle System


I have a coordinate system where North has the angle value 1. East +0.707 and West -0.707. South has the angle 0. It's very annoying to calculate angle deltas in this angle system. Is there a nice way to convert it to a standard 0 to 360 degree coordinate system? Python solution preferred but I'm more interested in the operations instead of ready to use implementation.


Solution

  • That angle system is very weird. It seems like your "angle" is calculated as sin(radians(d/2)) where d is actual angle in degrees (with south being 0° and east 90°). You can invert this:

    >>> from math import *
    >>> ewns = [0.707, -0.707, 1.0, 0.0]
    >>> [degrees(asin(x) * 2) for x in ewns]
    [89.98269667432403, -89.98269667432403, 180.0, 0.0]
    

    Optionally round and add % 360 to get 0..360 instead of -180..180:

    >>> [round(degrees(asin(x) * 2)) % 360 for x in ewns]
    [90, 270, 180, 0]