1 atan2的用法 :atna2(y,x)求出原点与x轴的夹角(-π,π]
atan : atan(y/x) 取值范围为(-1/2π,1/2π)
atan2比 atan稳定
2 Rad_to_deg = 57.29577951 弧度转角度
3example:
// coordin.h
# ifndef COORDIN_H_
# define COORDIN_H_
struct polar
{
double distance ;
double angle;
};
struct rect
{
double x;
double y;
};
//prototype
polar rect_to_polar (rect xypos);
void show_polar(polar dapos);
#endif
// file1.cpp
# include <iostream>
# include "coordin.h" //structure templates,function prototypes
using namespace std;
int main()
{
rect rplace;
polar pplace;
cout<<"Enter the x and y values:";
while (cin>>rplace.x>>rplace.y) //slick use of cin
{
pplace = rect_to_polar(rplace);
show_polar(pplace);
cout<<"Text two numbers (q to quit ): ";
}
cout<<"Bye!\n";
return 0;
}
// file2.cpp
# include <iostream>
# inclu