环绕的两个角度的平均值

发布于 2024-07-28 11:46:18 字数 383 浏览 15 评论 0原文

可能的重复:
如何计算一组的平均值循环数据?

我有两个角度,a=20 度和 b=350 度。 这两个角度的平均值是 185 度。 然而,如果我们考虑最大角度为 360 度并允许环绕,则可以看到 5 度是更接近的平均值。

在计算平均值时,我很难想出一个好的公式来处理这种情况。 有人有任何提示吗?

还是我在这里搬起石头砸自己的脚? 这在数学中被认为是“不好的做法”吗?

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

I have two angles, a=20 degrees and b=350 degrees. The average of those two angles are 185 degrees. However, if we consider that the maximum angle is 360 degrees and allows for wrap around, one could see that 5 degrees is a closer average.

I'm having troubles coming up with a good formula to handle that wrap around when calculating average. Anyone got any hints?

Or am I shooting myself in the foot here? Is this considered "bad practice" in math?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

好多鱼好多余 2024-08-04 11:46:37

只需取正常平均值,然后取模 180。在您的示例中,这给出了 5 度,正如预期的那样。

Just take a normal average and then take it mod 180. In your example this gives 5 degrees, as expected.

岁月流歌 2024-08-04 11:46:34

试试这个(C# 中的示例):

    static void Main(string[] args)
    {
        Console.WriteLine(GetAngleAverage(0,0));
        Console.WriteLine(GetAngleAverage(269, 271));
        Console.WriteLine(GetAngleAverage(350, 20));
        Console.WriteLine(GetAngleAverage(361, 361));
    }

    static int GetAngleAverage(int a, int b)
    {
        a = a % 360;
        b = b % 360;

        int sum = a + b;
        if (sum > 360 && sum < 540)
        {
            sum = sum % 180;
        }
        return sum / 2;
    }

我认为它有效,输出是

0
270
5
1

Try this (example in C#):

    static void Main(string[] args)
    {
        Console.WriteLine(GetAngleAverage(0,0));
        Console.WriteLine(GetAngleAverage(269, 271));
        Console.WriteLine(GetAngleAverage(350, 20));
        Console.WriteLine(GetAngleAverage(361, 361));
    }

    static int GetAngleAverage(int a, int b)
    {
        a = a % 360;
        b = b % 360;

        int sum = a + b;
        if (sum > 360 && sum < 540)
        {
            sum = sum % 180;
        }
        return sum / 2;
    }

I think it works, the output is

0
270
5
1
站稳脚跟 2024-08-04 11:46:30

如果你看一下角圈,你会发现有 2 个相对的“角度”对应于你的“平均值”。

所以185°和5°都是正确的。

但您提到了更接近的平均值。 所以在这种情况下,你可以选择更近的角度。

通常,角度的“平均值”涉及逆时针方向。 如果你交换两个角度(或者如果你使用顺时针方向),“平均值”是不一样的。

例如,对于 a=20°b=350°,您要查找 a 之后和 之前的角度b逆时针方向185°就是答案。 如果您正在寻找逆时针方向位于 a 之前和 b 之后的角度(或在 a 之后和 b< /code> 逆时针方向), 就是答案。

这篇文章的答案是正确的做法。

所以解决方案的伪代码是

if (a+180)mod 360 == b then
  return (a+b)/2 mod 360 and ((a+b)/2 mod 360) + 180 (they are both the solution, so you may choose one depending if you prefer counterclockwise or clockwise direction)
else
  return arctan(  (sin(a)+sin(b)) / (cos(a)+cos(b) )

if you have a look at the angular circle, you will see that there are 2 opposite "angles" that corresponds to your "average".

So both 185° and 5° are correct.

But you mentionned the closer average. So in that case, you may choose the angle that is closer.

Usually, the "average" of angles concerns the counterclockwise direction. The "average" is not the same if you switch your two angles (or if you use the clockwise direction).

For example, with a=20° and b=350°, you are looking for the angle that comes after a and before b in the counterclockwise direction, 185° is the answer. If you are looking for the angle that comes before a and after b in the counterclockwise direction (or after a and before b in the counterclock wise direction), is the answer.

The answer of this post is the right way to do.

So the pseudo-code for the solution is

if (a+180)mod 360 == b then
  return (a+b)/2 mod 360 and ((a+b)/2 mod 360) + 180 (they are both the solution, so you may choose one depending if you prefer counterclockwise or clockwise direction)
else
  return arctan(  (sin(a)+sin(b)) / (cos(a)+cos(b) )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文