【问题标题】:Average of 2 angles with 360 degrees wrap around360 度环绕的 2 个角度的平均值
【发布时间】:2017-11-04 02:49:42
【问题描述】:

Average of two angles with wrap around 中的最佳答案每次测试 + cmets 都是错误的。

底部答案 12>

 math:atan(  (math:sin(180)+math:sin(270)) / (math:cos(180)+math:cos(270))).
-1.1946710584651132

但我得到 -1.946.. 而不是预期的 225。

但是,Erlang 的 math:atan 的行为与 http://rapidtables.com/calc/math/Arctan_Calculator.htm 不同,这会产生不同的结果。

如何求圆中两个角的平均值?

编辑:尝试使用弧度。 度数分别为 180 和 270。

16> A = 180 * 3.14 / 180.
3.14
17> B = 270 * 3.14 / 180.
4.71
18> S = math:sin(A) + math:sin(B).
-0.9984044934712312
19> S2 = S / 2.
-0.4992022467356156
20> C = math:cos(A) + math:cos(B).
-1.002387709839821
21> C2 = C / 2.
-0.5011938549199105
22> math:atan(S, C).
** exception error: undefined function math:atan/2
23> math:atan(S/C).
0.7834073464102068
24> math:atan(S/C) * 180 / 3.14.
44.90870138657236
25> math:atan(S2/C2) * 180 / 3.14.
44.90870138657236

转换: -1.19 度 = -68.18198.3 360 - 68 = 292。这不是预期的 225。

【问题讨论】:

  • 尝试使用弧度。
  • 我尝试使用弧度,请参阅编辑
  • 使用math:atan2(S,C)这会将角度放在正确的象限上。
  • 这给出了数学:atan2(S, C)。 3.1288514248714483。 ~178 度
  • S=-0.9984044934712312C=-1.002387709839821 上面的代码中。 atan2(S,C)=-2.35818 是 -135 度。 -135+360=225

标签: erlang geometry trigonometry


【解决方案1】:

<cos(t), sin(t)> 是角度为t 以弧度表示的单位向量。所以你的公式将两个单位向量相加,然后找到合成向量的角度。

只需使用弧度而不是度数,并使用atan2 而不是atan(将角度放在正确的象限上),您应该会看到您的公式正确运行。

math:atan2( math:sin(t1)+math:sin(t2), math:cos(t1)+math:cos(t2))

这个公式不起作用的地方是,如果两个角度正好相距 180 度。在这种情况下,合成向量是零向量,atan 未定义。

【讨论】:

  • math:atan2( math:sin(180)+math:sin(270), 29> math:cos(180)+math:cos(270))。 -1.1946710584651132。我正在尝试以度数给出答案。
  • 是的。你需要使用弧度,你需要使用atan2。完成后您可以转换回度数。
  • @quantumpotato 如果这对您有用,请考虑接受答案。
  • 请参阅我对原始问题“转换”的编辑。我尝试了您在 cmets 中的建议。如果您有有效的答案,请使用我的示例代码并编辑您的答案
  • @quantumpotato 180 度 = pi 弧度。 270 度 = 3pi/2 弧度。 sin(pi)+sin(3pi/2) = -1。 cos(pi)+cos(3pi/2)=-1。 atan2(-1,-1)=5pi/4 弧度或 225 度。
猜你喜欢
  • 1970-01-01
  • 2010-12-13
  • 1970-01-01
  • 2015-10-23
  • 1970-01-01
  • 1970-01-01
  • 2017-11-06
  • 1970-01-01
  • 2010-12-21
相关资源
最近更新 更多