Created
May 3, 2018 12:12
-
-
Save jpriebe/bcc27fc99f32cc19e08b05cee405d130 to your computer and use it in GitHub Desktop.
Convert degrees to direction string
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
function degrees_to_direction ($degrees, $short=true) | |
{ | |
$dir_ary = [ | |
['N', 'North'], | |
['NNE', 'North Northeast'], | |
['NE', 'Northeast'], | |
['ENE', 'East Northeast'], | |
['E', 'East'], | |
['ESE', 'East Southeast'], | |
['SE', 'Southeast'], | |
['SSE', 'South Southeast'], | |
['S', 'South'], | |
['SSW', 'South Southwest'], | |
['SW', 'Southwest'], | |
['WSW', 'West Southwest'], | |
['W', 'West'], | |
['WNW', 'West Northwest'], | |
['NW', 'Northwest'], | |
['NNW', 'North Northwest'], | |
]; | |
$idx = round ($degrees / 22.5) % 16; | |
if ($short) | |
{ | |
return $dir_ary[$idx][0]; | |
} | |
return $dir_ary[$idx][1]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment