From 8ae973c4cb4ebf4fd27ed65cbc3831098b790d2e Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sat, 10 Feb 2024 00:08:13 -0600 Subject: [PATCH] Utility function to get geographic coordinate from i and j --- .../source/scwx/qt/util/geographic_lib.cpp | 21 +++++++++++++++++++ .../source/scwx/qt/util/geographic_lib.hpp | 13 ++++++++++++ 2 files changed, 34 insertions(+) diff --git a/scwx-qt/source/scwx/qt/util/geographic_lib.cpp b/scwx-qt/source/scwx/qt/util/geographic_lib.cpp index 8582d21c..20323eb8 100644 --- a/scwx-qt/source/scwx/qt/util/geographic_lib.cpp +++ b/scwx-qt/source/scwx/qt/util/geographic_lib.cpp @@ -1,6 +1,8 @@ #include #include +#include + #include #include #include @@ -90,6 +92,25 @@ GetAngle(double lat1, double lon1, double lat2, double lon2) return units::angle::degrees {azi1}; } +common::Coordinate GetCoordinate(const common::Coordinate& center, + units::meters i, + units::meters j) +{ + // Calculate polar coordinates based on i and j + const double angle = + std::atan2(i.value(), j.value()) * 180.0 / std::numbers::pi; + const double range = + std::sqrt(i.value() * i.value() + j.value() * j.value()); + + double latitude; + double longitude; + + DefaultGeodesic().Direct( + center.latitude_, center.longitude_, angle, range, latitude, longitude); + + return {latitude, longitude}; +} + units::length::meters GetDistance(double lat1, double lon1, double lat2, double lon2) { diff --git a/scwx-qt/source/scwx/qt/util/geographic_lib.hpp b/scwx-qt/source/scwx/qt/util/geographic_lib.hpp index 66b4f42b..7f3f64bd 100644 --- a/scwx-qt/source/scwx/qt/util/geographic_lib.hpp +++ b/scwx-qt/source/scwx/qt/util/geographic_lib.hpp @@ -49,6 +49,19 @@ bool AreaContainsPoint(const std::vector& area, units::angle::degrees GetAngle(double lat1, double lon1, double lat2, double lon2); +/** + * Get a coordinate from an (i, j) offset. + * + * @param [in] center The center coordinate from which i and j are offset + * @param [in] i The easting offset in meters + * @param [in] j The northing offset in meters + * + * @return offset coordinate + */ +common::Coordinate GetCoordinate(const common::Coordinate& center, + units::meters i, + units::meters j); + /** * Get the distance between two points. *