meridian_convergence_angle_correction_test.cpp 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // BSD 3-Clause License
  2. //
  3. // Copyright (c) 2023, Map IV, Inc.
  4. // All rights reserved.
  5. //
  6. // Redistribution and use in source and binary forms, with or without
  7. // modification, are permitted provided that the following conditions are met:
  8. //
  9. // 1. Redistributions of source code must retain the above copyright notice, this
  10. // list of conditions and the following disclaimer.
  11. //
  12. // 2. Redistributions in binary form must reproduce the above copyright notice,
  13. // this list of conditions and the following disclaimer in the documentation
  14. // and/or other materials provided with the distribution.
  15. //
  16. // 3. Neither the name of the copyright holder nor the names of its
  17. // contributors may be used to endorse or promote products derived from
  18. // this software without specific prior written permission.
  19. //
  20. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23. // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  24. // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  26. // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  27. // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. #include "llh_converter/meridian_convergence_angle_correction.hpp"
  31. #include "llh_converter/llh_converter.hpp"
  32. #include <iostream>
  33. #include <iomanip>
  34. void test(const double& result, const double& answer)
  35. {
  36. double diff = std::abs(result - answer);
  37. double diff_theres = 0.0001;
  38. if (diff < diff_theres)
  39. {
  40. std::cout << "\033[32;1mTEST SUCCESS: |(" << result << ") - (" << answer << ")| = " << diff << "< " << diff_theres << "\033[m" << std::endl;
  41. }
  42. else
  43. {
  44. std::cout << "\033[31;1mTEST FAILED: |(" << result << ") - (" << answer << ")| = " << diff << ">= " << diff_theres << "\033[m" << std::endl;
  45. }
  46. }
  47. void meridian_convergence_angle_correction_test(const double& test_lat, const double& test_lon, const double& answered_angle,
  48. llh_converter::LLHConverter &llh_converter, const llh_converter::LLHParam &param
  49. )
  50. {
  51. llh_converter::LLA lla;
  52. llh_converter::XYZ xyz;
  53. lla.latitude = test_lat;
  54. lla.longitude = test_lon;
  55. lla.altitude = 30.0;
  56. // convert lla to xyz
  57. llh_converter.convertDeg2XYZ(lla.latitude, lla.longitude, lla.altitude, xyz.x, xyz.y, xyz.z, param);
  58. // get meridian convergence angle
  59. double mca = llh_converter::getMeridianConvergence(lla, xyz, llh_converter, param);
  60. std::cout << "-------------------------------------------------------------------------------------" << std::endl;
  61. std::cout << "Testing LatLon (" << std::setw(6) << test_lat << ", " << std::setw(6) << test_lat << ") ... " << std::endl;
  62. std::cout << "Calcalated Meridian Convergence Angle (" << mca << ")" << std::endl;
  63. test(llh_converter::rad2deg(mca), answered_angle);
  64. }
  65. int main(int argc, char** argv)
  66. {
  67. // Meridian Convergence Angle Correction Test
  68. llh_converter::LLHConverter llh_converter;
  69. llh_converter::LLHParam param;
  70. param.use_mgrs = false;
  71. param.plane_num = 7;
  72. param.height_convert_type = llh_converter::ConvertType::NONE;
  73. param.geoid_type = llh_converter::GeoidType::EGM2008;
  74. // ref: Conversion to plane rectangular coordinates(in Japanse)
  75. // https://vldb.gsi.go.jp/sokuchi/surveycalc/surveycalc/bl2xyf.html
  76. // nagoya city ueda
  77. double test_lat = 35.141168610, test_lon = 136.989591759;
  78. double answered_angle = -0.101925000; // [deg]
  79. meridian_convergence_angle_correction_test(test_lat, test_lon, answered_angle, llh_converter, param);
  80. // nagoya city ozone
  81. double test_lat2 = 35.188843433, test_lon2 = 136.943096063;
  82. double answered_angle2 = -0.128838889; // [deg]
  83. meridian_convergence_angle_correction_test(test_lat2, test_lon2, answered_angle2, llh_converter, param);
  84. return 0;
  85. }