直角坐标转极坐标

#include
#include
using namespace std;
struct rext		//直角坐标系
{double x;double y;
};
struct polar	//极坐标系
{double distance;double angle;
};
void rect_to_polar(const rext*pxy, polar *pda)
{pda->distance = sqrt(pxy->x * pxy->x + pxy->y * pxy->y);pda->angle = atan2(pxy->y, pxy->x);
}
void show_polar(const polar * pda)
{const double Red_to_deg = 57.29577951;cout << "distance = " << pda->distance << endl;cout << "angle = " << pda->angle*Red_to_deg << endl;
}
int main()
{rext rplace;polar pplace;cout << "Enter the x and y :";while (cin >> rplace.x >> rplace.y){rect_to_polar( &rplace, &pplace);show_polar(&pplace);cin.get();}cin.get();return 0;
}

 


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部