isce3 0.25.0
Loading...
Searching...
No Matches
Ellipsoid.h
1// -*- C++ -*-
2// -*- coding: utf-8 -*-
3//
4// Author: Joshua Cohen, Bryan V. Riel
5// Copyright 2017-2018
6//
7
8#pragma once
9
10#include "forward.h"
11
12#include <cstdio>
13#include <cmath>
14#include "Constants.h"
15#include "Vector.h"
16
21
22 public:
27 CUDA_HOSTDEV
28 Ellipsoid(double maj, double ecc) : _a(maj), _e2(ecc) {}
29
31 /* Empty constructor - default to Earth WGS-84 ellipsoid */
32 CUDA_HOSTDEV
33 Ellipsoid() : Ellipsoid(EarthSemiMajorAxis, EarthEccentricitySquared) {}
35
37 CUDA_HOSTDEV
38 double a() const {return _a;}
39
41 CUDA_HOSTDEV
42 double b() const {return _a * std::sqrt(1.0 - _e2);}
43
45 CUDA_HOSTDEV
46 double e2() const {return _e2;}
47
51 void a(double val) {_a = val;}
52
56 void e2(double val) {_e2 = val;}
57
59 CUDA_HOSTDEV
60 inline double rEast(double lat) const;
61
63 CUDA_HOSTDEV
64 inline double rNorth(double lat) const;
65
67 CUDA_HOSTDEV
68 inline double rDir(double hdg, double lat) const;
69
71 CUDA_HOSTDEV
72 void lonLatToXyz(const cartesian_t &llh, cartesian_t &xyz) const;
73 CUDA_HOSTDEV Vec3 lonLatToXyz(const Vec3& llh) const {
74 Vec3 xyz;
75 lonLatToXyz(llh, xyz);
76 return xyz;
77 }
78
80 CUDA_HOSTDEV
81 void xyzToLonLat(const cartesian_t &xyz, cartesian_t &llh) const;
82 CUDA_HOSTDEV Vec3 xyzToLonLat(const Vec3& xyz) const {
83 Vec3 llh;
84 xyzToLonLat(xyz, llh);
85 return llh;
86 }
87
89 CUDA_HOSTDEV
90 inline void nVector(double lon, double lat, cartesian_t &vec) const;
91 CUDA_HOSTDEV
92 inline Vec3 nVector(double lon, double lat) const {
93 Vec3 result;
94 nVector(lon, lat, result);
95 return result;
96 }
97
99 CUDA_HOSTDEV
100 inline void xyzOnEllipse(double lon, double lat, cartesian_t &xyz) const;
101
103 void getImagingAnglesAtPlatform(const cartesian_t &pos,const cartesian_t &vel,
104 const cartesian_t &los, double &azi, double &look) const;
105
106 private:
107 double _a;
108 double _e2;
109
110};
111
112
116CUDA_HOSTDEV
117double isce3::core::Ellipsoid::rEast(double lat) const {
118 // Radius of Ellipsoid in East direction (assuming latitude-wise symmetry)
119 return _a / std::sqrt(1.0 - (_e2 * std::pow(std::sin(lat), 2)));
120}
121
122
126CUDA_HOSTDEV
127double isce3::core::Ellipsoid::rNorth(double lat) const {
128 // Radius of Ellipsoid in North direction (assuming latitude-wise symmetry)
129 return (_a * (1.0 - _e2)) / std::pow((1.0 - (_e2 * std::pow(std::sin(lat), 2))), 1.5);
130}
131
137CUDA_HOSTDEV
138double isce3::core::Ellipsoid::rDir(double hdg, double lat) const {
139 auto re = rEast(lat);
140 auto rn = rNorth(lat);
141 return (re * rn) / ((re * std::pow(std::cos(hdg), 2))
142 + (rn * std::pow(std::sin(hdg), 2)));
143}
144
145
151CUDA_HOSTDEV
152void isce3::core::Ellipsoid::nVector(double lon, double lat, cartesian_t &vec) const
153{
154 double clat = std::cos(lat);
155 vec[0] = clat * std::cos(lon);
156 vec[1] = clat * std::sin(lon);
157 vec[2] = std::sin(lat);
158}
159
160
166CUDA_HOSTDEV
167void isce3::core::Ellipsoid::xyzOnEllipse(double lon, double lat, cartesian_t &vec) const
168{
169 nVector(lon, lat, vec);
170 vec[0] *= _a;
171 vec[1] *= _a;
172 vec[2] *= b();
173}
174
177CUDA_HOSTDEV inline void isce3::core::Ellipsoid::
178lonLatToXyz(const cartesian_t & llh, cartesian_t & xyz) const {
179 /*
180 * Given a lat, lon, and height, produces a geocentric vector.
181 */
182
183 // Radius of Earth in East direction
184 auto re = rEast(llh[1]);
185 // Parametric representation of a circle as a function of longitude
186 xyz[0] = (re + llh[2]) * std::cos(llh[1]) * std::cos(llh[0]);
187 xyz[1] = (re + llh[2]) * std::cos(llh[1]) * std::sin(llh[0]);
188 // Parametric representation with the radius adjusted for eccentricity
189 xyz[2] = ((re * (1.0 - _e2)) + llh[2]) * std::sin(llh[1]);
190}
191
196CUDA_HOSTDEV inline void isce3::core::Ellipsoid::
197xyzToLonLat(const cartesian_t & xyz, cartesian_t & llh) const {
198 /*
199 * Given a geocentric XYZ, produces a lat, lon, and height above the reference ellipsoid.
200 * VERMEILLE IMPLEMENTATION
201 */
202 // Pre-compute some values
203 const double e4 = _e2 * _e2;
204 const double a2 = _a * _a;
205 // Lateral distance normalized by the major axis
206 double p = (std::pow(xyz[0], 2) + std::pow(xyz[1], 2)) / a2;
207 // Polar distance normalized by the minor axis
208 double q = ((1. - _e2) * std::pow(xyz[2], 2)) / a2;
209 double r = (p + q - e4) / 6.;
210 double s = (e4 * p * q) / (4. * std::pow(r, 3));
211 double t = std::pow(1. + s + std::sqrt(s * (2. + s)), (1./3.));
212 double u = r * (1. + t + (1. / t));
213 double rv = std::sqrt(std::pow(u, 2) + (e4 * q));
214 double w = (_e2 * (u + rv - q)) / (2. * rv);
215 double k = std::sqrt(u + rv + std::pow(w, 2)) - w;
216 // Radius adjusted for eccentricity
217 double d = (k * std::sqrt(std::pow(xyz[0], 2) + std::pow(xyz[1], 2))) / (k + _e2);
218 // Latitude is a function of z and radius
219 llh[1] = std::atan2(xyz[2], d);
220 // Longitude is a function of x and y
221 llh[0] = std::atan2(xyz[1], xyz[0]);
222 // Height is a function of location and radius
223 llh[2] = ((k + _e2 - 1.) * sqrt(std::pow(d, 2) + std::pow(xyz[2], 2))) / k;
224}
Data structure to store Ellipsoid information.
Definition Ellipsoid.h:20
void a(double val)
Set semi-major axis.
Definition Ellipsoid.h:51
CUDA_HOSTDEV double rNorth(double lat) const
Return local radius in NS direction.
Definition Ellipsoid.h:127
CUDA_HOSTDEV void xyzToLonLat(const cartesian_t &xyz, cartesian_t &llh) const
Transform ECEF xyz to Lon/Lat/Hgt.
Definition Ellipsoid.h:197
CUDA_HOSTDEV Ellipsoid(double maj, double ecc)
Constructor using semi-major axis and eccentricity^2.
Definition Ellipsoid.h:28
CUDA_HOSTDEV double a() const
Return semi-major axis.
Definition Ellipsoid.h:38
void getImagingAnglesAtPlatform(const cartesian_t &pos, const cartesian_t &vel, const cartesian_t &los, double &azi, double &look) const
Estimate azimuth angle and look angle for a given LOS vector.
Definition Ellipsoid.cpp:23
void e2(double val)
Set eccentricity^2.
Definition Ellipsoid.h:56
CUDA_HOSTDEV void xyzOnEllipse(double lon, double lat, cartesian_t &xyz) const
Return ECEF coordinates of point on ellipse.
Definition Ellipsoid.h:167
CUDA_HOSTDEV double e2() const
Return eccentricity^2.
Definition Ellipsoid.h:46
CUDA_HOSTDEV void nVector(double lon, double lat, cartesian_t &vec) const
Return normal to the ellipsoid at given lon, lat.
Definition Ellipsoid.h:152
CUDA_HOSTDEV void lonLatToXyz(const cartesian_t &llh, cartesian_t &xyz) const
Transform WGS84 Lon/Lat/Hgt to ECEF xyz.
Definition Ellipsoid.h:178
CUDA_HOSTDEV double b() const
Return semi-minor axis.
Definition Ellipsoid.h:42
CUDA_HOSTDEV double rEast(double lat) const
Return local radius in EW direction.
Definition Ellipsoid.h:117
CUDA_HOSTDEV double rDir(double hdg, double lat) const
Return directional local radius.
Definition Ellipsoid.h:138

Generated for ISCE3.0 by doxygen 1.13.2.