-
-
Save allebb/165faffa61f145fb7b81c2f8d49ced9d to your computer and use it in GitHub Desktop.
Compass heading to cardinal direction in c#
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
public static string DegreesToCardinal(double degrees) | |
{ | |
string[] caridnals = { "N", "NE", "E", "SE", "S", "SW", "W", "NW", "N" }; | |
return caridnals[ (int)Math.Round(((double)degrees % 360) / 45) ]; | |
} | |
public static string DegreesToCardinalDetailed(double degrees) | |
{ | |
string[] caridnals = { "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW", "N" }; | |
return caridnals[ (int)Math.Round(((double)degrees*10 % 3600) / 225) ]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment