Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting wind direction in angles to text words

Tags:

angle

I have wind direction data coming from a weather vane, and the data is represented in 0 to 359 degrees.

I want to convert this into text format (compass rose) with 16 different directions.

Basically I want to know if there is a fast slick way to scale the angle reading to a 16 string array to print out the correct wind direction without using a bunch of if statements and checking for ranges of angles

Wind direction can be found here.

thanks!

like image 930
zacharoni Avatar asked Sep 20 '11 19:09

zacharoni


People also ask

How do you write wind direction in degrees?

The truth is that wind direction can also be presented in azimuth degrees, i.e., in a numerical measure that moves around the Rose of the Winds in a clockwise circle from 0 degrees (N) to 360 degrees (N). So, if north represents 0 degrees, then east is 90 degrees, south is 180 degrees, and west sits at 270 degrees.

How do you convert the wind from degrees to cardinal directions?

To convert degrees to compass directions, I first divide the compass into 16 sectors of 22.5 degrees each. The sectors are like slices of pie, centered on the compass points. Tip: If you would like to use eight sectors instead of 16, with a shorter lookup table, divide by 45 degrees instead of 22.5 degrees.

What wind direction is 180 degrees?

Wind direction is typically reported in degrees, and describes the direction from which the wind emanates. A direction of 0 degrees is due North on a compass, and 180 degrees is due South. A direction of 270 degrees would indicate a wind blowing in from the west.

What wind direction is 360?

North is 360 degrees. A wind direction of 0 degrees is only used when wind is calm.


2 Answers

EDIT :

Since there is an angle change at every 22.5 degrees, the direction should swap hands after 11.25 degrees.

Therefore:

349-360//0-11 = N 12-33 = NNE 34-56 = NE 

Using values from 327-348 (The entire NNW spectrum) failed to produce a result for eudoxos' answer. After giving it some thought I could not find the flaw in his logic, so i rewrote my own..

def degToCompass(num):     val=int((num/22.5)+.5)     arr=["N","NNE","NE","ENE","E","ESE", "SE", "SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"]     print arr[(val % 16)]  >>> degToCompass(0) N >>> degToCompass(180) S >>> degToCompass(720) N >>> degToCompass(11) N >>> 12 12 >>> degToCompass(12) NNE >>> degToCompass(33) NNE >>> degToCompass(34) NE 

STEPS :

  1. Divide the angle by 22.5 because 360deg/16 directions = 22.5deg/direction change.
  2. Add .5 so that when you truncate the value you can break the 'tie' between the change threshold.
  3. Truncate the value using integer division (so there is no rounding).
  4. Directly index into the array and print the value (mod 16).
like image 62
steve-gregory Avatar answered Sep 22 '22 12:09

steve-gregory


Here's a javascript implementation of steve-gregory's answer, which works for me.

function degToCompass(num) {     var val = Math.floor((num / 22.5) + 0.5);     var arr = ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"];     return arr[(val % 16)]; } 

See his answer for an explanation of the logic.

like image 38
Matt Frear Avatar answered Sep 23 '22 12:09

Matt Frear