Converting wind direction in angles to text words

后端 未结 15 757
执笔经年
执笔经年 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 14:13

    If you arrived here and are only interested in breaking your degrees into one of 8 directions.

    function degToCompass(num){
        const val =  Math.floor((num / 45) + 0.5);
        const arr = ["N","NE","E", "SE","S","SW","W","NW"];
        return arr[(val % 8)]
    

提交回复
热议问题