首页 > 编程知识 正文

直角坐标转极坐标积分上下限,直角坐标转极坐标公式

时间:2023-05-06 11:27:28 阅读:258211 作者:767

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;};//prototypepolar rect_to_polar (rect xypos);void show_polar(polar dapos);#endif // file1.cpp# include <iostream># include "coordin.h" //structure templates,function prototypesusing 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># include <cmath># include "coordin.h" //structure template ,function prototypes//convert rectangular to polar coordinates 直角坐标转换成极坐标polar rect_to_polar(rect xypos){using namespace std ;polar answer;answer.distance =sqrt(xypos.x * xypos.x + xypos.y * xypos.y);answer.angle = atan2(xypos.y,xypos.x);return answer; //return a polar strucutre}//show polar coordinates,convert angle to degressvoid show_polar(polar dapos){ using namespace std; const double Rad_to_deg = 57.29577951; cout<<"distance = "<<dapos.distance; cout<<", angle = "<<dapos.angle * Rad_to_deg; cout<<" degreesn";}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。