Skip to content

Instantly share code, notes, and snippets.

@zhayes84
Forked from RobertSudwarts/deg_to_cardinal.py
Last active April 26, 2022 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhayes84/3642e2e432f9c5aaa83caf4d53af3955 to your computer and use it in GitHub Desktop.
Save zhayes84/3642e2e432f9c5aaa83caf4d53af3955 to your computer and use it in GitHub Desktop.
[python] degrees to cardinal directions
def degrees_to_cardinal(degrees):
directions = ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE",
"S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"]
ix = round(degrees / (360. / len(directions)))
return directions[ix % len(directions)]
@zhayes84
Copy link
Author

Updated to increase readability by using full words for variables and changing the degree conversion based on this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment