Converting wind direction in angles to text words

后端 未结 15 919
执笔经年
执笔经年 2021-01-30 13:16

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 di

15条回答
  •  误落风尘
    2021-01-30 13:47

    Watch out for rounding, angles between 349...11 should be "N", therefore add half sector first (+(360/16)/2), then handle overflow over 360 by %360, then divide by 360/16:

    ["N","NNW",...,"NNE"][((d+(360/16)/2)%360)/(360/16)]
    

提交回复
热议问题