Skip to content

Instantly share code, notes, and snippets.

@jpriebe
Created May 3, 2018 12:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpriebe/bcc27fc99f32cc19e08b05cee405d130 to your computer and use it in GitHub Desktop.
Save jpriebe/bcc27fc99f32cc19e08b05cee405d130 to your computer and use it in GitHub Desktop.
Convert degrees to direction string
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