NumCpp  2.14.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
ECEFtoLLA.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <cmath>
31
37#include "NumCpp/Utils/sqr.hpp"
38
40{
50 {
51 constexpr int MAX_ITER = 10;
54
55 const auto p = std::hypot(ecef.x, ecef.y);
56 const auto lon = std::atan2(ecef.y, ecef.x);
57
58 double alt = 0.0;
59 double lat = 0.0;
60
61 if (p < tol)
62 {
63 lat = sign(ecef.z) * constants::pi / 2.;
65 }
66 else
67 {
68 // Iteratively update latitude and altitude.
69 // This is expected to converge in ~4 iterations, but apply a maximum number of iterations incase tol is
70 // too small
71 double err = 1.0;
72 int iter = 0;
73 while (err > tol && iter < MAX_ITER)
74 {
76 std::sqrt(1 - E_SQR * utils::sqr(std::sin(lat)));
77 lat = std::atan((ecef.z / p) / (1 - (N * E_SQR / (N + alt))));
78 double newAlt = (p / std::cos(lat)) - N;
79 err = std::abs(alt - newAlt);
80 alt = newAlt;
81 iter++;
82 }
83 }
84 return { lat, lon, alt };
85 }
86} // namespace nc::coordinates::transforms
ECEF coordinates.
Definition ECEF.hpp:40
Geodetic coordinates.
Definition LLA.hpp:40
constexpr double pi
Pi.
Definition Core/Constants.hpp:39
constexpr double EARTH_POLAR_RADIUS
Definition Coordinates/ReferenceFrames/Constants.hpp:33
constexpr double EARTH_EQUATORIAL_RADIUS
Definition Coordinates/ReferenceFrames/Constants.hpp:34
Definition AERtoECEF.hpp:38
reference_frames::LLA ECEFtoLLA(const reference_frames::ECEF &ecef, double tol=1e-8) noexcept
Converts ECEF coordinates to LLA https://en.wikipedia.org/wiki/Geographic_coordinate_conversion#From_...
Definition ECEFtoLLA.hpp:49
constexpr dtype sqr(dtype inValue) noexcept
Definition sqr.hpp:42
int8 sign(dtype inValue) noexcept
Definition sign.hpp:52
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59