-
-
Save jxxe/13c4f564a6c102edf5bedf20ccad2b18 to your computer and use it in GitHub Desktop.
[PHP] Convert degrees to cardinal directions
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 degreesToCardinal($degrees) { | |
$directions = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW']; | |
$index = ($degrees + 11.25) / 22.5; | |
return $directions[$index % 16]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment