Created
September 29, 2013 00:51
-
-
Save alecperkins/6748189 to your computer and use it in GitHub Desktop.
Convert a bearing in degrees to a cardinal or ordinal direction. eg: 90 becomes E, 195 becomes SSW
This file contains hidden or 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
bearingToDirection = (bearing, abbrev=true) -> | |
if abbrev | |
directions = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N'] | |
else | |
directions = ['North', 'North-Northeast', 'Northeast', 'East-Northeast', 'East', 'East-Southeast', 'Southeast', 'South-Southeast', 'South', 'South-Southwest', 'Southwest', 'West-Southwest', 'West', 'West-Northwest', 'Northwest', 'North-Northwest', 'North'] | |
return directions[Math.floor((bearing + 11.25) / 22.5)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment