Averaging angles… Again

后端 未结 12 2115
情歌与酒
情歌与酒 2020-12-14 08:26

I want to calculate the average of a set of angles, which represents source bearing (0 to 360 deg) - (similar to wind-direction)

I know it has been

12条回答
  •  自闭症患者
    2020-12-14 09:29

    Here you go! The reference is https://www.wxforum.net/index.php?topic=8660.0

    def avgWind(directions):
        sinSum = 0
        cosSum = 0
        d2r = math.pi/180 #degree to radian
        r2d = 180/math.pi
           
        for i in range(len(directions)):
            sinSum += math.sin(directions[i]*d2r)
            cosSum += math.cos(directions[i]*d2r)
          
        return ((r2d*(math.atan2(sinSum, cosSum)) + 360) % 360)
    a= np.random.randint(low=0, high=360, size=6)
    print(a)
    avgWind(a)
    

提交回复
热议问题