【发布时间】:2013-03-29 18:57:47
【问题描述】:
我正在尝试制作一个角度程序来计算输入角度的 sin、cos 和 tan。这是我遇到问题的代码部分:
c.println ("You have entered an angle of " + angle + " degrees.");
radians = Math.toRadians (angle); //convert angle (which is in degrees) to radians(radians = (pi / 180)*degrees)
c.println ("The angle in radians is " + radians); //diplay angle in radians
//caluclating sine, cosine & tangent
double sinx = Math.sin (Math.toRadians (angle));
c.println ("The sine of the angle is " + sinx+ " radians."); //convert sin of angle (in deg) to radians
double cosx = Math.cos (Math.toRadians (angle));
c.println ("The cosine of the angle is " + cosx+ " radians.");//convert cos of angle (in deg) to radians
double tanx = Math.tan (Math.toRadians (angle));
c.println ("The tangent of the angle is " + tanx+ " radians.");//convert tan of angle (in deg) to radians
如果我输入一个 90 度的角度,余弦输出是 6.12^-17.... 而它应该只是 = 0。所以某处有计算错误?
【问题讨论】:
-
There's an error in the code是什么意思? -
你遇到了什么错误?
-
什么是样本输入和输出?另外,请注意弧度是从 0-6.28...,而不是 0-2。
-
"The ... of the angle is ... radians."- 不确定打印信息是否不正确,或者您的理解是否正确,但角度的sin/cos/tan不会返回以弧度为单位的数字.sin和cos是[-1,1],tan是[-Inf, Inf]。见this。 -
我试过并用我的计算器检查了它,它会输出所有应该的东西。我没有看到任何错误。
标签: java trigonometry angle