Skip to content

Instantly share code, notes, and snippets.

@RobertSudwarts
RobertSudwarts / deg_to_cardinal.py
Created June 7, 2015 16:18
[python] degrees to cardinal directions
def degrees_to_cardinal(d):
'''
note: this is highly approximate...
'''
dirs = ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE",
"S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"]
ix = int((d + 11.25)/22.5)
return dirs[ix % 16]