Last active
August 7, 2022 03:33
-
-
Save mmar/284964 to your computer and use it in GitHub Desktop.
Converting degrees to compass heading
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
class Fixnum | |
def degrees_to_compass | |
%w( N NNE NE ENE E ESE SE SSE S SSW SW WSW W WNW NW NNW )[((self+11.25).modulo(360)/22.5).floor] | |
end | |
end |
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
func heading(degrees: Double) -> String { | |
["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"][Int((degrees + 11.25).truncatingRemainder(dividingBy: 360) / 22.5)] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment