从弧度到度的转换
我正在尝试用 C++ 进行简单的三角计算。以下是我遇到的问题的示例。据我所知,C++ 以弧度为单位,而不是度数。因此,从弧度到度数的转换应该是乘以 180 再除以 pi 的简单情况。一个简单的测试是 tan(45),它应该等于 1。但是,以下程序生成的值是 92.8063...
#include <iostream>
using namespace std;
#include <math.h>
int main(){
double a,b;
a = tan(45);
b = a * 180 / 3.14159265;
cout << b;
return 0;
}
出了什么问题?
I am trying to do a simple trigonometric calculation in C++. The following is an example of the problem I am having with this. As far as I know, C++ works in radians, not degrees. So conversion from radians to degrees should be a simple case of multiplying by 180 and dividing by pi. A simple test is tan(45), which should equate 1. The following program produces a value of 92.8063 however...
#include <iostream>
using namespace std;
#include <math.h>
int main(){
double a,b;
a = tan(45);
b = a * 180 / 3.14159265;
cout << b;
return 0;
}
What is wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你这是在倒退。不要将公式应用于
tan
的输出,而是将其应用于参数。此外,您还需要乘以 pi 再除以 180,而不是相反。
You're doing it backwards. Don't apply the formula to the output of
tan
, apply it to the parameter.Also you'll want to multiply by pi and divide by 180, not vice versa.
角度是
tan
的输入。所以你想要:The angle is the input to
tan
. So you want:您必须将弧度传递给 tan 函数。角度到弧度也是错误的。
You must pass radians to the tan function. Also degrees to radian is wrong.
Tan接受一个角度,并返回一个商。 不是相反。你想要
Tan accepts an angle, and returns a quotient. It is not the other way around. You want