本文介绍了平均角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看了一些解决方案,在这里,但没有提供我所需要的,因此:

I looked at some solutions here but none provide what I need, so:

我要平均的角度数组(0至359.9,没有底片)(A1 + A2 + A3 +安)/ N

I need to average an array of angles(0 to 359.9, no negatives)(A1 + A2 + A3 + An) / n

的问题是,当你得到一个数组{1,359,2,358}的平均值,如果你使用上面的公式是180,但实际上它应该是0。

The issue is when you get an array {1, 359, 2, 358} the average if you use the formula above is 180, but actually it is supposed to be 0.

有什么想法?

推荐答案

...添加各角度的单位向量,将得到的矢量转换回的角度。如果结果向量的长度为零,输入相互抵消,其结果是不确定的。

Add unit vectors of each angle, and convert the resulting vector back into an angle. If the result vector is of zero length, the inputs cancelled each other out and the result is indeterminate.

一个单位矢量具有1的长度,以及它的x和y长度由角的余弦和正弦给出。因此,你平均的例子如下面的伪code:

A unit vector has a length of 1, and its x and y lengths are given by the cosine and sine of the angle. Thus you average your examples as in the following pseudo-code:

x = cos(radians(1)) + cos(radians(359)) + cos(radians(2)) + cos(radians(358));
y = sin(radians(1)) + sin(radians(359)) + sin(radians(2)) + sin(radians(358));
angle = degrees(atan2(y, x));

这篇关于平均角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 06:38