-
-
Save zhayes84/3642e2e432f9c5aaa83caf4d53af3955 to your computer and use it in GitHub Desktop.
[python] degrees to cardinal directions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to increase readability by using full words for variables and changing the degree conversion based on this comment.