角度用什么变量类型?
比方说要用arctan(y/x)计算出来的角度要存储,然后要判断在-90°到90°之间的哪个区间,如何做?谢谢啦!
[解决办法]
函数名称: atan2
函数原型: double atan2(double x,double y);
函数功能: 计算tan^-1/(x/y)的值.求x/y的反正切值.
函数返回: 计算结果
参数说明: 单位为弧度
所属文件: <math.h>
使用范例:
#include <stdio.h>
#include <math.h>
int main()
{
double result;
double x=90.0,y=45.0;
result=atan2(y,x);
printf( "The arc tangent ratio of %lf is %lf ",(y/x),result);
return 0;
}
[解决办法]
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
int main()
{
double x =0;
double y=0;
printf( "Please input x and y: ");
scanf( "%lf %lf ", &x, &y);
// atan2(y,x)返回弧度值在(-pi, pi)之间。
double degree = atan2( y, x );
// 将弧度转为角度
degree = degree / M_PI * 180.0;
// 输出角度
printf( "arctan(%g, %g)= %g \n ", y, x, degree);
system( "pause ");
}