【发布时间】:2013-08-28 01:49:41
【问题描述】:
我试图计算直角三角形的角度值。侧面是相反的,斜边也恰好与角度相邻。用 Java 编写的一段代码使用 atan2 来获取角度。当我在 C 中使用 atan2 时,我得到了不同的值。我获得正确值的唯一方法是使用 asin。
这是C语言中的sn-p代码:
for(i = 0; i < n; i++)
{
m = sqrt( (x - l[i].x) * (x - l[i].x) + (y * y) );
dist = abs(x - l[i].x);
ang = asin(dist/m) * 180.0 / 3.14159265;
if(ang <= (l[i].a + .01))
total += (double) l[i].I/(m*m);
}
这是Java中的sn-p代码:
for (j = 0; j < n; j++)
{
d = Math.sqrt( (xs - lights[j]) * (xs - lights[j]) + (ys * ys) );
w = Math.abs(xs - lights[j]);
ang = Math.atan2(w, ys) * 180.0 / 3.14159265;
if (ang <= angles[j] + 0.01)
{
total += (double ) intensities[j] / (d * d);
}
}
谁能解释一下这个问题?
【问题讨论】:
-
因为 atan2 != asin !!
-
但是在 Java 中使用 atan2 给了我与在 C 中使用 asin 相同的角度。为什么?!在 C 中使用 atan2 给了我与在 Java 中使用 atan2 不同的角度。为什么?!
标签: trigonometry atan2