Skip to content

Instantly share code, notes, and snippets.

@Freakisimo
Forked from RobertSudwarts/deg_to_cardinal.py
Created August 6, 2019 20:24
Show Gist options
  • Save Freakisimo/ea2482be6cc4d5d32e1758bc41dcdc36 to your computer and use it in GitHub Desktop.
Save Freakisimo/ea2482be6cc4d5d32e1758bc41dcdc36 to your computer and use it in GitHub Desktop.
[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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment