GeoreferencingConversionTest.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/UnitTest/TestTypes.h>
  9. #include <AzTest/AzTest.h>
  10. #include "Clients/GNSSFormatConversions.h"
  11. namespace UnitTest
  12. {
  13. class GeoreferencingConversionTest : public LeakDetectionFixture
  14. {
  15. };
  16. constexpr double OneMillimiter = 0.001; // 1 mm in meters
  17. constexpr double OneMillimeterInDegreesOnEquator = 360.0 / (40000.0 * 1000.0 / OneMillimiter); // 40000 km is the equator length
  18. TEST_F(GeoreferencingConversionTest, WGS84ToECEF)
  19. {
  20. using namespace Georeferencing::WGS;
  21. const AZStd::vector<AZStd::pair<WGS84Coordinate, Vector3d>> inputGoldSet = {
  22. { { 10.0, 20.0, 300.0 }, { 5903307.167667380, 2148628.092761247, 1100300.642188661 } },
  23. { { -70.0, 170.0, 500.0 }, { -2154856.524084172, 379959.3447517005, -5971509.853428957 } },
  24. { { 50.0, -120.0, -100.0 }, { -2053899.906222906, -3557458.991239029, 4862712.433262121 } },
  25. };
  26. for (const auto& [input, goldResult] : inputGoldSet)
  27. {
  28. const auto result = Georeferencing::Utils::GeodeticConversions::WGS84ToECEF(input);
  29. EXPECT_NEAR(result.m_x, goldResult.m_x, OneMillimiter);
  30. EXPECT_NEAR(result.m_y, goldResult.m_y, OneMillimiter);
  31. EXPECT_NEAR(result.m_z, goldResult.m_z, OneMillimiter);
  32. }
  33. }
  34. TEST_F(GeoreferencingConversionTest, ECEFToENU)
  35. {
  36. using namespace Georeferencing::WGS;
  37. const AZStd::vector<AZStd::tuple<Vector3d, WGS84Coordinate, Vector3d>> inputGoldSet = {
  38. { { -2053900.0, -3557459.0, 4862712.0 }, { 50.0, -120.0, -100.0 }, { -0.076833, -0.3202, -0.2969 } },
  39. { { 5903307.167667380, 2148628.092761247, 1100300.642188661 },
  40. { 11.0, 21.0, 400.0 },
  41. { -109638.9539891188, -110428.2398398574, -2004.501240225796 } },
  42. { { -2154856.524084172, 379959.3447517005, -5971509.853428957 },
  43. { -72.0, 169.0, 1000.0 },
  44. { 38187.58712786288, 222803.8182465429, -4497.428919329745 } },
  45. };
  46. for (const auto& [input, refWGS84, goldResult] : inputGoldSet)
  47. {
  48. const auto result = Georeferencing::Utils::GeodeticConversions::ECEFToENU(refWGS84, input);
  49. EXPECT_NEAR(result.m_x, goldResult.m_x, OneMillimiter);
  50. EXPECT_NEAR(result.m_y, goldResult.m_y, OneMillimiter);
  51. EXPECT_NEAR(result.m_z, goldResult.m_z, OneMillimiter);
  52. }
  53. }
  54. TEST_F(GeoreferencingConversionTest, ENUToECEF)
  55. {
  56. using namespace Georeferencing::WGS;
  57. const AZStd::vector<AZStd::tuple<Vector3d, WGS84Coordinate, Vector3d>> inputGoldSet = {
  58. { { -0.076833, -0.3202, -0.2969 }, { 50.0, -120.0, -100.0 }, { -2053900.0, -3557459.0, 4862712.0 } },
  59. { { -109638.9539891188, -110428.2398398574, -2004.501240225796 },
  60. { 11.0, 21.0, 400.0 },
  61. { 5903307.167667380, 2148628.092761247, 1100300.642188661 } },
  62. { { 38187.58712786288, 222803.8182465429, -4497.428919329745 },
  63. { -72.0, 169.0, 1000.0 },
  64. { -2154856.524084172, 379959.3447517005, -5971509.853428957 } },
  65. };
  66. for (const auto& [input, refWGS84, goldResult] : inputGoldSet)
  67. {
  68. const auto result = Georeferencing::Utils::GeodeticConversions::ENUToECEF(refWGS84, input);
  69. EXPECT_NEAR(result.m_x, goldResult.m_x, OneMillimiter);
  70. EXPECT_NEAR(result.m_y, goldResult.m_y, OneMillimiter);
  71. EXPECT_NEAR(result.m_z, goldResult.m_z, OneMillimiter);
  72. }
  73. }
  74. TEST_F(GeoreferencingConversionTest, ECEFToWGS84)
  75. {
  76. using namespace Georeferencing::WGS;
  77. const AZStd::vector<AZStd::pair<Vector3d, WGS84Coordinate>> inputGoldSet = {
  78. { { 5903307.167667380, 2148628.092761247, 1100300.642188661 }, { 10.0, 20.0, 300.0 } },
  79. { { -2154856.524084172, 379959.3447517005, -5971509.853428957 }, { -70.0, 170.0, 500.0 } },
  80. { { -2053899.906222906, -3557458.991239029, 4862712.433262121 }, { 50.0, -120.0, -100.0 } },
  81. };
  82. for (const auto& [input, goldResult] : inputGoldSet)
  83. {
  84. const auto result = Georeferencing::Utils::GeodeticConversions::ECEFToWGS84(input);
  85. EXPECT_NEAR(result.m_longitude, goldResult.m_longitude, OneMillimeterInDegreesOnEquator);
  86. EXPECT_NEAR(result.m_latitude, goldResult.m_latitude, OneMillimeterInDegreesOnEquator);
  87. EXPECT_NEAR(result.m_altitude, goldResult.m_altitude, OneMillimiter);
  88. }
  89. }
  90. } // namespace UnitTest