Converting wind direction in angles to text words

后端 未结 15 900
执笔经年
执笔经年 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:57

    Wanted to use @eudoxos but needed to pull all the parts together:

    def deg_to_compass(d):
      return ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE",
            "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"] [math.floor(((d+(360/16)/2)%360)/(360/16))]
    

    Borrrowed @Hristo markow to check the results:

    for i in range(0,360):
      print (i,deg_to_compass(i) == wind_deg_to_str2(i))
    

提交回复
热议问题