isce3  0.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
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
35 
37  Ellipsoid(const Ellipsoid & ellps) : _a(ellps.a()), _e2(ellps.e2()) {}
38 
40  inline Ellipsoid& operator=(const Ellipsoid&);
41 
43  CUDA_HOSTDEV
44  double a() const {return _a;}
45 
47  CUDA_HOSTDEV
48  double b() const {return _a * std::sqrt(1.0 - _e2);}
49 
51  CUDA_HOSTDEV
52  double e2() const {return _e2;}
53 
57  void a(double val) {_a = val;}
58 
62  void e2(double val) {_e2 = val;}
63 
65  CUDA_HOSTDEV
66  inline double rEast(double lat) const;
67 
69  CUDA_HOSTDEV
70  inline double rNorth(double lat) const;
71 
73  CUDA_HOSTDEV
74  inline double rDir(double hdg, double lat) const;
75 
77  CUDA_HOSTDEV
78  void lonLatToXyz(const cartesian_t &llh, cartesian_t &xyz) const;
79  CUDA_HOSTDEV Vec3 lonLatToXyz(const Vec3& llh) const {
80  Vec3 xyz;
81  lonLatToXyz(llh, xyz);
82  return xyz;
83  }
84 
86  CUDA_HOSTDEV
87  void xyzToLonLat(const cartesian_t &xyz, cartesian_t &llh) const;
88  CUDA_HOSTDEV Vec3 xyzToLonLat(const Vec3& xyz) const {
89  Vec3 llh;
90  xyzToLonLat(xyz, llh);
91  return llh;
92  }
93 
95  CUDA_HOSTDEV
96  inline void nVector(double lon, double lat, cartesian_t &vec) const;
97  CUDA_HOSTDEV
98  inline Vec3 nVector(double lon, double lat) const {
99  Vec3 result;
100  nVector(lon, lat, result);
101  return result;
102  }
103 
105  CUDA_HOSTDEV
106  inline void xyzOnEllipse(double lon, double lat, cartesian_t &xyz) const;
107 
109  void getImagingAnglesAtPlatform(const cartesian_t &pos,const cartesian_t &vel,
110  const cartesian_t &los, double &azi, double &look) const;
111 
112  private:
113  double _a;
114  double _e2;
115 };
116 
118  _a = rhs.a();
119  _e2 = rhs.e2();
120  return *this;
121 }
122 
126 CUDA_HOSTDEV
127 double isce3::core::Ellipsoid::rEast(double lat) const {
128  // Radius of Ellipsoid in East direction (assuming latitude-wise symmetry)
129  return _a / std::sqrt(1.0 - (_e2 * std::pow(std::sin(lat), 2)));
130 }
131 
132 
136 CUDA_HOSTDEV
137 double isce3::core::Ellipsoid::rNorth(double lat) const {
138  // Radius of Ellipsoid in North direction (assuming latitude-wise symmetry)
139  return (_a * (1.0 - _e2)) / std::pow((1.0 - (_e2 * std::pow(std::sin(lat), 2))), 1.5);
140 }
141 
147 CUDA_HOSTDEV
148 double isce3::core::Ellipsoid::rDir(double hdg, double lat) const {
149  auto re = rEast(lat);
150  auto rn = rNorth(lat);
151  return (re * rn) / ((re * std::pow(std::cos(hdg), 2))
152  + (rn * std::pow(std::sin(hdg), 2)));
153 }
154 
155 
161 CUDA_HOSTDEV
162 void isce3::core::Ellipsoid::nVector(double lon, double lat, cartesian_t &vec) const
163 {
164  double clat = std::cos(lat);
165  vec[0] = clat * std::cos(lon);
166  vec[1] = clat * std::sin(lon);
167  vec[2] = std::sin(lat);
168 }
169 
170 
176 CUDA_HOSTDEV
177 void isce3::core::Ellipsoid::xyzOnEllipse(double lon, double lat, cartesian_t &vec) const
178 {
179  nVector(lon, lat, vec);
180  vec[0] *= _a;
181  vec[1] *= _a;
182  vec[2] *= b();
183 }
184 
187 CUDA_HOSTDEV inline void isce3::core::Ellipsoid::
188 lonLatToXyz(const cartesian_t & llh, cartesian_t & xyz) const {
189  /*
190  * Given a lat, lon, and height, produces a geocentric vector.
191  */
192 
193  // Radius of Earth in East direction
194  auto re = rEast(llh[1]);
195  // Parametric representation of a circle as a function of longitude
196  xyz[0] = (re + llh[2]) * std::cos(llh[1]) * std::cos(llh[0]);
197  xyz[1] = (re + llh[2]) * std::cos(llh[1]) * std::sin(llh[0]);
198  // Parametric representation with the radius adjusted for eccentricity
199  xyz[2] = ((re * (1.0 - _e2)) + llh[2]) * std::sin(llh[1]);
200 }
201 
206 CUDA_HOSTDEV inline void isce3::core::Ellipsoid::
207 xyzToLonLat(const cartesian_t & xyz, cartesian_t & llh) const {
208  /*
209  * Given a geocentric XYZ, produces a lat, lon, and height above the reference ellipsoid.
210  * VERMEILLE IMPLEMENTATION
211  */
212  // Pre-compute some values
213  const double e4 = _e2 * _e2;
214  const double a2 = _a * _a;
215  // Lateral distance normalized by the major axis
216  double p = (std::pow(xyz[0], 2) + std::pow(xyz[1], 2)) / a2;
217  // Polar distance normalized by the minor axis
218  double q = ((1. - _e2) * std::pow(xyz[2], 2)) / a2;
219  double r = (p + q - e4) / 6.;
220  double s = (e4 * p * q) / (4. * std::pow(r, 3));
221  double t = std::pow(1. + s + std::sqrt(s * (2. + s)), (1./3.));
222  double u = r * (1. + t + (1. / t));
223  double rv = std::sqrt(std::pow(u, 2) + (e4 * q));
224  double w = (_e2 * (u + rv - q)) / (2. * rv);
225  double k = std::sqrt(u + rv + std::pow(w, 2)) - w;
226  // Radius adjusted for eccentricity
227  double d = (k * std::sqrt(std::pow(xyz[0], 2) + std::pow(xyz[1], 2))) / (k + _e2);
228  // Latitude is a function of z and radius
229  llh[1] = std::atan2(xyz[2], d);
230  // Longitude is a function of x and y
231  llh[0] = std::atan2(xyz[1], xyz[0]);
232  // Height is a function of location and radius
233  llh[2] = ((k + _e2 - 1.) * sqrt(std::pow(d, 2) + std::pow(xyz[2], 2))) / k;
234 }
CUDA_HOSTDEV void xyzOnEllipse(double lon, double lat, cartesian_t &xyz) const
Return ECEF coordinates of point on ellipse.
Definition: Ellipsoid.h:177
void a(double val)
Set semi-major axis.
Definition: Ellipsoid.h:57
void e2(double val)
Set eccentricity^2.
Definition: Ellipsoid.h:62
CUDA_HOSTDEV double rDir(double hdg, double lat) const
Return directional local radius.
Definition: Ellipsoid.h:148
CUDA_HOSTDEV double e2() const
Return eccentricity^2.
Definition: Ellipsoid.h:52
Data structure to store Ellipsoid information.
Definition: Ellipsoid.h:20
CUDA_HOSTDEV void xyzToLonLat(const cartesian_t &xyz, cartesian_t &llh) const
Transform ECEF xyz to Lon/Lat/Hgt.
Definition: Ellipsoid.h:207
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:22
CUDA_HOSTDEV Ellipsoid(double maj, double ecc)
Constructor using semi-major axis and eccentricity^2.
Definition: Ellipsoid.h:28
CUDA_HOSTDEV void lonLatToXyz(const cartesian_t &llh, cartesian_t &xyz) const
Transform WGS84 Lon/Lat/Hgt to ECEF xyz.
Definition: Ellipsoid.h:188
CUDA_HOSTDEV double a() const
Return semi-major axis.
Definition: Ellipsoid.h:44
const double EarthEccentricitySquared
Eccentricity^2 for WGS84.
Definition: Constants.h:44
const double EarthSemiMajorAxis
Semi-major axis for WGS84.
Definition: Constants.h:41
CUDA_HOSTDEV double b() const
Return semi-minor axis.
Definition: Ellipsoid.h:48
CUDA_HOSTDEV double rNorth(double lat) const
Return local radius in NS direction.
Definition: Ellipsoid.h:137
CUDA_HOSTDEV void nVector(double lon, double lat, cartesian_t &vec) const
Return normal to the ellipsoid at given lon, lat.
Definition: Ellipsoid.h:162
Ellipsoid & operator=(const Ellipsoid &)
Overloaded assignment operator.
Definition: Ellipsoid.h:117
Ellipsoid(const Ellipsoid &ellps)
Copy constructor.
Definition: Ellipsoid.h:37
CUDA_HOSTDEV double rEast(double lat) const
Return local radius in EW direction.
Definition: Ellipsoid.h:127

Generated for ISCE3.0 by doxygen 1.8.5.