blh2xyz.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // Academic License - for use in teaching, academic research, and meeting
  3. // course requirements at degree granting institutions only. Not for
  4. // government, commercial, or other organizational use.
  5. // File: blh2xyz.cpp
  6. //
  7. // MATLAB Coder version : 5.3
  8. // C/C++ source code generated on : 04-Apr-2023 15:36:25
  9. //
  10. // Include Files
  11. #include "blh2xyz.h"
  12. #include <cmath>
  13. // Function Definitions
  14. //
  15. // Example:
  16. // (BLh)WGS84-(XYZ)WGS84
  17. // LAT = 40.9987167395335;
  18. // LON = 39.7652393428761;
  19. // h = 51.403;
  20. //
  21. // Arguments : double LAT
  22. // double LON
  23. // double h
  24. // double *X
  25. // double *Y
  26. // double *Z
  27. // Return Type : void
  28. //
  29. void blh2xyz(double LAT, double LON, double h, double *X, double *Y, double *Z)
  30. {
  31. double N;
  32. double a_tmp;
  33. double lat;
  34. double lon;
  35. // WGS84
  36. lat = LAT * 3.1415926535897931 / 180.0;
  37. lon = LON * 3.1415926535897931 / 180.0;
  38. a_tmp = std::sin(lat);
  39. N = 6.378137E+6 / std::sqrt(1.0 - 0.0066943799902085318 * (a_tmp * a_tmp));
  40. lat = (N + h) * std::cos(lat);
  41. *X = lat * std::cos(lon);
  42. *Y = lat * std::sin(lon);
  43. *Z = (N * 0.9933056200097915 + h) * a_tmp;
  44. }
  45. //
  46. // File trailer for blh2xyz.cpp
  47. //
  48. // [EOF]
  49. //