CS.cpp 836 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "pch.h"
  2. #include "CS.h"
  3. #include <math.h>
  4. CS::CS() {
  5. }
  6. CS::~CS()
  7. {
  8. }
  9. // 直角坐标系 -> 球坐标系
  10. void CS::CartesianToSpherical(CoordCartesian &pcc, CoordSpherical &pcg)
  11. {
  12. pcg.r = sqrt(pcc.x*pcc.x + pcc.y*pcc.y + pcc.z*pcc.z);
  13. pcg.θ = atan2l(pcc.y, pcc.x) * 180 / PI;
  14. DOUBLE xy2 = pcc.x*pcc.x + pcc.y*pcc.y;
  15. if (xy2 > 0){
  16. pcg.φ = atan(pcc.z / sqrt(pcc.x*pcc.x + pcc.y*pcc.y)) * 180 / PI;
  17. }
  18. else {
  19. pcg.φ = 0;
  20. }
  21. }
  22. // 直角坐标系 -> 柱坐标系
  23. void CS::CartesianToCylindrical(CoordCartesian &pcc, CoordCylindrical &pcy)
  24. {
  25. DOUBLE at = atan2l(pcc.y, pcc.x);
  26. if (at != 0)
  27. pcy.r = pcc.x / (atan2l(pcc.y, pcc.x) * 180 / PI);
  28. else
  29. pcy.r = 0;
  30. pcy.θ = atan2l(pcc.y , pcc.x) * 180 / PI;
  31. pcy.z = pcc.z;
  32. }
  33. // 点包络值
  34. DOUBLE CS::EnvelopeValue(DOUBLE x, DOUBLE y)
  35. {
  36. return sqrt(x * x + y * y);
  37. }