直角坐标转极坐标

矫情吗;* 2022-06-12 01:39 257阅读 0赞
  1. #include<iostream>
  2. #include<cmath>
  3. using namespace std;
  4. struct rext //直角坐标系
  5. {
  6. double x;
  7. double y;
  8. };
  9. struct polar //极坐标系
  10. {
  11. double distance;
  12. double angle;
  13. };
  14. void rect_to_polar(const rext*pxy, polar *pda)
  15. {
  16. pda->distance = sqrt(pxy->x * pxy->x + pxy->y * pxy->y);
  17. pda->angle = atan2(pxy->y, pxy->x);
  18. }
  19. void show_polar(const polar * pda)
  20. {
  21. const double Red_to_deg = 57.29577951;
  22. cout << "distance = " << pda->distance << endl;
  23. cout << "angle = " << pda->angle*Red_to_deg << endl;
  24. }
  25. int main()
  26. {
  27. rext rplace;
  28. polar pplace;
  29. cout << "Enter the x and y :";
  30. while (cin >> rplace.x >> rplace.y)
  31. {
  32. rect_to_polar( &rplace, &pplace);
  33. show_polar(&pplace);
  34. cin.get();
  35. }
  36. cin.get();
  37. return 0;
  38. }

发表评论

表情:
评论列表 (有 0 条评论,257人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Matlab坐标画图

    Matlab极坐标画图 在Matlab中,我们可以使用极坐标来绘制各种有趣的图形。极坐标是一种使用极径和极角来描述点位置的坐标系统,它可以用来表示圆形、螺旋线等形状。本文将介