Last active
April 29, 2017 01:22
-
-
Save alexitaylor/b92f4c3973f6bdca4d6d8a8dabd1a9a8 to your computer and use it in GitHub Desktop.
Cardinal Direction: get cardinal direction from degrees
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
//given "0-360" returns the nearest cardinal direction "N/NE/E/SE/S/SW/W/NW/N" | |
function getCardinal (angle) { | |
if (angle >= 0 && angle <= 22 || angle >= 338 && angle <= 360) | |
return "N"; | |
if (angle >= 23 && angle <= 67) | |
return "NE"; | |
if (angle >= 68 && angle <= 112) | |
return "E"; | |
if (angle >= 113 && angle <= 157) | |
return "SE"; | |
if (angle >= 158 && angle <= 202) | |
return "S"; | |
if (angle >= 203 && angle <= 247) | |
return "SW"; | |
if (angle >= 248 && angle <= 292) | |
return "W"; | |
if (angle >= 293 && angle <= 337) | |
return "NW"; | |
//Should never happen: | |
return undefined; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment