fun10_distcal.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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: distcal.cpp
  6. //
  7. // MATLAB Coder version : 5.3
  8. // C/C++ source code generated on : 27-Mar-2023 15:34:32
  9. //
  10. // Include Files
  11. #include "fun10_distcal.h"
  12. #include "rt_nonfinite.h"
  13. #include <cmath>
  14. // Function Definitions
  15. //
  16. // DISTCAL 计算距离
  17. // 此处显示详细说明
  18. //
  19. // Arguments : const double PlatA_data[]
  20. // const int PlatA_size[2]
  21. // const double PlatB_data[]
  22. // const int PlatB_size[2]
  23. // Return Type : double
  24. //
  25. double b_distcal(const double PlatA_data[], const int PlatA_size[2],
  26. const double PlatB_data[], const int PlatB_size[2])
  27. {
  28. double dist;
  29. dist = 0.0;
  30. if (PlatA_size[1] == PlatB_size[1]) {
  31. if (PlatA_size[1] == 2) {
  32. double a;
  33. double b_a;
  34. a = PlatA_data[0] - PlatB_data[0];
  35. b_a = PlatA_data[1] - PlatB_data[1];
  36. dist = std::sqrt(a * a + b_a * b_a);
  37. } else if (PlatA_size[1] == 3) {
  38. double a;
  39. double b_a;
  40. a = PlatA_data[0] - PlatB_data[0];
  41. b_a = PlatA_data[1] - PlatB_data[1];
  42. dist = std::sqrt(a * a + b_a * b_a);
  43. }
  44. } else {
  45. dist = -1.0;
  46. }
  47. return dist;
  48. }
  49. //
  50. // DISTCAL 计算距离
  51. // 此处显示详细说明
  52. //
  53. // Arguments : const double PlatA_data[]
  54. // const int PlatA_size[2]
  55. // const double PlatB_data[]
  56. // const int PlatB_size[2]
  57. // Return Type : double
  58. //
  59. double distcal(const double PlatA_data[], const int PlatA_size[2],
  60. const double PlatB_data[], const int PlatB_size[2])
  61. {
  62. double dist;
  63. dist = 0.0;
  64. if (PlatA_size[1] == PlatB_size[1]) {
  65. if (PlatA_size[1] == 2) {
  66. double a;
  67. double b_a;
  68. a = PlatA_data[0] - PlatB_data[0];
  69. b_a = PlatA_data[1] - PlatB_data[1];
  70. dist = std::sqrt(a * a + b_a * b_a);
  71. } else if (PlatA_size[1] == 3) {
  72. double a;
  73. double b_a;
  74. a = PlatA_data[0] - PlatB_data[0];
  75. b_a = PlatA_data[1] - PlatB_data[1];
  76. dist = std::sqrt(a * a + b_a * b_a);
  77. }
  78. } else {
  79. dist = -1.0;
  80. }
  81. return dist;
  82. }
  83. //
  84. // File trailer for distcal.cpp
  85. //
  86. // [EOF]
  87. //