平均2个角度,360度环绕

时间:2017-11-04 02:49:43

标签: erlang geometry trigonometry

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

底部答案12>

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

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

根据http://rapidtables.com/calc/math/Arctan_Calculator.htm,Erlang math:atan的行为并不正常,但会产生不同的结果。

如何在圆圈中找到2个角度的平均值?

编辑:尝试使用Radians。 学位是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。

1 个答案:

答案 0 :(得分:2)

<cos(t), sin(t)>是角度为t 的单位向量,以弧度为单位。因此,您的公式会添加两个单位向量,然后找到合成向量的角度。

只需使用弧度而不是度数,然后使用atan2代替atan(将角度放在正确的象限上),您应该看到您的公式正常工作。

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

此公式不起作用的是两个角度彼此精确相差180度。在这种情况下,结果向量是零向量,atan未定义。