algorithm - 平均角度......再次

标签 algorithm math geometry

我想计算一组角度的平均值,代表源方位(0 到 360 度)-(类似于风向)

我知道之前已经讨论过(多次)。公认的答案是根据角度计算单位向量并取其平均值

然而,这个答案以一种非直观的方式定义了平均值。 0、0 和 90 的平均值将是 atan( (sin(0)+sin(0)+sin(90))/(cos(0)+cos(0)+cos(90)) ) = atan(1/2)= 26.56 度

我希望 0、0 和 90 的平均值为 30 度。

所以我认为重新问这个问题是公平的:你会如何计算平均值,所以这样的例子会给出直观的预期答案。

2014 年编辑:

问完这个问题后,我发布了 an article on CodeProject其中提供了透彻的分析。文章考察了以下引用问题:

  • 给定 2000 年美国每次出生的时间 [00:00-24:00) - 计算平均出生时间
  • 给定从固定发射器到固定接收器的多组方向测量值,使用具有包裹正态分布误差的测量技术 – 估计方向。
  • 给定由“普通”人类做出的两点之间的多组方位角估计(假设受到包裹截断正态分布误差的影响)——估计方向。

最佳答案

[注意 OP 的问题(但不是标题)似乎已经变成了一个相当专业的问题(“......角度序列的平均值,其中每个连续添加都没有与运行平均值的差异超过指定数量。”) - 请参阅@MaR 评论和我的。我的以下回答涉及 OP 的标题以及与之相关的大部分讨论和回答。]

这不是逻辑或直觉的问题,而是定义的问题。之前已经在 SO 上讨论过这个问题,但没有达成任何真正的共识。角度应在一个范围内定义(可能是 -PI 到 +PI,或 0 到 2*PI,或者可能是 -Inf 到 +Inf。每种情况下的答案都会不同。

“角度”这个词会引起混淆,因为它的含义不同。 视角是一个无符号的量(通常是 PI > theta > 0。在这种情况下,“正常”平均值可能会有用。旋转角度(例如总旋转如果是溜冰者)可能会或可能不会签名,并且可能包括 theta > 2PI 和 theta < -2PI。

这里定义的是angle = direction,需要向量。如果您使用“方向”而不是“角度”一词,您将捕捉到 OP 的(明显的原始)意图,这将有助于摆脱标量。

维基百科显示了当角度被定义为圆形时的正确方法

theta = theta+2*PI*N = theta-2*PI*N

均值的答案不是标量而是向量。 OP 可能不觉得这是直观的,但它是唯一有用的正确方法。我们不能将 -4 的平方根重新定义为 -2,因为它更直观——它必须是 +-2*i。同样,方位角 -90 度和 +90 度的平均值是零长度矢量,而不是 0.0 度。

维基百科 ( http://en.wikipedia.org/wiki/Mean_of_circular_quantities ) 有一个特殊的部分和状态(方程式是 LaTeX 并且可以在维基百科中看到渲染):

Most of the usual means fail on circular quantities, like angles, daytimes, fractional parts of real numbers. For those quantities you need a mean of circular quantities.

Since the arithmetic mean is not effective for angles, the following method can be used to obtain both a mean value and measure for the variance of the angles:

Convert all angles to corresponding points on the unit circle, e.g., α to (cosα,sinα). That is convert polar coordinates to Cartesian coordinates. Then compute the arithmetic mean of these points. The resulting point will lie on the unit disk. Convert that point back to polar coordinates. The angle is a reasonable mean of the input angles. The resulting radius will be 1 if all angles are equal. If the angles are uniformly distributed on the circle, then the resulting radius will be 0, and there is no circular mean. In other words, the radius measures the concentration of the angles.

Given the angles \alpha_1,\dots,\alpha_n the mean is computed by

M \alpha = \operatorname{atan2}\left(\frac{1}{n}\cdot\sum_{j=1}^n

\sin\alpha_j, \frac{1}{n}\cdot\sum_{j=1}^n \cos\alpha_j\right)

using the atan2 variant of the arctangent function, or

M \alpha = \arg\left(\frac{1}{n}\cdot\sum_{j=1}^n

\exp(i\cdot\alpha_j)\right)

using complex numbers.

请注意,在 OP 的问题中,角度 0 完全是任意的——风从 0 度而不是 180 度没有什么特别的(除了在这个半球,自行车上的温度更冷)。尝试将 0,0,90 更改为 289、289、379,看看简单的算术不再有效。

(一些分布,其中 0 和 PI 的角度具有特殊意义,但它们不在此处的范围内)。

以下是一些反射(reflect)当前观点传播的激烈讨论:-)

Link

How do you calculate the average of a set of circular data?

http://forums.xkcd.com/viewtopic.php?f=17&t=22435

http://www.allegro.cc/forums/thread/595008

关于algorithm - 平均角度......再次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1813483/

相关文章:

geometry - 极几何

algorithm - 找到具有给定点数的最小包含凸多边形

algorithm - 搜索操作复杂度

algorithm - 贪婪将如何在这个硬币找零的案例中发挥作用

algorithm - 如何比较两个形状?

math - 在Prolog程序中求所有自然数解

javascript - math.js 中的变量名和限制运算符

algorithm - 根据数字确定日期

javascript - Canvas 图像编辑器

c++ - 按中心、法线、长度和高度获取矩形顶点