Skip to content

Instantly share code, notes, and snippets.

@dario61081
Created May 9, 2017 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dario61081/fa4cde146d143bb0ba6055b84c5eb33e to your computer and use it in GitHub Desktop.
Save dario61081/fa4cde146d143bb0ba6055b84c5eb33e to your computer and use it in GitHub Desktop.
Convertir grados en rosa de vientos
public String convertDegreeToCardinalDirection(int directionInDegrees){
String cardinalDirection = null;
if( (directionInDegrees >= 348.75) && (directionInDegrees <= 360) ||
(directionInDegrees >= 0) && (directionInDegrees <= 11.25) ){
cardinalDirection = "N";
} else if( (directionInDegrees >= 11.25 ) && (directionInDegrees <= 33.75)){
cardinalDirection = "NNE";
} else if( (directionInDegrees >= 33.75 ) &&(directionInDegrees <= 56.25)){
cardinalDirection = "NE";
} else if( (directionInDegrees >= 56.25 ) && (directionInDegrees <= 78.75)){
cardinalDirection = "ENE";
} else if( (directionInDegrees >= 78.75 ) && (directionInDegrees <= 101.25) ){
cardinalDirection = "E";
} else if( (directionInDegrees >= 101.25) && (directionInDegrees <= 123.75) ){
cardinalDirection = "ESE";
} else if( (directionInDegrees >= 123.75) && (directionInDegrees <= 146.25) ){
cardinalDirection = "SE";
} else if( (directionInDegrees >= 146.25) && (directionInDegrees <= 168.75) ){
cardinalDirection = "SSE";
} else if( (directionInDegrees >= 168.75) && (directionInDegrees <= 191.25) ){
cardinalDirection = "S";
} else if( (directionInDegrees >= 191.25) && (directionInDegrees <= 213.75) ){
cardinalDirection = "SSW";
} else if( (directionInDegrees >= 213.75) && (directionInDegrees <= 236.25) ){
cardinalDirection = "SW";
} else if( (directionInDegrees >= 236.25) && (directionInDegrees <= 258.75) ){
cardinalDirection = "WSW";
} else if( (directionInDegrees >= 258.75) && (directionInDegrees <= 281.25) ){
cardinalDirection = "W";
} else if( (directionInDegrees >= 281.25) && (directionInDegrees <= 303.75) ){
cardinalDirection = "WNW";
} else if( (directionInDegrees >= 303.75) && (directionInDegrees <= 326.25) ){
cardinalDirection = "NW";
} else if( (directionInDegrees >= 326.25) && (directionInDegrees <= 348.75) ){
cardinalDirection = "NNW";
} else {
cardinalDirection = "?";
}
return cardinalDirection;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment