Reputation: 2315
I'm write this bit of code to convert azimuth degrees to human redable, but the conversion is not more accurate, in cases of degrees is slightly smaller than 360.
function azimutHuman(ang) { //can be 0 - 360
var azimuthHumans = [
'Nord','Nord-NE','Nord-Est','Est-NE',
'Est','Est-SE','Sud-Est','Sud-SE',
'Sud','Sud-SO','Sud-Ovest','Ovest-SO',
'Ovest','Ovest-SO','Nord-Ovest','Nord-NO'];
return azimuthHumans[ Math.round(ang/22.5) ];
}
for example:
azimutHuman(350); //return undefined instead of "Nord"
Upvotes: 0
Views: 346
Reputation: 425
350 -> 360 = 0->10 : 360 is north as will as 0 .
so you need to add an element "Nord" again .try this function now :
function azimutHuman(ang) { //can be 0 - 360
var azimuthHumans = [
'Nord','Nord-NE','Nord-Est','Est-NE',
'Est','Est-SE','Sud-Est','Sud-SE',
'Sud','Sud-SO','Sud-Ovest','Ovest-SO',
'Ovest','Ovest-SO','Nord-Ovest','Nord-NO','Nord'];
return azimuthHumans[ Math.round(ang/22.5) ];
}
Upvotes: 1
Reputation: 2226
Math.round(350/22.5) = 16
Your array at index 16 is undefined. Add a 16th element to it, Nord
again should work
Upvotes: 0