Coverage for pygeodesy/ellipsoids.py: 96%

747 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-05-04 12:01 -0400

1 

2# -*- coding: utf-8 -*- 

3 

4u'''Ellipsoidal and spherical earth models. 

5 

6Classes L{a_f2Tuple}, L{Ellipsoid} and L{Ellipsoid2}, an L{Ellipsoids} registry and 

72 dozen functions to convert I{equatorial} radius, I{polar} radius, I{eccentricities}, 

8I{flattenings} and I{inverse flattening}. 

9 

10See module L{datums} for L{Datum} and L{Transform} information and other details. 

11 

12Following is the list of predefined L{Ellipsoid}s, all instantiated lazily. 

13 

14@var Ellipsoids.Airy1830: Ellipsoid(name='Airy1830', a=6377563.396, f=0.00334085, f_=299.3249646, b=6356256.90923729) 

15@var Ellipsoids.AiryModified: Ellipsoid(name='AiryModified', a=6377340.189, f=0.00334085, f_=299.3249646, b=6356034.44793853) 

16@var Ellipsoids.ATS1977: Ellipsoid(name='ATS1977', a=6378135, f=0.00335281, f_=298.257, b=6356750.30492159) 

17@var Ellipsoids.Australia1966: Ellipsoid(name='Australia1966', a=6378160, f=0.00335289, f_=298.25, b=6356774.71919531) 

18@var Ellipsoids.Bessel1841: Ellipsoid(name='Bessel1841', a=6377397.155, f=0.00334277, f_=299.1528128, b=6356078.962818) 

19@var Ellipsoids.BesselModified: Ellipsoid(name='BesselModified', a=6377492.018, f=0.00334277, f_=299.1528128, b=6356173.5087127) 

20@var Ellipsoids.CGCS2000: Ellipsoid(name='CGCS2000', a=6378137, f=0.00335281, f_=298.2572221, b=6356752.31414036) 

21@var Ellipsoids.Clarke1866: Ellipsoid(name='Clarke1866', a=6378206.4, f=0.00339008, f_=294.97869821, b=6356583.8) 

22@var Ellipsoids.Clarke1880: Ellipsoid(name='Clarke1880', a=6378249.145, f=0.00340756, f_=293.465, b=6356514.86954978) 

23@var Ellipsoids.Clarke1880IGN: Ellipsoid(name='Clarke1880IGN', a=6378249.2, f=0.00340755, f_=293.46602129, b=6356515) 

24@var Ellipsoids.Clarke1880Mod: Ellipsoid(name='Clarke1880Mod', a=6378249.145, f=0.00340755, f_=293.46630766, b=6356514.96639549) 

25@var Ellipsoids.CPM1799: Ellipsoid(name='CPM1799', a=6375738.7, f=0.00299052, f_=334.39, b=6356671.92557493) 

26@var Ellipsoids.Delambre1810: Ellipsoid(name='Delambre1810', a=6376428, f=0.00321027, f_=311.5, b=6355957.92616372) 

27@var Ellipsoids.Engelis1985: Ellipsoid(name='Engelis1985', a=6378136.05, f=0.00335282, f_=298.2566, b=6356751.32272154) 

28@var Ellipsoids.Everest1969: Ellipsoid(name='Everest1969', a=6377295.664, f=0.00332445, f_=300.8017, b=6356094.667915) 

29@var Ellipsoids.Everest1975: Ellipsoid(name='Everest1975', a=6377299.151, f=0.00332445, f_=300.8017255, b=6356098.14512013) 

30@var Ellipsoids.Fisher1968: Ellipsoid(name='Fisher1968', a=6378150, f=0.00335233, f_=298.3, b=6356768.33724438) 

31@var Ellipsoids.GEM10C: Ellipsoid(name='GEM10C', a=6378137, f=0.00335281, f_=298.2572236, b=6356752.31424783) 

32@var Ellipsoids.GPES: Ellipsoid(name='GPES', a=6378135, f=0, f_=0, b=6378135) 

33@var Ellipsoids.GRS67: Ellipsoid(name='GRS67', a=6378160, f=0.00335292, f_=298.24716743, b=6356774.51609071) 

34@var Ellipsoids.GRS80: Ellipsoid(name='GRS80', a=6378137, f=0.00335281, f_=298.2572221, b=6356752.31414035) 

35@var Ellipsoids.Helmert1906: Ellipsoid(name='Helmert1906', a=6378200, f=0.00335233, f_=298.3, b=6356818.16962789) 

36@var Ellipsoids.IAU76: Ellipsoid(name='IAU76', a=6378140, f=0.00335281, f_=298.257, b=6356755.28815753) 

37@var Ellipsoids.IERS1989: Ellipsoid(name='IERS1989', a=6378136, f=0.00335281, f_=298.257, b=6356751.30156878) 

38@var Ellipsoids.IERS1992TOPEX: Ellipsoid(name='IERS1992TOPEX', a=6378136.3, f=0.00335281, f_=298.25722356, b=6356751.61659215) 

39@var Ellipsoids.IERS2003: Ellipsoid(name='IERS2003', a=6378136.6, f=0.00335282, f_=298.25642, b=6356751.85797165) 

40@var Ellipsoids.Intl1924: Ellipsoid(name='Intl1924', a=6378388, f=0.003367, f_=297, b=6356911.94612795) 

41@var Ellipsoids.Intl1967: Ellipsoid(name='Intl1967', a=6378157.5, f=0.0033529, f_=298.24961539, b=6356772.2) 

42@var Ellipsoids.Krassovski1940: Ellipsoid(name='Krassovski1940', a=6378245, f=0.00335233, f_=298.3, b=6356863.01877305) 

43@var Ellipsoids.Krassowsky1940: Ellipsoid(name='Krassowsky1940', a=6378245, f=0.00335233, f_=298.3, b=6356863.01877305) 

44@var Ellipsoids.Maupertuis1738: Ellipsoid(name='Maupertuis1738', a=6397300, f=0.0052356, f_=191, b=6363806.28272251) 

45@var Ellipsoids.Mercury1960: Ellipsoid(name='Mercury1960', a=6378166, f=0.00335233, f_=298.3, b=6356784.28360711) 

46@var Ellipsoids.Mercury1968Mod: Ellipsoid(name='Mercury1968Mod', a=6378150, f=0.00335233, f_=298.3, b=6356768.33724438) 

47@var Ellipsoids.NWL1965: Ellipsoid(name='NWL1965', a=6378145, f=0.00335289, f_=298.25, b=6356759.76948868) 

48@var Ellipsoids.OSU86F: Ellipsoid(name='OSU86F', a=6378136.2, f=0.00335281, f_=298.2572236, b=6356751.51693008) 

49@var Ellipsoids.OSU91A: Ellipsoid(name='OSU91A', a=6378136.3, f=0.00335281, f_=298.2572236, b=6356751.6165948) 

50@var Ellipsoids.Plessis1817: Ellipsoid(name='Plessis1817', a=6376523, f=0.00324002, f_=308.64, b=6355862.93325557) 

51@var Ellipsoids.PZ90: Ellipsoid(name='PZ90', a=6378136, f=0.0033528, f_=298.2578393, b=6356751.36174571) 

52@var Ellipsoids.SGS85: Ellipsoid(name='SGS85', a=6378136, f=0.00335281, f_=298.257, b=6356751.30156878) 

53@var Ellipsoids.SoAmerican1969: Ellipsoid(name='SoAmerican1969', a=6378160, f=0.00335289, f_=298.25, b=6356774.71919531) 

54@var Ellipsoids.Sphere: Ellipsoid(name='Sphere', a=6371008.771415, f=0, f_=0, b=6371008.771415) 

55@var Ellipsoids.SphereAuthalic: Ellipsoid(name='SphereAuthalic', a=6371000, f=0, f_=0, b=6371000) 

56@var Ellipsoids.SpherePopular: Ellipsoid(name='SpherePopular', a=6378137, f=0, f_=0, b=6378137) 

57@var Ellipsoids.Struve1860: Ellipsoid(name='Struve1860', a=6378298.3, f=0.00339294, f_=294.73, b=6356657.14266956) 

58@var Ellipsoids.WGS60: Ellipsoid(name='WGS60', a=6378165, f=0.00335233, f_=298.3, b=6356783.28695944) 

59@var Ellipsoids.WGS66: Ellipsoid(name='WGS66', a=6378145, f=0.00335289, f_=298.25, b=6356759.76948868) 

60@var Ellipsoids.WGS72: Ellipsoid(name='WGS72', a=6378135, f=0.00335278, f_=298.26, b=6356750.52001609) 

61@var Ellipsoids.WGS84: Ellipsoid(name='WGS84', a=6378137, f=0.00335281, f_=298.25722356, b=6356752.31424518) 

62@var Ellipsoids.WGS84_NGS: Ellipsoid(name='WGS84_NGS', a=6378137, f=0.00335281, f_=298.2572221, b=6356752.31414035) 

63''' 

64# make sure int/int division yields float quotient, see .basics 

65from __future__ import division as _; del _ # PYCHOK semicolon 

66 

67# from pygeodesy.albers import AlbersEqualAreaCylindrical # _MODS 

68from pygeodesy.basics import copysign0, isbool, _isin, isint, typename 

69from pygeodesy.constants import EPS, EPS0, EPS02, EPS1, INF, NINF, PI4, PI_2, PI_3, R_M, R_MA, R_FM, \ 

70 _EPSqrt, _EPStol as _TOL, _floatuple as _T, _isfinite, _over, \ 

71 _0_0s, _0_0, _0_5, _1_0, _1_EPS, _2_0, _4_0, _90_0, \ 

72 _0_25, _3_0 # PYCHOK used! 

73from pygeodesy.errors import _AssertionError, IntersectionError, _ValueError, _xattr, _xkwds_not 

74from pygeodesy.fmath import cbrt, cbrt2, fdot, Fhorner, fpowers, hypot, hypot_, \ 

75 hypot1, hypot2, sqrt3, Fsum 

76# from pygeodesy.fsums import Fsum # from .fmath 

77# from pygeodesy.internals import typename # from .basics 

78from pygeodesy.interns import NN, _a_, _Airy1830_, _AiryModified_, _b_, _Bessel1841_, _beta_, \ 

79 _Clarke1866_, _Clarke1880IGN_, _DMAIN_, _DOT_, _f_, _GRS80_, \ 

80 _height_, _Intl1924_, _incompatible_, _invalid_, _Krassovski1940_, \ 

81 _Krassowsky1940_, _lat_, _meridional_, _negative_, _not_finite_, \ 

82 _prime_vertical_, _radius_, _Sphere_, _SPACE_, _vs_, _WGS72_, _WGS84_ 

83# from pygeodesy.lazily import _ALL_LAZY, _ALL_MODS as _MODS # from .named 

84from pygeodesy.named import _lazyNamedEnumItem as _lazy, _name__, _NamedEnum, \ 

85 _NamedEnumItem, _NamedTuple, _Pass, _ALL_LAZY, _MODS 

86from pygeodesy.namedTuples import Distance2Tuple, Vector3Tuple, Vector4Tuple 

87from pygeodesy.props import deprecated_Property_RO, Property_RO, property_doc_, \ 

88 deprecated_property_RO, property_RO, property_ROver 

89from pygeodesy.streprs import Fmt, fstr, instr, strs, unstr 

90# from pygeodesy.triaxials import _hartzell3 # _MODS 

91from pygeodesy.units import Azimuth, Bearing, Distance, Float, Float_, Height, Lamd, Lat, \ 

92 Meter, Meter2, Meter3, Phi, Phid, Radius, Radius_, Scalar 

93from pygeodesy.utily import atan1, atan1d, atan2b, degrees90, m2radians, radians2m, sincos2d 

94 

95from math import asinh, atan, atanh, cos, degrees, exp, fabs, radians, sin, sinh, sqrt, tan # as _tan 

96 

97__all__ = _ALL_LAZY.ellipsoids 

98__version__ = '25.04.28' 

99 

100_f_0_0 = Float(f =_0_0) # zero flattening 

101_f__0_0 = Float(f_=_0_0) # zero inverse flattening 

102# see U{WGS84_f<https://GeographicLib.SourceForge.io/C++/doc/classGeographicLib_1_1Constants.html>} 

103_f__WGS84 = Float(f_=_1_0 / (1000000000 / 298257223563)) # 298.257223562_999_97 vs 298.257223563 

104 

105 

106def _aux(lat, inverse, auxLat, clip=90): 

107 '''Return a named auxiliary latitude in C{degrees}. 

108 ''' 

109 return Lat(lat, clip=clip, name=_lat_ if inverse else typename(auxLat)) 

110 

111 

112def _s2_c2(phi): 

113 '''(INTERNAL) Return 2-tuple C{(sin(B{phi})**2, cos(B{phi})**2)}. 

114 ''' 

115 if phi: 

116 s2 = sin(phi)**2 

117 if s2 > EPS: 

118 c2 = _1_0 - s2 

119 if c2 > EPS: 

120 if c2 < EPS1: 

121 return s2, c2 

122 else: 

123 return _1_0, _0_0 # phi == PI_2 

124 return _0_0, _1_0 # phi == 0 

125 

126 

127class a_f2Tuple(_NamedTuple): 

128 '''2-Tuple C{(a, f)} specifying an ellipsoid by I{equatorial} 

129 radius C{a} in C{meter} and scalar I{flattening} C{f}. 

130 

131 @see: Class L{Ellipsoid2}. 

132 ''' 

133 _Names_ = (_a_, _f_) # name 'f' not 'f_' 

134 _Units_ = (_Pass, _Pass) 

135 

136 def __new__(cls, a, f, **name): 

137 '''New L{a_f2Tuple} ellipsoid specification. 

138 

139 @arg a: Equatorial radius (C{scalar} > 0). 

140 @arg f: Flattening (C{scalar} < 1, negative for I{prolate}). 

141 @kwarg name: Optional C{B{name}=NN} (C{str}). 

142 

143 @return: An L{a_f2Tuple}C{(a, f)}. 

144 

145 @raise UnitError: Invalid B{C{a}} or B{C{f}}. 

146 

147 @note: C{abs(B{f}) < }L{EPS<pygeodesy.constants.EPS>} is 

148 forced to C{B{f}=0}, I{spherical}. 

149 

150 @note: Negative C{B{f}} produces a I{prolate} ellipsoid. 

151 ''' 

152 a = Radius_(a=a) # low=EPS, high=None 

153 f = Float_( f=f, low=None, high=EPS1) 

154 if fabs(f) < EPS: # force spherical 

155 f = _f_0_0 

156 return _NamedTuple.__new__(cls, a, f, **name) 

157 

158 @Property_RO 

159 def b(self): 

160 '''Get the I{polar} radius (C{meter}), M{a * (1 - f)}. 

161 ''' 

162 return a_f2b(self.a, self.f) # PYCHOK .a and .f 

163 

164 def ellipsoid(self, **name): 

165 '''Return an L{Ellipsoid} for this 2-tuple C{(a, f)}. 

166 

167 @kwarg name: Optional C{B{name}=NN} (C{str}). 

168 

169 @raise NameError: A registered C{ellipsoid} with the 

170 same B{C{name}} already exists. 

171 ''' 

172 return Ellipsoid(self.a, f=self.f, name=self._name__(name)) # PYCHOK .a and .f 

173 

174 @Property_RO 

175 def f_(self): 

176 '''Get the I{inverse} flattening (C{scalar}), M{1 / f} == M{a / (a - b)}. 

177 ''' 

178 return f2f_(self.f) # PYCHOK .f 

179 

180 

181class Circle4Tuple(_NamedTuple): 

182 '''4-Tuple C{(radius, height, lat, beta)} of the C{radius} and C{height}, 

183 both conventionally in C{meter} of a parallel I{circle of latitude} at 

184 (geodetic) latitude C{lat} and the I{parametric (or reduced) auxiliary 

185 latitude} C{beta}, both in C{degrees90}. 

186 

187 The C{height} is the (signed) distance along the z-axis between the 

188 parallel and the equator. At near-polar C{lat}s, the C{radius} is C{0}, 

189 the C{height} is the ellipsoid's (signed) polar radius and C{beta} 

190 equals C{lat}. 

191 ''' 

192 _Names_ = (_radius_, _height_, _lat_, _beta_) 

193 _Units_ = ( Radius, Height, Lat, Lat) 

194 

195 

196class Curvature2Tuple(_NamedTuple): 

197 '''2-Tuple C{(meridional, prime_vertical)} of radii of curvature, both in 

198 C{meter}, conventionally. 

199 ''' 

200 _Names_ = (_meridional_, _prime_vertical_) 

201 _Units_ = ( Meter, Meter) 

202 

203 @property_RO 

204 def transverse(self): 

205 '''Get this I{prime_vertical}, aka I{transverse} radius of curvature. 

206 ''' 

207 return self.prime_vertical 

208 

209 

210class Ellipsoid(_NamedEnumItem): 

211 '''Ellipsoid with I{equatorial} and I{polar} radii, I{flattening}, I{inverse 

212 flattening} and other, often used, I{cached} attributes, supporting 

213 I{oblate} and I{prolate} ellipsoidal and I{spherical} earth models. 

214 ''' 

215 _a = 0 # equatorial radius, semi-axis (C{meter}) 

216 _b = 0 # polar radius, semi-axis (C{meter}): a * (f - 1) / f 

217 _f = 0 # (1st) flattening: (a - b) / a 

218 _f_ = 0 # inverse flattening: 1 / f = a / (a - b) 

219 

220 _geodsolve = NN # means, use PYGEODESY_GEODSOLVE 

221 _KsOrder = 8 # Krüger series order (4, 6 or 8) 

222 _rhumbsolve = NN # means, use PYGEODESY_RHUMBSOLVE 

223 

224 def __init__(self, a, b=None, f_=None, f=None, **name): 

225 '''New L{Ellipsoid} from the I{equatorial} radius I{and} either 

226 the I{polar} radius or I{inverse flattening} or I{flattening}. 

227 

228 @arg a: Equatorial radius, semi-axis (C{meter}). 

229 @arg b: Optional polar radius, semi-axis (C{meter}). 

230 @arg f_: Inverse flattening: M{a / (a - b)} (C{float} >>> 1.0). 

231 @arg f: Flattening: M{(a - b) / a} (C{scalar}, near zero for 

232 spherical). 

233 @kwarg name: Optional, unique C{B{name}=NN} (C{str}). 

234 

235 @raise NameError: Ellipsoid with the same B{C{name}} already exists. 

236 

237 @raise ValueError: Invalid B{C{a}}, B{C{b}}, B{C{f_}} or B{C{f}} or 

238 B{C{f_}} and B{C{f}} are incompatible. 

239 

240 @note: M{abs(f_) > 1 / EPS} or M{abs(1 / f_) < EPS} is forced 

241 to M{1 / f_ = 0}, spherical. 

242 ''' 

243 ff_ = f, f_ # assertion below 

244 n = _name__(**name) if name else NN 

245 try: 

246 a = Radius_(a=a) # low=EPS 

247 if not _isfinite(a): 

248 raise ValueError(_SPACE_(_a_, _not_finite_)) 

249 

250 if b: # not _isin(b, None, _0_0) 

251 b = Radius_(b=b) # low=EPS 

252 f = a_b2f(a, b) if f is None else Float(f=f) 

253 f_ = f2f_(f) if f_ is None else Float(f_=f_) 

254 elif f is not None: 

255 f = Float(f=f) 

256 b = a_f2b(a, f) 

257 f_ = f2f_(f) if f_ is None else Float(f_=f_) 

258 elif f_: 

259 f_ = Float(f_=f_) 

260 b = a_f_2b(a, f_) # a * (f_ - 1) / f_ 

261 f = f_2f(f_) 

262 else: # only a, spherical 

263 f_ = f = 0 

264 b = a # superfluous 

265 

266 if not f < _1_0: # sanity check, see .ecef.Ecef.__init__ 

267 raise ValueError(_SPACE_(_f_, _invalid_)) 

268 if not _isfinite(b): 

269 raise ValueError(_SPACE_(_b_, _not_finite_)) 

270 

271 if fabs(f) < EPS or a == b or not f_: # spherical 

272 b = a 

273 f = _f_0_0 

274 f_ = _f__0_0 

275 

276 except (TypeError, ValueError) as x: 

277 d = _xkwds_not(None, b=b, f_=f_, f=f) 

278 t = instr(self, a=a, name=n, **d) 

279 raise _ValueError(t, cause=x) 

280 

281 self._a = a 

282 self._b = b 

283 self._f = f 

284 self._f_ = f_ 

285 

286 self._register(Ellipsoids, n) 

287 

288 if f and f_: # see test/testEllipsoidal 

289 d = dict(eps=_TOL) 

290 if None in ff_: # both f_ and f given 

291 d.update(Error=_ValueError, txt=_incompatible_) 

292 self._assert(_1_0 / f, f_=f_, **d) 

293 self._assert(_1_0 / f_, f =f, **d) 

294 self._assert(self.b2_a2, e21=self.e21, eps=EPS) 

295 

296 def __eq__(self, other): 

297 '''Compare this and an other ellipsoid. 

298 

299 @arg other: The other ellipsoid (L{Ellipsoid} or L{Ellipsoid2}). 

300 

301 @return: C{True} if equal, C{False} otherwise. 

302 ''' 

303 return self is other or (isinstance(other, Ellipsoid) and 

304 self.a == other.a and 

305 (self.f == other.f or self.b == other.b)) 

306 

307 def __hash__(self): 

308 return self._hash # memoized 

309 

310 @Property_RO 

311 def a(self): 

312 '''Get the I{equatorial} radius, semi-axis (C{meter}). 

313 ''' 

314 return self._a 

315 

316 equatoradius = a # = Requatorial 

317 

318 @Property_RO 

319 def a2(self): 

320 '''Get the I{equatorial} radius I{squared} (C{meter} I{squared}), M{a**2}. 

321 ''' 

322 return Meter2(a2=self.a**2) 

323 

324 @Property_RO 

325 def a2_(self): 

326 '''Get the inverse of the I{equatorial} radius I{squared} (C{meter} I{squared}), M{1 / a**2}. 

327 ''' 

328 return Float(a2_=_1_0 / self.a2) 

329 

330 @Property_RO 

331 def a_b(self): 

332 '''Get the ratio I{equatorial} over I{polar} radius (C{float}), M{a / b} == M{1 / (1 - f)}. 

333 ''' 

334 return Float(a_b=self.a / self.b if self.f else _1_0) 

335 

336 @Property_RO 

337 def a2_b(self): 

338 '''Get the I{polar} meridional (or polar) radius of curvature (C{meter}), M{a**2 / b}. 

339 

340 @see: U{Radii of Curvature 

341 <https://WikiPedia.org/wiki/Earth_radius#Radii_of_curvature>} 

342 and U{Moritz, H. (1980), Geodetic Reference System 1980 

343 <https://WikiPedia.org/wiki/Earth_radius#cite_note-Moritz-2>}. 

344 

345 @note: Symbol C{c} is used by IUGG and IERS for the U{polar radius of curvature 

346 <https://WikiPedia.org/wiki/Earth_radius#Radii_of_curvature>}, see L{c2} 

347 and L{R2} or L{Rauthalic}. 

348 ''' 

349 return Radius(a2_b=self.a2 / self.b if self.f else self.a) # = rocPolar 

350 

351 @Property_RO 

352 def a2_b2(self): 

353 '''Get the ratio I{equatorial} over I{polar} radius I{squared} (C{float}), 

354 M{(a / b)**2} == M{1 / (1 - e**2)} == M{1 / (1 - e2)} == M{1 / e21}. 

355 ''' 

356 return Float(a2_b2=self.a_b**2 if self.f else _1_0) 

357 

358 @Property_RO 

359 def a_f(self): 

360 '''Get the I{equatorial} radius and I{flattening} (L{a_f2Tuple}), see method C{toEllipsoid2}. 

361 ''' 

362 return a_f2Tuple(self.a, self.f, name=self.name) 

363 

364 a_f2 = a_f # synonym 

365 

366 @Property_RO 

367 def A(self): 

368 '''Get the UTM I{meridional (or rectifying)} radius (C{meter}). 

369 

370 @note: C{A * PI / 2} ≈= L{L<Ellipsoid.L>}, the I{quarter meridian}. 

371 

372 @see: I{Meridian arc unit} U{Q<https://StudyLib.net/doc/7443565/>}, 

373 the mean, meridional length I{per radian}. 

374 ''' 

375 A, n = self.a, self.n 

376 if n: 

377 d = (n + _1_0) * 1048576 / A 

378 if d: # use 6 n**2 terms, half-way between the _KsOrder's 4, 6, 8 

379 # <https://GeographicLib.SourceForge.io/C++/doc/tmseries30.html> 

380 # <https://GeographicLib.SourceForge.io/C++/doc/transversemercator.html> and 

381 # <https://www.MyGeodesy.id.AU/documents/Karney-Krueger%20equations.pdf> (3) 

382 # A *= fhorner(n**2, 1048576, 262144, 16384, 4096, 1600, 784, 441) / 1048576) / (1 + n) 

383 A = Radius(A=Fhorner(n**2, 1048576, 262144, 16384, 4096, 1600, 784, 441).fover(d)) 

384 return A 

385# # Moritz, H. <https://Geodesy.Geology.Ohio-State.EDU/course/refpapers/00740128.pdf> 

386# # q = 4 / self.rocPolar 

387# # Q = (1 - 3 / 4 * e'2 + 45 / 64 * e'4 - 175 / 256 * e'6 + 11025 / 16384 * e'8) * rocPolar 

388# # = (4 + e'2 * (-3 + e'2 * (45 / 16 + e'2 * (-175 / 64 + e'2 * 11025 / 4096)))) / q 

389# return Radius(Q=Fhorner(self.e22, 4, -3, 45 / 16, -175 / 64, 11025 / 4096).fover(q)) 

390 

391 @Property_RO 

392 def _albersCyl(self): 

393 '''(INTERNAL) Helper for C{auxAuthalic}. 

394 ''' 

395 return _MODS.albers.AlbersEqualAreaCylindrical(datum=self, name=self.name) 

396 

397 @Property_RO 

398 def AlphaKs(self): 

399 '''Get the I{Krüger} U{Alpha series coefficients<https://GeographicLib.SourceForge.io/C++/doc/tmseries30.html>} (C{KsOrder}C{-tuple}). 

400 ''' 

401 return self._Kseries( # XXX int/int quotients may require from __future__ import division as _; del _ # PYCHOK semicolon 

402 # n n**2 n**3 n**4 n**5 n**6 n**7 n**8 

403 _T(1/2, -2/3, 5/16, 41/180, -127/288, 7891/37800, 72161/387072, -18975107/50803200), 

404 _T(13/48, -3/5, 557/1440, 281/630, -1983433/1935360, 13769/28800, 148003883/174182400), # PYCHOK unaligned 

405 _T(61/240, -103/140, 15061/26880, 167603/181440, -67102379/29030400, 79682431/79833600), # PYCHOK unaligned 

406 _T(49561/161280, -179/168, 6601661/7257600, 97445/49896, -40176129013/7664025600), # PYCHOK unaligned 

407 _T(34729/80640, -3418889/1995840, 14644087/9123840, 2605413599/622702080), # PYCHOK unaligned 

408 _T(212378941/319334400, -30705481/10378368, 175214326799/58118860800), # PYCHOK unaligned 

409 _T(1522256789/1383782400, -16759934899/3113510400), # PYCHOK unaligned 

410 _T(1424729850961/743921418240)) # PYCHOK unaligned 

411 

412 @Property_RO 

413 def area(self): 

414 '''Get the ellipsoid's surface area (C{meter} I{squared}), M{4 * PI * c2}. 

415 

416 @see: Properties L{areax}, L{c2} and L{R2} and functions 

417 L{ellipsoidalExact.areaOf} and L{ellipsoidalKarney.areaOf}. 

418 ''' 

419 return Meter2(area=self.c2 * PI4) 

420 

421 @Property_RO 

422 def areax(self): 

423 '''Get the ellipsoid's surface area (C{meter} I{squared}), M{4 * PI * c2x}, more 

424 accurate for very I{oblate} ellipsoids. 

425 

426 @see: Properties L{area}, L{c2x} and L{R2x}, class L{GeodesicExact} and 

427 functions L{ellipsoidalExact.areaOf} and L{ellipsoidalKarney.areaOf}. 

428 ''' 

429 return Meter2(areax=self.c2x * PI4) 

430 

431 def _assert(self, val, eps=_TOL, f0=_0_0, Error=_AssertionError, txt=NN, **name_value): 

432 '''(INTERNAL) Assert a C{name=value} vs C{val}. 

433 ''' 

434 for n, v in name_value.items(): 

435 if fabs(v - val) > eps: # PYCHOK no cover 

436 t = (v, _vs_, val) 

437 t = _SPACE_.join(strs(t, prec=12, fmt=Fmt.g)) 

438 t = Fmt.EQUAL(self._DOT_(n), t) 

439 raise Error(t, txt=txt or Fmt.exceeds_eps(eps)) 

440 return Float(v if self.f else f0, name=n) 

441 raise Error(unstr(self._DOT_(typename(self._assert)), val, 

442 eps=eps, f0=f0, **name_value)) 

443 

444 def auxAuthalic(self, lat, inverse=False): 

445 '''Compute the I{authalic} auxiliary latitude or the I{inverse} thereof. 

446 

447 @arg lat: The geodetic (or I{authalic}) latitude (C{degrees90}). 

448 @kwarg inverse: If C{True}, B{C{lat}} is the I{authalic} and 

449 return the geodetic latitude (C{bool}). 

450 

451 @return: The I{authalic} (or geodetic) latitude in C{degrees90}. 

452 

453 @see: U{Inverse-/AuthalicLatitude<https://GeographicLib.SourceForge.io/ 

454 C++/doc/classGeographicLib_1_1Ellipsoid.html>}, U{Authalic latitude 

455 <https://WikiPedia.org/wiki/Latitude#Authalic_latitude>}, and 

456 U{Snyder<https://Pubs.USGS.gov/pp/1395/report.pdf>}, p 16. 

457 ''' 

458 if self.f: 

459 f = self._albersCyl._tanf if inverse else \ 

460 self._albersCyl._txif # PYCHOK attr 

461 lat = atan1d(f(tan(Phid(lat)))) # PYCHOK attr 

462 return _aux(lat, inverse, Ellipsoid.auxAuthalic) 

463 

464 def auxConformal(self, lat, inverse=False): 

465 '''Compute the I{conformal} auxiliary latitude or the I{inverse} thereof. 

466 

467 @arg lat: The geodetic (or I{conformal}) latitude (C{degrees90}). 

468 @kwarg inverse: If C{True}, B{C{lat}} is the I{conformal} and 

469 return the geodetic latitude (C{bool}). 

470 

471 @return: The I{conformal} (or geodetic) latitude in C{degrees90}. 

472 

473 @see: U{Inverse-/ConformalLatitude<https://GeographicLib.SourceForge.io/ 

474 C++/doc/classGeographicLib_1_1Ellipsoid.html>}, U{Conformal latitude 

475 <https://WikiPedia.org/wiki/Latitude#Conformal_latitude>}, and 

476 U{Snyder<https://Pubs.USGS.gov/pp/1395/report.pdf>}, pp 15-16. 

477 ''' 

478 if self.f: 

479 f = self.es_tauf if inverse else self.es_taupf # PYCHOK attr 

480 lat = atan1d(f(tan(Phid(lat)))) # PYCHOK attr 

481 return _aux(lat, inverse, Ellipsoid.auxConformal) 

482 

483 def auxGeocentric(self, lat, inverse=False): 

484 '''Compute the I{geocentric} auxiliary latitude or the I{inverse} thereof. 

485 

486 @arg lat: The geodetic (or I{geocentric}) latitude (C{degrees90}). 

487 @kwarg inverse: If C{True}, B{C{lat}} is the geocentric and 

488 return the I{geocentric} latitude (C{bool}). 

489 

490 @return: The I{geocentric} (or geodetic) latitude in C{degrees90}. 

491 

492 @see: U{Inverse-/GeocentricLatitude<https://GeographicLib.SourceForge.io/ 

493 C++/doc/classGeographicLib_1_1Ellipsoid.html>}, U{Geocentric latitude 

494 <https://WikiPedia.org/wiki/Latitude#Geocentric_latitude>}, and 

495 U{Snyder<https://Pubs.USGS.gov/pp/1395/report.pdf>}, pp 17-18. 

496 ''' 

497 if self.f: 

498 f = self.a2_b2 if inverse else self.b2_a2 

499 lat = atan1d(tan(Phid(lat)) * f) 

500 return _aux(lat, inverse, Ellipsoid.auxGeocentric) 

501 

502 def auxIsometric(self, lat, inverse=False): 

503 '''Compute the I{isometric} auxiliary latitude or the I{inverse} thereof. 

504 

505 @arg lat: The geodetic (or I{isometric}) latitude (C{degrees}). 

506 @kwarg inverse: If C{True}, B{C{lat}} is the I{isometric} and 

507 return the geodetic latitude (C{bool}). 

508 

509 @return: The I{isometric} (or geodetic) latitude in C{degrees}. 

510 

511 @note: The I{isometric} latitude for geodetic C{+/-90} is far 

512 outside the C{[-90..+90]} range but the inverse 

513 thereof is the original geodetic latitude. 

514 

515 @see: U{Inverse-/IsometricLatitude<https://GeographicLib.SourceForge.io/ 

516 C++/doc/classGeographicLib_1_1Ellipsoid.html>}, U{Isometric latitude 

517 <https://WikiPedia.org/wiki/Latitude#Isometric_latitude>}, and 

518 U{Snyder<https://Pubs.USGS.gov/pp/1395/report.pdf>}, pp 15-16. 

519 ''' 

520 if self.f: 

521 r = Phid(lat, clip=0) 

522 lat = degrees(atan1(self.es_tauf(sinh(r))) if inverse else 

523 asinh(self.es_taupf(tan(r)))) 

524 # clip=0, since auxIsometric(+/-90) is far outside [-90..+90] 

525 return _aux(lat, inverse, Ellipsoid.auxIsometric, clip=0) 

526 

527 def auxParametric(self, lat, inverse=False): 

528 '''Compute the I{parametric} auxiliary latitude or the I{inverse} thereof. 

529 

530 @arg lat: The geodetic (or I{parametric}) latitude (C{degrees90}). 

531 @kwarg inverse: If C{True}, B{C{lat}} is the I{parametric} and 

532 return the geodetic latitude (C{bool}). 

533 

534 @return: The I{parametric} (or geodetic) latitude in C{degrees90}. 

535 

536 @see: U{Inverse-/ParametricLatitude<https://GeographicLib.SourceForge.io/ 

537 C++/doc/classGeographicLib_1_1Ellipsoid.html>}, U{Parametric latitude 

538 <https://WikiPedia.org/wiki/Latitude#Parametric_(or_reduced)_latitude>}, 

539 and U{Snyder<https://Pubs.USGS.gov/pp/1395/report.pdf>}, p 18. 

540 ''' 

541 if self.f: 

542 lat = self._beta(Lat(lat), inverse=inverse) 

543 return _aux(lat, inverse, Ellipsoid.auxParametric) 

544 

545 auxReduced = auxParametric # synonymous 

546 

547 def auxRectifying(self, lat, inverse=False): 

548 '''Compute the I{rectifying} auxiliary latitude or the I{inverse} thereof. 

549 

550 @arg lat: The geodetic (or I{rectifying}) latitude (C{degrees90}). 

551 @kwarg inverse: If C{True}, B{C{lat}} is the I{rectifying} and 

552 return the geodetic latitude (C{bool}). 

553 

554 @return: The I{rectifying} (or geodetic) latitude in C{degrees90}. 

555 

556 @see: U{Inverse-/RectifyingLatitude<https://GeographicLib.SourceForge.io/ 

557 C++/doc/classGeographicLib_1_1Ellipsoid.html>}, U{Rectifying latitude 

558 <https://WikiPedia.org/wiki/Latitude#Rectifying_latitude>}, and 

559 U{Snyder<https://Pubs.USGS.gov/pp/1395/report.pdf>}, pp 16-17. 

560 ''' 

561 if self.f: 

562 lat = Lat(lat) 

563 if 0 < fabs(lat) < _90_0: 

564 if inverse: 

565 e = self._elliptic_e22 

566 d = degrees90(e.fEinv(e.cE * lat / _90_0)) 

567 lat = self.auxParametric(d, inverse=True) 

568 else: 

569 lat = _over(self.Llat(lat), self.L) * _90_0 

570 return _aux(lat, inverse, Ellipsoid.auxRectifying) 

571 

572 @Property_RO 

573 def b(self): 

574 '''Get the I{polar} radius, semi-axis (C{meter}). 

575 ''' 

576 return self._b 

577 

578 polaradius = b # = Rpolar 

579 

580 @Property_RO 

581 def b_a(self): 

582 '''Get the ratio I{polar} over I{equatorial} radius (C{float}), M{b / a == f1 == 1 - f}. 

583 

584 @see: Property L{f1}. 

585 ''' 

586 return self._assert(self.b / self.a, b_a=self.f1, f0=_1_0) 

587 

588 @Property_RO 

589 def b2(self): 

590 '''Get the I{polar} radius I{squared} (C{float}), M{b**2}. 

591 ''' 

592 return Meter2(b2=self.b**2) 

593 

594 @Property_RO 

595 def b2_a(self): 

596 '''Get the I{equatorial} meridional radius of curvature (C{meter}), M{b**2 / a}, see C{rocMeridional}C{(0)}. 

597 

598 @see: U{Radii of Curvature<https://WikiPedia.org/wiki/Earth_radius#Radii_of_curvature>}. 

599 ''' 

600 return Radius(b2_a=_over(self.b2, self.a) if self.f else self.b) 

601 

602 @Property_RO 

603 def b2_a2(self): 

604 '''Get the ratio I{polar} over I{equatorial} radius I{squared} (C{float}), M{(b / a)**2} 

605 == M{(1 - f)**2} == M{1 - e**2} == C{e21}. 

606 ''' 

607 return Float(b2_a2=self.b_a**2 if self.f else _1_0) 

608 

609 def _beta(self, lat, inverse=False): 

610 '''(INTERNAL) Get the I{parametric (or reduced) auxiliary latitude} or inverse thereof. 

611 ''' 

612 s, c = sincos2d(lat) # like Karney's tand(lat) 

613 s *= self.a_b if inverse else self.b_a 

614 return atan1d(s, c) 

615 

616 @Property_RO 

617 def BetaKs(self): 

618 '''Get the I{Krüger} U{Beta series coefficients<https://GeographicLib.SourceForge.io/C++/doc/tmseries30.html>} (C{KsOrder}C{-tuple}). 

619 ''' 

620 return self._Kseries( # XXX int/int quotients may require from __future__ import division as _; del _ # PYCHOK semicolon 

621 # n n**2 n**3 n**4 n**5 n**6 n**7 n**8 

622 _T(1/2, -2/3, 37/96, -1/360, -81/512, 96199/604800, -5406467/38707200, 7944359/67737600), 

623 _T(1/48, 1/15, -437/1440, 46/105, -1118711/3870720, 51841/1209600, 24749483/348364800), # PYCHOK unaligned 

624 _T(17/480, -37/840, -209/4480, 5569/90720, 9261899/58060800, -6457463/17740800), # PYCHOK unaligned 

625 _T(4397/161280, -11/504, -830251/7257600, 466511/2494800, 324154477/7664025600), # PYCHOK unaligned 

626 _T(4583/161280, -108847/3991680, -8005831/63866880, 22894433/124540416), # PYCHOK unaligned 

627 _T(20648693/638668800, -16363163/518918400, -2204645983/12915302400), # PYCHOK unaligne 

628 _T(219941297/5535129600, -497323811/12454041600), # PYCHOK unaligned 

629 _T(191773887257/3719607091200)) # PYCHOK unaligned 

630 

631 @deprecated_Property_RO 

632 def c(self): # PYCHOK no cover 

633 '''DEPRECATED, use property C{R2} or C{Rauthalic}.''' 

634 return self.R2 

635 

636 @Property_RO 

637 def c2(self): 

638 '''Get the I{authalic} earth radius I{squared} (C{meter} I{squared}). 

639 

640 @see: Properties L{c2x}, L{area}, L{R2}, L{Rauthalic}, I{Karney's} U{equation (60) 

641 <https://Link.Springer.com/article/10.1007%2Fs00190-012-0578-z>} and C++ U{Ellipsoid.Area 

642 <https://GeographicLib.SourceForge.io/C++/doc/classGeographicLib_1_1Ellipsoid.html>}, 

643 U{Authalic radius<https://WikiPedia.org/wiki/Earth_radius#Authalic_radius>}, U{Surface area 

644 <https://WikiPedia.org/wiki/Ellipsoid>} and U{surface area 

645 <https://www.Numericana.com/answer/geometry.htm#oblate>}. 

646 ''' 

647 return self._c2f(False) 

648 

649 @Property_RO 

650 def c2x(self): 

651 '''Get the I{authalic} earth radius I{squared} (C{meter} I{squared}), more accurate for very I{oblate} 

652 ellipsoids. 

653 

654 @see: Properties L{c2}, L{areax}, L{R2x}, L{Rauthalicx}, class L{GeodesicExact} and I{Karney}'s comments at C++ 

655 attribute U{GeodesicExact._c2<https://GeographicLib.SourceForge.io/C++/doc/GeodesicExact_8cpp_source.html>}. 

656 ''' 

657 return self._c2f(True) 

658 

659 def _c2f(self, c2x): 

660 '''(INTERNAL) Helper for C{.c2} and C{.c2x}. 

661 ''' 

662 f, c2 = self.f, self.b2 

663 if f: 

664 e = self.e 

665 if e > EPS0: 

666 if f > 0: # .isOblate 

667 c2 *= (asinh(sqrt(self.e22abs)) if c2x else atanh(e)) / e 

668 elif f < 0: # .isProlate 

669 c2 *= atan1(e) / e # XXX asin? 

670 c2 = Meter2(c2=(self.a2 + c2) * _0_5) 

671 return c2 

672 

673 def circle4(self, lat): 

674 '''Get the equatorial or a parallel I{circle of latitude}. 

675 

676 @arg lat: Geodetic latitude (C{degrees90}, C{str}). 

677 

678 @return: A L{Circle4Tuple}C{(radius, height, lat, beta)}. 

679 

680 @raise RangeError: Latitude B{C{lat}} outside valid range and 

681 L{rangerrors<pygeodesy.rangerrors>} is C{True}. 

682 

683 @raise TypeError: Invalid B{C{lat}}. 

684 

685 @raise ValueError: Invalid B{C{lat}}. 

686 

687 @see: Definition of U{I{p} and I{z} under B{Parametric (or reduced) latitude} 

688 <https://WikiPedia.org/wiki/Latitude>}, I{Karney's} C++ U{CircleRadius and CircleHeight 

689 <https://GeographicLib.SourceForge.io/C++/doc/classGeographicLib_1_1Ellipsoid.html>} 

690 and method C{Rlat}. 

691 ''' 

692 lat = Lat(lat) 

693 if lat: 

694 b = lat 

695 if fabs(lat) < _90_0: 

696 if self.f: 

697 b = self._beta(lat) 

698 z, r = sincos2d(b) 

699 r *= self.a 

700 z *= self.b 

701 else: # near-polar 

702 r, z = _0_0, copysign0(self.b, lat) 

703 else: # equator 

704 r = self.a 

705 z = lat = b = _0_0 

706 return Circle4Tuple(r, z, lat, b) 

707 

708 def degrees2m(self, deg, lat=0): 

709 '''Convert an angle to the distance along the equator or 

710 along a parallel of (geodetic) latitude. 

711 

712 @arg deg: The angle (C{degrees}). 

713 @kwarg lat: Parallel latitude (C{degrees90}, C{str}). 

714 

715 @return: Distance (C{meter}, same units as the equatorial 

716 and polar radii) or C{0} for near-polar B{C{lat}}. 

717 

718 @raise RangeError: Latitude B{C{lat}} outside valid range and 

719 L{rangerrors<pygeodesy.rangerrors>} is C{True}. 

720 

721 @raise ValueError: Invalid B{C{deg}} or B{C{lat}}. 

722 ''' 

723 return self.radians2m(radians(deg), lat=lat) 

724 

725 def distance2(self, lat0, lon0, lat1, lon1): 

726 '''I{Approximate} the distance and (initial) bearing between 

727 two points based on the U{local, flat earth approximation 

728 <https://www.EdWilliams.org/avform.htm#flat>} aka U{Hubeny 

729 <https://www.OVG.AT/de/vgi/files/pdf/3781/>} formula. 

730 

731 I{Suitable only for distances of several hundred Km or Miles 

732 and only between points not near-polar}. 

733 

734 @arg lat0: From latitude (C{degrees}). 

735 @arg lon0: From longitude (C{degrees}). 

736 @arg lat1: To latitude (C{degrees}). 

737 @arg lon1: To longitude (C{degrees}). 

738 

739 @return: A L{Distance2Tuple}C{(distance, initial)} with C{distance} 

740 in same units as this ellipsoid's axes. 

741 

742 @note: The meridional and prime_vertical radii of curvature are 

743 taken and scaled I{at the initial latitude}, see C{roc2}. 

744 

745 @see: Function L{pygeodesy.flatLocal}/L{pygeodesy.hubeny}. 

746 ''' 

747 phi0 = Phid(lat0=lat0) 

748 m, n = self.roc2_(phi0, scaled=True) 

749 m *= Phid(lat1=lat1) - phi0 

750 n *= Lamd(lon1=lon1) - Lamd(lon0=lon0) 

751 return Distance2Tuple(hypot(m, n), atan2b(n, m)) 

752 

753 @Property_RO 

754 def e(self): 

755 '''Get the I{unsigned, (1st) eccentricity} (C{float}), M{sqrt(1 - (b / a)**2))}, see C{a_b2e}. 

756 

757 @see: Property L{es}. 

758 ''' 

759 return Float(e=sqrt(self.e2abs) if self.e2 else _0_0) 

760 

761 @deprecated_Property_RO 

762 def e12(self): # see property ._e12 

763 '''DEPRECATED, use property C{e21}.''' 

764 return self.e21 

765 

766# @Property_RO 

767# def _e12(self): # see property ._elliptic_e12 

768# # (INTERNAL) until e12 above can be replaced with e21. 

769# return self.e2 / (_1_0 - self.e2) # see I{Karney}'s Ellipsoid._e12 = e2 / (1 - e2) 

770 

771 @Property_RO 

772 def e2(self): 

773 '''Get the I{signed, (1st) eccentricity squared} (C{float}), M{f * (2 - f) 

774 == 1 - (b / a)**2}, see C{a_b2e2}. 

775 ''' 

776 return self._assert(a_b2e2(self.a, self.b), e2=f2e2(self.f)) 

777 

778 @Property_RO 

779 def e2abs(self): 

780 '''Get the I{unsigned, (1st) eccentricity squared} (C{float}). 

781 ''' 

782 return fabs(self.e2) 

783 

784 @Property_RO 

785 def e21(self): 

786 '''Get 1 less I{1st eccentricity squared} (C{float}), M{1 - e**2} 

787 == M{1 - e2} == M{(1 - f)**2} == M{b**2 / a**2}, see C{b2_a2}. 

788 ''' 

789 return self._assert((_1_0 - self.f)**2, e21=_1_0 - self.e2, f0=_1_0) 

790 

791# _e2m = e21 # see I{Karney}'s Ellipsoid._e2m = 1 - _e2 

792 _1_e21 = a2_b2 # == M{1 / e21} == M{1 / (1 - e**2)} 

793 

794 @Property_RO 

795 def e22(self): 

796 '''Get the I{signed, 2nd eccentricity squared} (C{float}), M{e2 / (1 - e2) 

797 == e2 / (1 - f)**2 == (a / b)**2 - 1}, see C{a_b2e22}. 

798 ''' 

799 return self._assert(a_b2e22(self.a, self.b), e22=f2e22(self.f)) 

800 

801 @Property_RO 

802 def e22abs(self): 

803 '''Get the I{unsigned, 2nd eccentricity squared} (C{float}). 

804 ''' 

805 return fabs(self.e22) 

806 

807 @Property_RO 

808 def e32(self): 

809 '''Get the I{signed, 3rd eccentricity squared} (C{float}), M{e2 / (2 - e2) 

810 == (a**2 - b**2) / (a**2 + b**2)}, see C{a_b2e32}. 

811 ''' 

812 return self._assert(a_b2e32(self.a, self.b), e32=f2e32(self.f)) 

813 

814 @Property_RO 

815 def e32abs(self): 

816 '''Get the I{unsigned, 3rd eccentricity squared} (C{float}). 

817 ''' 

818 return fabs(self.e32) 

819 

820 @Property_RO 

821 def e4(self): 

822 '''Get the I{unsignd, (1st) eccentricity} to 4th power (C{float}), M{e**4 == e2**2}. 

823 ''' 

824 return Float(e4=self.e2**2 if self.e2 else _0_0) 

825 

826 eccentricity = e # eccentricity 

827# eccentricity2 = e2 # eccentricity squared 

828 eccentricity1st2 = e2 # first eccentricity squared, signed 

829 eccentricity2nd2 = e22 # second eccentricity squared, signed 

830 eccentricity3rd2 = e32 # third eccentricity squared, signed 

831 

832 def ecef(self, Ecef=None): 

833 '''Return U{ECEF<https://WikiPedia.org/wiki/ECEF>} converter. 

834 

835 @kwarg Ecef: ECEF class to use, default L{EcefKarney}. 

836 

837 @return: An ECEF converter for this C{ellipsoid}. 

838 

839 @raise TypeError: Invalid B{C{Ecef}}. 

840 

841 @see: Module L{pygeodesy.ecef}. 

842 ''' 

843 return _MODS.ecef._4Ecef(self, Ecef) 

844 

845 @Property_RO 

846 def _elliptic_e12(self): # see I{Karney}'s Ellipsoid._e12 

847 '''(INTERNAL) Elliptic helper for C{Rhumb}. 

848 ''' 

849 e12 = _over(self.e2, self.e2 - _1_0) # NOT DEPRECATED .e12! 

850 return _MODS.elliptic.Elliptic(e12) 

851 

852 @Property_RO 

853 def _elliptic_e22(self): # aka ._elliptic_ep2 

854 '''(INTERNAL) Elliptic helper for C{auxRectifying}, C{L}, C{Llat}. 

855 ''' 

856 return _MODS.elliptic.Elliptic(-self.e22abs) # complex 

857 

858 equatoradius = a # Requatorial 

859 

860 def e2s(self, s): 

861 '''Compute norm M{sqrt(1 - e2 * s**2)}. 

862 

863 @arg s: Sine value (C{scalar}). 

864 

865 @return: Norm (C{float}). 

866 

867 @raise ValueError: Invalid B{C{s}}. 

868 ''' 

869 return sqrt(self.e2s2(s)) if self.e2 else _1_0 

870 

871 def e2s2(self, s): 

872 '''Compute M{1 - e2 * s**2}. 

873 

874 @arg s: Sine value (C{scalar}). 

875 

876 @return: Result (C{float}). 

877 

878 @raise ValueError: Invalid B{C{s}}. 

879 ''' 

880 r = _1_0 

881 if self.e2: 

882 try: 

883 r -= self.e2 * Scalar(s=s)**2 

884 if r < 0: 

885 raise ValueError(_negative_) 

886 except (TypeError, ValueError) as x: 

887 t = self._DOT_(typename(Ellipsoid.e2s2)) 

888 raise _ValueError(t, s, cause=x) 

889 return r 

890 

891 @Property_RO 

892 def es(self): 

893 '''Get the I{signed (1st) eccentricity} (C{float}). 

894 

895 @see: Property L{e}. 

896 ''' 

897 # note, self.e is always non-negative 

898 return Float(es=copysign0(self.e, self.f)) # see .ups 

899 

900 def es_atanh(self, x): 

901 '''Compute M{es * atanh(es * x)} or M{-es * atan(es * x)} 

902 for I{oblate} respectively I{prolate} ellipsoids where 

903 I{es} is the I{signed} (1st) eccentricity. 

904 

905 @raise ValueError: Invalid B{C{x}}. 

906 

907 @see: Function U{Math::eatanhe<https://GeographicLib.SourceForge.io/ 

908 C++/doc/classGeographicLib_1_1Math.html>}. 

909 ''' 

910 return self._es_atanh(Scalar(x=x)) if self.f else _0_0 

911 

912 def _es_atanh(self, x): # see .albers._atanhee, .AuxLat._atanhee 

913 '''(INTERNAL) Helper for .es_atanh, ._es_taupf2 and ._exp_es_atanh. 

914 ''' 

915 es = self.es # signOf(es) == signOf(f) 

916 return es * (atanh(es * x) if es > 0 else # .isOblate 

917 (-atan(es * x) if es < 0 else # .isProlate 

918 _0_0)) # .isSpherical 

919 

920 @Property_RO 

921 def es_c(self): 

922 '''Get M{(1 - f) * exp(es_atanh(1))} (C{float}), M{b_a * exp(es_atanh(1))}. 

923 ''' 

924 return Float(es_c=(self._exp_es_atanh_1 * self.b_a) if self.f else _1_0) 

925 

926 def es_tauf(self, taup): 

927 '''Compute I{Karney}'s U{equations (19), (20) and (21) 

928 <https://ArXiv.org/abs/1002.1417>}. 

929 

930 @see: I{Karney}'s C++ method U{Math::tauf<https://GeographicLib. 

931 SourceForge.io/C++/doc/classGeographicLib_1_1Math.html>} and 

932 and I{Veness}' JavaScript method U{toLatLon<https://www. 

933 Movable-Type.co.UK/scripts/latlong-utm-mgrs.html>}. 

934 ''' 

935 t = Scalar(taup=taup) 

936 if self.f: # .isEllipsoidal 

937 a = fabs(t) 

938 T = (self._exp_es_atanh_1 if a > 70 else self._1_e21) * t 

939 if fabs(T * _EPSqrt) < _2_0: # handles +/- INF and NAN 

940 s = (a * _TOL) if a > _1_0 else _TOL 

941 for T, _, d in self._es_tauf3(t, T): # max 2 

942 if fabs(d) < s: 

943 break 

944 t = Scalar(tauf=T) 

945 return t 

946 

947 def _es_tauf3(self, taup, T, N=9): # in .utm.Utm._toLLEB 

948 '''(INTERNAL) Yield a 3-tuple C{(τi, iteration, delta)} for at most 

949 B{C{N}} Newton iterations, converging rapidly except when C{delta} 

950 toggles on +/-1.12e-16 or +/-4.47e-16, see C{.utm.Utm._toLLEB}. 

951 ''' 

952 e = self._1_e21 

953 _F2_ = Fsum(T).fsum2f_ # τ0 

954 _tf2 = self._es_taupf2 

955 for i in range(1, N + 1): 

956 a, h = _tf2(T) 

957 # = (taup - a) / hypot1(a) / ((e + T**2) / h) 

958 d = _over((taup - a) * (T**2 + e), hypot1(a) * h) 

959 T, d = _F2_(d) # τi, (τi - τi-1) 

960 yield T, i, d 

961 

962 def es_taupf(self, tau): 

963 '''Compute I{Karney}'s U{equations (7), (8) and (9) 

964 <https://ArXiv.org/abs/1002.1417>}. 

965 

966 @see: I{Karney}'s C++ method U{Math::taupf<https://GeographicLib. 

967 SourceForge.io/C++/doc/classGeographicLib_1_1Math.html>}. 

968 ''' 

969 t = Scalar(tau=tau) 

970 if self.f: # .isEllipsoidal 

971 t, _ = self._es_taupf2(t) 

972 t = Scalar(taupf=t) 

973 return t 

974 

975 def _es_taupf2(self, tau): 

976 '''(INTERNAL) Return 2-tuple C{(es_taupf(tau), hypot1(tau))}. 

977 ''' 

978 if _isfinite(tau): 

979 h = hypot1(tau) 

980 s = sinh(self._es_atanh(tau / h)) 

981 a = hypot1(s) * tau - h * s 

982 else: 

983 a, h = tau, INF 

984 return a, h 

985 

986 @Property_RO 

987 def _exp_es_atanh_1(self): 

988 '''(INTERNAL) Helper for .es_c and .es_tauf. 

989 ''' 

990 return exp(self._es_atanh(_1_0)) if self.es else _1_0 

991 

992 @Property_RO 

993 def f(self): 

994 '''Get the I{flattening} (C{scalar}), M{(a - b) / a}, C{0} for spherical, negative for prolate. 

995 ''' 

996 return self._f 

997 

998 @Property_RO 

999 def f_(self): 

1000 '''Get the I{inverse flattening} (C{scalar}), M{1 / f} == M{a / (a - b)}, C{0} for spherical, see C{a_b2f_}. 

1001 ''' 

1002 return self._f_ 

1003 

1004 @Property_RO 

1005 def f1(self): 

1006 '''Get the I{1 - flattening} (C{float}), M{f1 == 1 - f == b / a}. 

1007 

1008 @see: Property L{b_a}. 

1009 ''' 

1010 return Float(f1=_1_0 - self.f) 

1011 

1012 @Property_RO 

1013 def f2(self): 

1014 '''Get the I{2nd flattening} (C{float}), M{(a - b) / b == f / (1 - f)}, C{0} for spherical, see C{a_b2f2}. 

1015 ''' 

1016 return self._assert(self.a_b - _1_0, f2=f2f2(self.f)) 

1017 

1018 @deprecated_Property_RO 

1019 def geodesic(self): 

1020 '''DEPRECATED, use property C{geodesicw}.''' 

1021 return self.geodesicw 

1022 

1023 def geodesic_(self, exact=True): 

1024 '''Get the an I{exact} C{Geodesic...} instance for this ellipsoid. 

1025 

1026 @kwarg exact: If C{bool} return L{GeodesicExact}C{(exact=B{exact}, ...)}, 

1027 otherwise a L{Geodesic}, L{GeodesicExact} or L{GeodesicSolve} 

1028 instance for I{this} ellipsoid. 

1029 

1030 @return: The C{exact} geodesic (C{Geodesic...}). 

1031 

1032 @raise TypeError: Invalid B{C{exact}}. 

1033 

1034 @raise ValueError: Incompatible B{C{exact}} ellipsoid. 

1035 ''' 

1036 if isbool(exact): # for consistenccy with C{.rhumb_} 

1037 g = _MODS.geodesicx.GeodesicExact(self, C4order=30 if exact else 24, 

1038 name=self.name) 

1039 else: 

1040 g = exact 

1041 E = _xattr(g, ellipsoid=None) 

1042 if not (E is self and isinstance(g, self._Geodesics)): 

1043 raise _ValueError(exact=g, ellipsoid=E, txt_not_=self.name) 

1044 return g 

1045 

1046 @property_ROver 

1047 def _Geodesics(self): 

1048 '''(INTERNAL) Get all C{Geodesic...} classes, I{once}. 

1049 ''' 

1050 t = (_MODS.geodesicx.GeodesicExact, 

1051 _MODS.geodsolve.GeodesicSolve) 

1052 try: 

1053 t += (_MODS.geodesicw.Geodesic, 

1054 _MODS.geodesicw._wrapped.Geodesic) 

1055 except ImportError: 

1056 pass 

1057 return t # overwrite property_ROver 

1058 

1059 @property_RO 

1060 def geodesicw(self): 

1061 '''Get this ellipsoid's I{wrapped} U{geodesicw.Geodesic 

1062 <https://GeographicLib.SourceForge.io/Python/doc/code.html>}, provided 

1063 I{Karney}'s U{geographiclib<https://PyPI.org/project/geographiclib>} 

1064 package is installed. 

1065 ''' 

1066 # if not self.isEllipsoidal: 

1067 # raise _IsnotError(_ellipsoidal_, ellipsoid=self) 

1068 return _MODS.geodesicw.Geodesic(self) 

1069 

1070 @property_RO 

1071 def geodesicx(self): 

1072 '''Get this ellipsoid's I{exact} L{GeodesicExact}. 

1073 ''' 

1074 # if not self.isEllipsoidal: 

1075 # raise _IsnotError(_ellipsoidal_, ellipsoid=self) 

1076 return _MODS.geodesicx.GeodesicExact(self, name=self.name) 

1077 

1078 @property 

1079 def geodsolve(self): 

1080 '''Get this ellipsoid's L{GeodesicSolve}, the I{wrapper} around utility 

1081 U{GeodSolve<https://GeographicLib.SourceForge.io/C++/doc/GeodSolve.1.html>}, 

1082 provided the path to the C{GeodSolve} executable is specified with env 

1083 variable C{PYGEODESY_GEODSOLVE} or re-/set with this property.. 

1084 ''' 

1085 # if not self.isEllipsoidal: 

1086 # raise _IsnotError(_ellipsoidal_, ellipsoid=self) 

1087 return _MODS.geodsolve.GeodesicSolve(self, path=self._geodsolve, name=self.name) 

1088 

1089 @geodsolve.setter # PYCHOK setter! 

1090 def geodsolve(self, path): 

1091 '''Re-/set the (fully qualified) path to the U{GeodSolve 

1092 <https://GeographicLib.SourceForge.io/C++/doc/GeodSolve.1.html>} executable, 

1093 overriding env variable C{PYGEODESY_GEODSOLVE} (C{str}). 

1094 ''' 

1095 self._geodsolve = path 

1096 

1097 def hartzell4(self, pov, los=None): 

1098 '''Compute the intersection of this ellipsoid's surface and a Line-Of-Sight 

1099 from a Point-Of-View in space. 

1100 

1101 @arg pov: Point-Of-View outside this ellipsoid (C{Cartesian}, L{Ecef9Tuple} 

1102 or L{Vector3d}). 

1103 @kwarg los: Line-Of-Sight, I{direction} to this ellipsoid (L{Los}, L{Vector3d}) 

1104 or C{True} for the I{normal, perpendicular, plumb} to the surface 

1105 of this ellipsoid or C{False} or C{None} to point to its center. 

1106 

1107 @return: L{Vector4Tuple}C{(x, y, z, h)} with the cartesian coordinates C{x}, 

1108 C{y} and C{z} of the projection on or the intersection with this 

1109 ellipsoid and the I{distance} C{h} from B{C{pov}} to C{(x, y, z)} 

1110 along B{C{los}}, all in C{meter}, conventionally. 

1111 

1112 @raise IntersectionError: Null B{C{pov}} or B{C{los}} vector, or B{C{pov}} 

1113 is inside this ellipsoid or B{C{los}} points 

1114 outside this ellipsoid or in opposite direction. 

1115 

1116 @raise TypeError: Invalid B{C{pov}} or B{C{los}}. 

1117 

1118 @see: U{I{Satellite Line-of-Sight Intersection with Earth}<https://StephenHartzell. 

1119 Medium.com/satellite-line-of-sight-intersection-with-earth-d786b4a6a9b6>} and 

1120 methods L{Ellipsoid.height4} and L{Triaxial.hartzell4}. 

1121 ''' 

1122 try: 

1123 v, d, i = _MODS.triaxials._hartzell3(pov, los, self._triaxial) 

1124 except Exception as x: 

1125 raise IntersectionError(pov=pov, los=los, cause=x) 

1126 return Vector4Tuple(v.x, v.y, v.z, d, iteration=i, name__=self.hartzell4) 

1127 

1128 @Property_RO 

1129 def _hash(self): 

1130 return hash((self.a, self.f)) 

1131 

1132 def height4(self, xyz, normal=True): 

1133 '''Compute the projection on and the height of a cartesian above or below 

1134 this ellipsoid's surface. 

1135 

1136 @arg xyz: The cartesian (C{Cartesian}, L{Ecef9Tuple}, L{Vector3d}, 

1137 L{Vector3Tuple} or L{Vector4Tuple}). 

1138 @kwarg normal: If C{True}, the projection is perpendicular to (the nearest 

1139 point on) this ellipsoid's surface, otherwise the C{radial} 

1140 line to this ellipsoid's center (C{bool}). 

1141 

1142 @return: L{Vector4Tuple}C{(x, y, z, h)} with the cartesian coordinates C{x}, 

1143 C{y} and C{z} of the projection on and the height C{h} above or 

1144 below this ellipsoid's surface, all in C{meter}, conventionally. 

1145 

1146 @raise ValueError: Null B{C{xyz}}. 

1147 

1148 @raise TypeError: Non-cartesian B{C{xyz}}. 

1149 

1150 @see: U{Distance to<https://StackOverflow.com/questions/22959698/distance-from-given-point-to-given-ellipse>} 

1151 and U{intersection with<https://MathWorld.wolfram.com/Ellipse-LineIntersection.html>} an ellipse and 

1152 methods L{Ellipsoid.hartzell4} and L{Triaxial.height4}. 

1153 ''' 

1154 v = _MODS.vector3d._otherV3d(xyz=xyz) 

1155 r = v.length 

1156 

1157 a, b, i = self.a, self.b, None 

1158 if r < EPS0: # EPS 

1159 v = v.times(_0_0) 

1160 h = -a 

1161 

1162 elif self.isSpherical: 

1163 v = v.times(a / r) 

1164 h = r - a 

1165 

1166 elif normal: # perpendicular to ellipsoid 

1167 x, y = hypot(v.x, v.y), fabs(v.z) 

1168 if x < EPS0: # PYCHOK no cover 

1169 z = copysign0(b, v.z) 

1170 v = Vector3Tuple(v.x, v.y, z) 

1171 h = y - b # polar 

1172 elif y < EPS0: # PYCHOK no cover 

1173 t = a / r 

1174 v = v.times_(t, t, 0) # force z=0.0 

1175 h = x - a # equatorial 

1176 else: # normal in 1st quadrant 

1177 x, y, i = _MODS.triaxials._plumbTo3(x, y, self) 

1178 t, v = v, v.times_(x, x, y) 

1179 h = t.minus(v).length 

1180 

1181 else: # radial to ellipsoid's center 

1182 h = hypot_(a * v.z, b * v.x, b * v.y) 

1183 t = (a * b / h) if h > EPS0 else _0_0 # EPS 

1184 v = v.times(t) 

1185 h = r * (_1_0 - t) 

1186 

1187 return Vector4Tuple(v.x, v.y, v.z, h, iteration=i, name__=self.height4) 

1188 

1189 def _hubeny_2(self, phi2, phi1, lam21, scaled=True, squared=True): 

1190 '''(INTERNAL) like function C{pygeodesy.flatLocal_}/C{pygeodesy.hubeny_}, 

1191 returning the I{angular} distance in C{radians squared} or C{radians} 

1192 ''' 

1193 m, n = self.roc2_((phi2 + phi1) * _0_5, scaled=scaled) 

1194 h, r = (hypot2, self.a2_) if squared else (hypot, _1_0 / self.a) 

1195 return h(m * (phi2 - phi1), n * lam21) * r 

1196 

1197 @Property_RO 

1198 def isEllipsoidal(self): 

1199 '''Is this model I{ellipsoidal} (C{bool})? 

1200 ''' 

1201 return self.f != 0 

1202 

1203 @Property_RO 

1204 def isOblate(self): 

1205 '''Is this ellipsoid I{oblate} (C{bool})? I{Prolate} or 

1206 spherical otherwise. 

1207 ''' 

1208 return self.f > 0 

1209 

1210 @Property_RO 

1211 def isProlate(self): 

1212 '''Is this ellipsoid I{prolate} (C{bool})? I{Oblate} or 

1213 spherical otherwise. 

1214 ''' 

1215 return self.f < 0 

1216 

1217 @Property_RO 

1218 def isSpherical(self): 

1219 '''Is this ellipsoid I{spherical} (C{bool})? 

1220 ''' 

1221 return self.f == 0 

1222 

1223 def _Kseries(self, *AB8Ks): 

1224 '''(INTERNAL) Compute the 4-, 6- or 8-th order I{Krüger} Alpha 

1225 or Beta series coefficients per I{Karney}'s U{equations (35) 

1226 and (36)<https://ArXiv.org/pdf/1002.1417v3.pdf>}. 

1227 

1228 @arg AB8Ks: 8-Tuple of 8-th order I{Krüger} Alpha or Beta series 

1229 coefficient tuples. 

1230 

1231 @return: I{Krüger} series coefficients (L{KsOrder}C{-tuple}). 

1232 

1233 @see: I{Karney}'s 30-th order U{TMseries30 

1234 <https://GeographicLib.SourceForge.io/C++/doc/tmseries30.html>}. 

1235 ''' 

1236 k = self.KsOrder 

1237 if self.n: 

1238 ns = fpowers(self.n, k) 

1239 ks = tuple(fdot(AB8Ks[i][:k-i], *ns[i:]) for i in range(k)) 

1240 else: 

1241 ks = _0_0s(k) 

1242 return ks 

1243 

1244 @property_doc_(''' the I{Krüger} series' order (C{int}), see properties C{AlphaKs}, C{BetaKs}.''') 

1245 def KsOrder(self): 

1246 '''Get the I{Krüger} series' order (C{int} 4, 6 or 8). 

1247 ''' 

1248 return self._KsOrder 

1249 

1250 @KsOrder.setter # PYCHOK setter! 

1251 def KsOrder(self, order): 

1252 '''Set the I{Krüger} series' order (C{int} 4, 6 or 8). 

1253 

1254 @raise ValueError: Invalid B{C{order}}. 

1255 ''' 

1256 if not (isint(order) and _isin(order, 4, 6, 8)): 

1257 raise _ValueError(order=order) 

1258 if self._KsOrder != order: 

1259 Ellipsoid.AlphaKs._update(self) 

1260 Ellipsoid.BetaKs._update(self) 

1261 self._KsOrder = order 

1262 

1263 @Property_RO 

1264 def L(self): 

1265 '''Get the I{quarter meridian} C{L}, aka the C{polar distance} 

1266 along a meridian between the equator and a pole (C{meter}), 

1267 M{b * Elliptic(-e2 / (1 - e2)).cE} or M{b * PI / 2}. 

1268 ''' 

1269 r = self._elliptic_e22.cE if self.f else PI_2 

1270 return Distance(L=self.b * r) 

1271 

1272 def Llat(self, lat): 

1273 '''Return the I{meridional length}, the distance along a meridian 

1274 between the equator and a (geodetic) latitude, see C{L}. 

1275 

1276 @arg lat: Geodetic latitude (C{degrees90}). 

1277 

1278 @return: The meridional length at B{C{lat}}, negative on southern 

1279 hemisphere (C{meter}). 

1280 ''' 

1281 r = self._elliptic_e22.fEd(self.auxParametric(lat)) if self.f else Phid(lat) 

1282 return Distance(Llat=self.b * r) 

1283 

1284 Lmeridian = Llat # meridional distance 

1285 

1286 @property_RO 

1287 def _Lpd(self): 

1288 '''Get the I{quarter meridian} per degree (C{meter}), M{self.L / 90}. 

1289 ''' 

1290 return Meter(_Lpd=self.L / _90_0) 

1291 

1292 @property_RO 

1293 def _Lpr(self): 

1294 '''Get the I{quarter meridian} per radian (C{meter}), M{self.L / PI_2}. 

1295 ''' 

1296 return Meter(_Lpr=self.L / PI_2) 

1297 

1298 @deprecated_Property_RO 

1299 def majoradius(self): # PYCHOK no cover 

1300 '''DEPRECATED, use property C{a} or C{Requatorial}.''' 

1301 return self.a 

1302 

1303 def m2degrees(self, distance, lat=0): 

1304 '''Convert a distance to an angle along the equator or along 

1305 a parallel of (geodetic) latitude. 

1306 

1307 @arg distance: Distance (C{meter}). 

1308 @kwarg lat: Parallel latitude (C{degrees90}, C{str}). 

1309 

1310 @return: Angle (C{degrees}) or C{INF} for near-polar B{C{lat}}. 

1311 

1312 @raise RangeError: Latitude B{C{lat}} outside valid range and 

1313 L{rangerrors<pygeodesy.rangerrors>} is C{True}. 

1314 

1315 @raise ValueError: Invalid B{C{distance}} or B{C{lat}}. 

1316 ''' 

1317 return degrees(self.m2radians(distance, lat=lat)) 

1318 

1319 def m2radians(self, distance, lat=0): 

1320 '''Convert a distance to an angle along the equator or along 

1321 a parallel of (geodetic) latitude. 

1322 

1323 @arg distance: Distance (C{meter}). 

1324 @kwarg lat: Parallel latitude (C{degrees90}, C{str}). 

1325 

1326 @return: Angle (C{radians}) or C{INF} for near-polar B{C{lat}}. 

1327 

1328 @raise RangeError: Latitude B{C{lat}} outside valid range and 

1329 L{rangerrors<pygeodesy.rangerrors>} is C{True}. 

1330 

1331 @raise ValueError: Invalid B{C{distance}} or B{C{lat}}. 

1332 ''' 

1333 r = self.circle4(lat).radius if lat else self.a 

1334 return m2radians(distance, radius=r, lat=0) 

1335 

1336 @deprecated_Property_RO 

1337 def minoradius(self): # PYCHOK no cover 

1338 '''DEPRECATED, use property C{b}, C{polaradius} or C{Rpolar}.''' 

1339 return self.b 

1340 

1341 @Property_RO 

1342 def n(self): 

1343 '''Get the I{3rd flattening} (C{float}), M{f / (2 - f) == (a - b) / (a + b)}, see C{a_b2n}. 

1344 ''' 

1345 return self._assert(a_b2n(self.a, self.b), n=f2n(self.f)) 

1346 

1347 flattening = f 

1348 flattening1st = f 

1349 flattening2nd = f2 

1350 flattening3rd = n 

1351 

1352 polaradius = b # Rpolar 

1353 

1354# Q = A # I{meridian arc unit} C{Q}, the mean, meridional length I{per radian} 

1355 

1356 @deprecated_Property_RO 

1357 def quarteradius(self): # PYCHOK no cover 

1358 '''DEPRECATED, use property C{L} or method C{Llat}.''' 

1359 return self.L 

1360 

1361 @Property_RO 

1362 def R1(self): 

1363 '''Get the I{mean} earth radius per I{IUGG} (C{meter}), M{(2 * a + b) / 3 == a * (1 - f / 3)}. 

1364 

1365 @see: U{Earth radius<https://WikiPedia.org/wiki/Earth_radius>} 

1366 and method C{Rgeometric}. 

1367 ''' 

1368 r = Fsum(self.a, self.a, self.b).fover(_3_0) if self.f else self.a 

1369 return Radius(R1=r) 

1370 

1371 Rmean = R1 

1372 

1373 @Property_RO 

1374 def R2(self): 

1375 '''Get the I{authalic} earth radius (C{meter}), M{sqrt(c2)}. 

1376 

1377 @see: C{R2x}, C{c2}, C{area} and U{Earth radius 

1378 <https://WikiPedia.org/wiki/Earth_radius>}. 

1379 ''' 

1380 return Radius(R2=sqrt(self.c2) if self.f else self.a) 

1381# # Moritz, H. <https://Geodesy.Geology.Ohio-State.EDU/course/refpapers/00740128.pdf> 

1382# # R2 = (1 - 2/3 * e'2 + 26/45 * e'4 - 100/189 * e'6 + 7034/14175 * e'8) * rocPolar 

1383# # = (3 + e'2 * (-2 + e'2 * (26/15 + e'2 * (-100/63 + e'2 * 7034/4725)))) * rocPolar / 3 

1384# return Fhorner(self.e22, 3, -2, 26 / 15, -100 / 63, 7034 / 4725).fover(3 / self.rocPolar) 

1385 

1386 Rauthalic = R2 

1387 

1388 @Property_RO 

1389 def R2x(self): 

1390 '''Get the I{authalic} earth radius (C{meter}), M{sqrt(c2x)}. 

1391 

1392 @see: C{R2}, C{c2x} and C{areax}. 

1393 ''' 

1394 return Radius(R2x=sqrt(self.c2x) if self.f else self.a) 

1395 

1396 Rauthalicx = R2x 

1397 

1398 @Property_RO 

1399 def R3(self): 

1400 '''Get the I{volumetric} earth radius (C{meter}), M{(a * a * b)**(1/3)}. 

1401 

1402 @see: U{Earth radius<https://WikiPedia.org/wiki/Earth_radius>} and C{volume}. 

1403 ''' 

1404 r = (cbrt(self.b_a) * self.a) if self.f else self.a 

1405 return Radius(R3=r) 

1406 

1407 Rvolumetric = R3 

1408 

1409 def radians2m(self, rad, lat=0): 

1410 '''Convert an angle to the distance along the equator or along 

1411 a parallel of (geodetic) latitude. 

1412 

1413 @arg rad: The angle (C{radians}). 

1414 @kwarg lat: Parallel latitude (C{degrees90}, C{str}). 

1415 

1416 @return: Distance (C{meter}, same units as the equatorial 

1417 and polar radii) or C{0} for near-polar B{C{lat}}. 

1418 

1419 @raise RangeError: Latitude B{C{lat}} outside valid range and 

1420 L{rangerrors<pygeodesy.rangerrors>} is C{True}. 

1421 

1422 @raise ValueError: Invalid B{C{rad}} or B{C{lat}}. 

1423 ''' 

1424 r = self.circle4(lat).radius if lat else self.a 

1425 return radians2m(rad, radius=r, lat=0) 

1426 

1427 @Property_RO 

1428 def Rbiaxial(self): 

1429 '''Get the I{biaxial, quadratic} mean earth radius (C{meter}), M{sqrt((a**2 + b**2) / 2)}. 

1430 

1431 @see: C{Rtriaxial} 

1432 ''' 

1433 a, b = self.a, self.b 

1434 if b < a: 

1435 b = sqrt(_0_5 + self.b2_a2 * _0_5) * a 

1436 elif b > a: 

1437 b *= sqrt(_0_5 + self.a2_b2 * _0_5) 

1438 return Radius(Rbiaxial=b) 

1439 

1440 Requatorial = a # for consistent naming 

1441 

1442 def Rgeocentric(self, lat): 

1443 '''Compute the I{geocentric} earth radius of (geodetic) latitude. 

1444 

1445 @arg lat: Latitude (C{degrees90}). 

1446 

1447 @return: Geocentric earth radius (C{meter}). 

1448 

1449 @raise ValueError: Invalid B{C{lat}}. 

1450 

1451 @see: U{Geocentric Radius 

1452 <https://WikiPedia.org/wiki/Earth_radius#Geocentric_radius>} 

1453 ''' 

1454 r, a = self.a, Phid(lat) 

1455 if a and self.f: 

1456 if fabs(a) < PI_2: 

1457 s2, c2 = _s2_c2(a) 

1458 b2_a2_s2 = self.b2_a2 * s2 

1459 # R == sqrt((a2**2 * c2 + b2**2 * s2) / (a2 * c2 + b2 * s2)) 

1460 # == sqrt(a2**2 * (c2 + (b2 / a2)**2 * s2) / (a2 * (c2 + b2 / a2 * s2))) 

1461 # == sqrt(a2 * (c2 + (b2 / a2)**2 * s2) / (c2 + (b2 / a2) * s2)) 

1462 # == a * sqrt((c2 + b2_a2 * b2_a2 * s2) / (c2 + b2_a2 * s2)) 

1463 # == a * sqrt((c2 + b2_a2 * b2_a2_s2) / (c2 + b2_a2_s2)) 

1464 r *= sqrt((c2 + b2_a2_s2 * self.b2_a2) / (c2 + b2_a2_s2)) 

1465 else: 

1466 r = self.b 

1467 return Radius(Rgeocentric=r) 

1468 

1469 @Property_RO 

1470 def Rgeometric(self): 

1471 '''Get the I{geometric} mean earth radius (C{meter}), M{sqrt(a * b)}. 

1472 

1473 @see: C{R1}. 

1474 ''' 

1475 g = sqrt(self.a * self.b) if self.f else self.a 

1476 return Radius(Rgeometric=g) 

1477 

1478 def rhumb_(self, exact=True): 

1479 '''Get the an I{exact} C{Rhumb...} instance for this ellipsoid. 

1480 

1481 @kwarg exact: If C{bool} or C{None} return L{Rhumb}C{(exact=B{exact}, ...)}, 

1482 otherwise a L{Rhumb}, L{RhumbAux} or L{RhumbSolve} instance 

1483 for I{this} ellipsoid. 

1484 

1485 @return: The C{exact} rhumb (C{Rhumb...}). 

1486 

1487 @raise TypeError: Invalid B{C{exact}}. 

1488 

1489 @raise ValueError: Incompatible B{C{exact}} ellipsoid. 

1490 ''' 

1491 if isbool(exact): # use Rhumb for backward compatibility 

1492 r = _MODS.rhumb.ekx.Rhumb(self, exact=exact, name=self.name) 

1493 else: 

1494 r = exact 

1495 E = _xattr(r, ellipsoid=None) 

1496 if not (E is self and isinstance(r, self._Rhumbs)): 

1497 raise _ValueError(exact=r, ellipsosid=E, txt_not_=self.name) 

1498 return r 

1499 

1500 @property_RO 

1501 def rhumbaux(self): 

1502 '''Get this ellipsoid's I{Auxiliary} C{rhumb.RhumbAux}. 

1503 ''' 

1504 # if not self.isEllipsoidal: 

1505 # raise _IsnotError(_ellipsoidal_, ellipsoid=self) 

1506 return _MODS.rhumb.aux_.RhumbAux(self, name=self.name) 

1507 

1508 @property_RO 

1509 def rhumbekx(self): 

1510 '''Get this ellipsoid's I{Elliptic, Krüger} C{rhumb.Rhumb}. 

1511 ''' 

1512 # if not self.isEllipsoidal: 

1513 # raise _IsnotError(_ellipsoidal_, ellipsoid=self) 

1514 return _MODS.rhumb.ekx.Rhumb(self, name=self.name) 

1515 

1516 @property_ROver 

1517 def _Rhumbs(self): 

1518 '''(INTERNAL) Get all C{Rhumb...} classes, I{once}. 

1519 ''' 

1520 r = _MODS.rhumb 

1521 return (r.aux_.RhumbAux, # overwrite property_ROver 

1522 r.ekx.Rhumb, r.solve.RhumbSolve) 

1523 

1524 @property 

1525 def rhumbsolve(self): 

1526 '''Get this ellipsoid's L{RhumbSolve}, the I{wrapper} around utility 

1527 U{RhumbSolve<https://GeographicLib.SourceForge.io/C++/doc/GeodSolve.1.html>}, 

1528 provided the path to the C{RhumbSolve} executable is specified with env 

1529 variable C{PYGEODESY_RHUMBSOLVE} or re-/set with this property. 

1530 ''' 

1531 # if not self.isEllipsoidal: 

1532 # raise _IsnotError(_ellipsoidal_, ellipsoid=self) 

1533 return _MODS.rhumb.solve.RhumbSolve(self, path=self._rhumbsolve, name=self.name) 

1534 

1535 @rhumbsolve.setter # PYCHOK setter! 

1536 def rhumbsolve(self, path): 

1537 '''Re-/set the (fully qualified) path to the U{RhumbSolve 

1538 <https://GeographicLib.SourceForge.io/C++/doc/GeodSolve.1.html>} executable, 

1539 overriding env variable C{PYGEODESY_RHUMBSOLVE} (C{str}). 

1540 ''' 

1541 self._rhumbsolve = path 

1542 

1543 @deprecated_property_RO 

1544 def rhumbx(self): 

1545 '''DEPRECATED on 2023.11.28, use property C{rhumbekx}. ''' 

1546 return self.rhumbekx 

1547 

1548 def Rlat(self, lat): 

1549 '''I{Approximate} the earth radius of (geodetic) latitude. 

1550 

1551 @arg lat: Latitude (C{degrees90}). 

1552 

1553 @return: Approximate earth radius (C{meter}). 

1554 

1555 @raise RangeError: Latitude B{C{lat}} outside valid range and 

1556 L{rangerrors<pygeodesy.rangerrors>} is C{True}. 

1557 

1558 @raise TypeError: Invalid B{C{lat}}. 

1559 

1560 @raise ValueError: Invalid B{C{lat}}. 

1561 

1562 @note: C{Rlat(B{90})} equals C{Rpolar}. 

1563 

1564 @see: Method C{circle4}. 

1565 ''' 

1566 # r = a - (a - b) * |lat| / 90 

1567 r = self.a 

1568 if self.f and lat: # .isEllipsoidal 

1569 r -= (r - self.b) * fabs(Lat(lat)) / _90_0 

1570 r = Radius(Rlat=r) 

1571 return r 

1572 

1573 Rpolar = b # for consistent naming 

1574 

1575 def roc1_(self, sa, ca=None): 

1576 '''Compute the I{prime-vertical}, I{normal} radius of curvature 

1577 of (geodetic) latitude, I{unscaled}. 

1578 

1579 @arg sa: Sine of the latitude (C{float}, [-1.0..+1.0]). 

1580 @kwarg ca: Optional cosine of the latitude (C{float}, [-1.0..+1.0]) 

1581 to use an alternate formula. 

1582 

1583 @return: The prime-vertical radius of curvature (C{float}). 

1584 

1585 @note: The delta between both formulae with C{Ellipsoids.WGS84} 

1586 is less than 2 nanometer over the entire latitude range. 

1587 

1588 @see: Method L{roc2_} and class L{EcefYou}. 

1589 ''' 

1590 if not self.f: # .isSpherical 

1591 n = self.a 

1592 elif ca is None: 

1593 r = self.e2s2(sa) # see .roc2_ and _EcefBase._forward 

1594 n = sqrt(self.a2 / r) if r > EPS02 else _0_0 

1595 elif ca: # derived from EcefYou.forward 

1596 h = hypot(ca, self.b_a * sa) if sa else fabs(ca) 

1597 n = self.a / h 

1598 elif sa: 

1599 n = self.a2_b / fabs(sa) 

1600 else: 

1601 n = self.a 

1602 return n 

1603 

1604 def roc2(self, lat, scaled=False): 

1605 '''Compute the I{meridional} and I{prime-vertical}, I{normal} 

1606 radii of curvature of (geodetic) latitude. 

1607 

1608 @arg lat: Latitude (C{degrees90}). 

1609 @kwarg scaled: Scale prime_vertical by C{cos(radians(B{lat}))} (C{bool}). 

1610 

1611 @return: An L{Curvature2Tuple}C{(meridional, prime_vertical)} with 

1612 the radii of curvature. 

1613 

1614 @raise ValueError: Invalid B{C{lat}}. 

1615 

1616 @see: Methods L{roc2_} and L{roc1_}, U{Local, flat earth approximation 

1617 <https://www.EdWilliams.org/avform.htm#flat>} and meridional and 

1618 prime vertical U{Radii of Curvature<https://WikiPedia.org/wiki/ 

1619 Earth_radius#Radii_of_curvature>}. 

1620 ''' 

1621 return self.roc2_(Phid(lat), scaled=scaled) 

1622 

1623 def roc2_(self, phi, scaled=False): 

1624 '''Compute the I{meridional} and I{prime-vertical}, I{normal} radii of 

1625 curvature of (geodetic) latitude. 

1626 

1627 @arg phi: Latitude (C{radians}). 

1628 @kwarg scaled: Scale prime_vertical by C{cos(B{phi})} (C{bool}). 

1629 

1630 @return: An L{Curvature2Tuple}C{(meridional, prime_vertical)} with the 

1631 radii of curvature. 

1632 

1633 @raise ValueError: Invalid B{C{phi}}. 

1634 

1635 @see: Methods L{roc2} and L{roc1_}, property L{rocEquatorial2}, U{Local, 

1636 flat earth approximation<https://www.EdWilliams.org/avform.htm#flat>} 

1637 and the meridional and prime vertical U{Radii of Curvature 

1638 <https://WikiPedia.org/wiki/Earth_radius#Radii_of_curvature>}. 

1639 ''' 

1640 a = fabs(Phi(phi)) 

1641 if self.f: 

1642 r = self.e2s2(sin(a)) 

1643 if r > EPS02: 

1644 n = self.a / sqrt(r) 

1645 m = n * self.e21 / r 

1646 else: 

1647 m = n = _0_0 

1648 else: 

1649 m = n = self.a 

1650 if scaled and a: 

1651 n *= cos(a) if a < PI_2 else _0_0 

1652 return Curvature2Tuple(m, n) 

1653 

1654 def rocAzimuth(self, lat, azimuth): 

1655 '''Compute the I{directional} radius of curvature of (geodetic) latitude 

1656 and C{azimuth} compass direction. 

1657 

1658 @see: Method L{rocBearing<Ellipsoid.rocBearing>} for details, using C{azimuth} for C{bearing}. 

1659 ''' 

1660 return Radius(rocAzimuth=self._rocDirectional(lat, Azimuth(azimuth))) 

1661 

1662 def rocBearing(self, lat, bearing): 

1663 '''Compute the I{directional} radius of curvature of (geodetic) latitude 

1664 and C{bearing} compass direction. 

1665 

1666 @arg lat: Latitude (C{degrees90}). 

1667 @arg bearing: Direction (compass C{degrees360}). 

1668 

1669 @return: Directional radius of curvature (C{meter}). 

1670 

1671 @raise RangeError: Latitude B{C{lat}} outside valid range and 

1672 L{rangerrors<pygeodesy.rangerrors>} is C{True}. 

1673 

1674 @raise ValueError: Invalid B{C{lat}} or B{C{bearing}}. 

1675 

1676 @see: U{Radii of Curvature<https://WikiPedia.org/wiki/Earth_radius#Radii_of_curvature>} 

1677 ''' 

1678 return Radius(rocBearing=self._rocDirectional(lat, Bearing(bearing))) 

1679 

1680 def _rocDirectional(self, lat, deg): 

1681 '''(INTERNAL) Helper for C{rocAzimuth} and C{rocBearing}. 

1682 ''' 

1683 if self.f: 

1684 s2, c2 = _s2_c2(radians(deg)) 

1685 m, n = self.roc2_(Phid(lat)) 

1686 if n < m: # == n / (c2 * n / m + s2) 

1687 c2 *= n / m 

1688 elif m < n: # == m / (c2 + s2 * m / n) 

1689 s2 *= m / n 

1690 n = m 

1691 r = _over(n, c2 + s2) # == 1 / (c2 / m + s2 / n) 

1692 else: 

1693 r = self.b # == self.a 

1694 return r 

1695 

1696 @Property_RO 

1697 def rocEquatorial2(self): 

1698 '''Get the I{meridional} and I{prime-vertical}, I{normal} radii of curvature 

1699 at the equator as L{Curvature2Tuple}C{(meridional, prime_vertical)}. 

1700 

1701 @see: Methods L{rocMeridional} and L{rocPrimeVertical}, properties L{b2_a}, 

1702 L{a2_b}, C{rocPolar} and polar and equatorial U{Radii of Curvature 

1703 <https://WikiPedia.org/wiki/Earth_radius#Radii_of_curvature>}. 

1704 ''' 

1705 m = self.b2_a if self.f else self.a 

1706 return Curvature2Tuple(m, self.a) 

1707 

1708 def rocGauss(self, lat): 

1709 '''Compute the I{Gaussian} radius of curvature of (geodetic) latitude. 

1710 

1711 @arg lat: Latitude (C{degrees90}). 

1712 

1713 @return: Gaussian radius of curvature (C{meter}). 

1714 

1715 @raise ValueError: Invalid B{C{lat}}. 

1716 

1717 @see: Non-directional U{Radii of Curvature<https://WikiPedia.org/wiki/ 

1718 Earth_radius#Radii_of_curvature>} 

1719 ''' 

1720 # using ... 

1721 # m, n = self.roc2_(Phid(lat)) 

1722 # return sqrt(m * n) 

1723 # ... requires 1 or 2 sqrt 

1724 g = self.b 

1725 if self.f: 

1726 s2, c2 = _s2_c2(Phid(lat)) 

1727 g = _over(g, c2 + self.b2_a2 * s2) 

1728 return Radius(rocGauss=g) 

1729 

1730 def rocMean(self, lat): 

1731 '''Compute the I{mean} radius of curvature of (geodetic) latitude. 

1732 

1733 @arg lat: Latitude (C{degrees90}). 

1734 

1735 @return: Mean radius of curvature (C{meter}). 

1736 

1737 @raise ValueError: Invalid B{C{lat}}. 

1738 

1739 @see: Non-directional U{Radii of Curvature<https://WikiPedia.org/wiki/ 

1740 Earth_radius#Radii_of_curvature>} 

1741 ''' 

1742 if self.f: 

1743 m, n = self.roc2_(Phid(lat)) 

1744 m *= _over(n * _2_0, m + n) # == 2 / (1 / m + 1 / n) 

1745 else: 

1746 m = self.a 

1747 return Radius(rocMean=m) 

1748 

1749 def rocMeridional(self, lat): 

1750 '''Compute the I{meridional} radius of curvature of (geodetic) latitude. 

1751 

1752 @arg lat: Latitude (C{degrees90}). 

1753 

1754 @return: Meridional radius of curvature (C{meter}). 

1755 

1756 @raise ValueError: Invalid B{C{lat}}. 

1757 

1758 @see: Methods L{roc2} and L{roc2_}, U{Local, flat earth approximation 

1759 <https://www.EdWilliams.org/avform.htm#flat>} and U{Radii of 

1760 Curvature<https://WikiPedia.org/wiki/Earth_radius#Radii_of_curvature>}. 

1761 ''' 

1762 r = self.roc2_(Phid(lat)) if lat else self.rocEquatorial2 

1763 return Radius(rocMeridional=r.meridional) 

1764 

1765 rocPolar = a2_b # synonymous 

1766 

1767 def rocPrimeVertical(self, lat): 

1768 '''Compute the I{prime-vertical}, I{normal} radius of curvature of 

1769 (geodetic) latitude, aka the I{transverse} radius of curvature. 

1770 

1771 @arg lat: Latitude (C{degrees90}). 

1772 

1773 @return: Prime-vertical radius of curvature (C{meter}). 

1774 

1775 @raise ValueError: Invalid B{C{lat}}. 

1776 

1777 @see: Methods L{roc2}, L{roc2_} and L{roc1_}, U{Local, flat earth 

1778 approximation<https://www.EdWilliams.org/avform.htm#flat>} and 

1779 U{Radii of Curvature<https://WikiPedia.org/wiki/ 

1780 Earth_radius#Radii_of_curvature>}. 

1781 ''' 

1782 r = self.roc2_(Phid(lat)) if lat else self.rocEquatorial2 

1783 return Radius(rocPrimeVertical=r.prime_vertical) 

1784 

1785 rocTransverse = rocPrimeVertical # synonymous 

1786 

1787 @deprecated_Property_RO 

1788 def Rquadratic(self): # PYCHOK no cover 

1789 '''DEPRECATED, use property C{Rbiaxial} or C{Rtriaxial}.''' 

1790 return self.Rbiaxial 

1791 

1792 @deprecated_Property_RO 

1793 def Rr(self): # PYCHOK no cover 

1794 '''DEPRECATED, use property C{Rrectifying}.''' 

1795 return self.Rrectifying 

1796 

1797 @Property_RO 

1798 def Rrectifying(self): 

1799 '''Get the I{rectifying} earth radius (C{meter}), M{((a**(3/2) + b**(3/2)) / 2)**(2/3)}. 

1800 

1801 @see: U{Earth radius<https://WikiPedia.org/wiki/Earth_radius>}. 

1802 ''' 

1803 r = self.a 

1804 if self.f: 

1805 r *= cbrt2((sqrt3(self.b_a) + _1_0) * _0_5) 

1806 return Radius(Rrectifying=r) 

1807 

1808 @deprecated_Property_RO 

1809 def Rs(self): # PYCHOK no cover 

1810 '''DEPRECATED, use property C{Rgeometric}.''' 

1811 return self.Rgeometric 

1812 

1813 @Property_RO 

1814 def Rtriaxial(self): 

1815 '''Get the I{triaxial, quadratic} mean earth radius (C{meter}), M{sqrt((3 * a**2 + b**2) / 4)}. 

1816 

1817 @see: C{Rbiaxial} 

1818 ''' 

1819 q, b = self.a, self.b 

1820 if b < q: 

1821 q *= sqrt((self.b2_a2 + _3_0) * _0_25) 

1822 elif b > q: 

1823 q = sqrt((self.a2_b2 * _3_0 + _1_0) * _0_25) * b 

1824 return Radius(Rtriaxial=q) 

1825 

1826 def toEllipsoid2(self, **name): 

1827 '''Get a copy of this ellipsoid as an L{Ellipsoid2}. 

1828 

1829 @kwarg name: Optional, unique C{B{name}=NN} (C{str}). 

1830 

1831 @see: Property C{a_f}. 

1832 ''' 

1833 return Ellipsoid2(self, None, **name) 

1834 

1835 def toStr(self, prec=8, terse=4, **sep_name): # PYCHOK expected 

1836 '''Return this ellipsoid as a text string. 

1837 

1838 @kwarg prec: Number of decimal digits, unstripped (C{int}). 

1839 @kwarg terse: Limit the number of items (C{int}, 0...18), 

1840 use C{B{terse}=0} or C{=None} for all. 

1841 @kwarg sep_name: Optional C{B{name}=NN} (C{str}) or C{None} 

1842 to exclude this ellipsoid's name and separator 

1843 C{B{sep}=", "} to join the items (C{str}). 

1844 

1845 @return: This C{Ellipsoid}'s attributes (C{str}). 

1846 ''' 

1847 E = Ellipsoid 

1848 t = (E.a, E.f, E.f_, E.b, E.f2, E.n, E.e, 

1849 E.e2, E.e21, E.e22, E.e32, 

1850 E.A, E.L, E.R1, E.R2, E.R3, 

1851 E.Rbiaxial, E.Rtriaxial) 

1852 if terse: 

1853 t = t[:terse] 

1854 return self._instr(prec=prec, props=t, **sep_name) 

1855 

1856 def toTriaxial(self, **name): 

1857 '''Convert this ellipsoid to a L{Triaxial_}. 

1858 

1859 @kwarg name: Optional C{B{name}=NN} (C{str}). 

1860 

1861 @return: A L{Triaxial_} or L{Triaxial} with the C{X} axis 

1862 pointing east and C{Z} pointing north. 

1863 

1864 @see: Method L{Triaxial_.toEllipsoid}. 

1865 ''' 

1866 T = self._triaxial 

1867 return T.copy(**name) if name else T 

1868 

1869 @property_RO 

1870 def _triaxial(self): 

1871 '''(INTERNAL) Get this ellipsoid's un-/ordered C{Triaxial/_}. 

1872 ''' 

1873 a, b, m = self.a, self.b, _MODS.triaxials 

1874 T = m.Triaxial if a > b else m.Triaxial_ 

1875 return T(a, a, b, name=self.name) 

1876 

1877 @Property_RO 

1878 def volume(self): 

1879 '''Get the ellipsoid's I{volume} (C{meter**3}), M{4 / 3 * PI * R3**3}. 

1880 

1881 @see: C{R3}. 

1882 ''' 

1883 return Meter3(volume=self.a2 * self.b * PI_3 * _4_0) 

1884 

1885 

1886class Ellipsoid2(Ellipsoid): 

1887 '''An L{Ellipsoid} specified by I{equatorial} radius and I{flattening}. 

1888 ''' 

1889 def __init__(self, a, f=None, **name): 

1890 '''New L{Ellipsoid2}. 

1891 

1892 @arg a: Equatorial radius, semi-axis (C{meter}) or a previous 

1893 L{Ellipsoid} instance. 

1894 @arg f: Flattening: (C{float} < 1.0, negative for I{prolate}), 

1895 if B{C{a}} is in C{meter}. 

1896 @kwarg name: Optional, unique C{B{name}=NN} (C{str}). 

1897 

1898 @raise NameError: Ellipsoid with that B{C{name}} already exists. 

1899 

1900 @raise ValueError: Invalid B{C{a}} or B{C{f}}. 

1901 

1902 @note: C{abs(B{f}) < EPS} is forced to C{B{f}=0}, I{spherical}. 

1903 Negative C{B{f}} produces a I{prolate} ellipsoid. 

1904 ''' 

1905 if f is None and isinstance(a, Ellipsoid): 

1906 Ellipsoid.__init__(self, a.a, f =a.f, 

1907 b=a.b, f_=a.f_, **name) 

1908 else: 

1909 Ellipsoid.__init__(self, a, f=f, **name) 

1910 

1911 

1912def _ispherical_a_b(a, b): 

1913 '''(INTERNAL) C{True} for spherical or invalid C{a} or C{b}. 

1914 ''' 

1915 return a < EPS0 or b < EPS0 or fabs(a - b) < EPS0 

1916 

1917 

1918def _ispherical_f(f): 

1919 '''(INTERNAL) C{True} for spherical or invalid C{f}. 

1920 ''' 

1921 return f > EPS1 or fabs(f) < EPS 

1922 

1923 

1924def _ispherical_f_(f_): 

1925 '''(INTERNAL) C{True} for spherical or invalid C{f_}. 

1926 ''' 

1927 f_ = fabs(f_) 

1928 return f_ < EPS or f_ > _1_EPS 

1929 

1930 

1931def a_b2e(a, b): 

1932 '''Return C{e}, the I{1st eccentricity} for a given I{equatorial} and I{polar} radius. 

1933 

1934 @arg a: Equatorial radius (C{scalar} > 0). 

1935 @arg b: Polar radius (C{scalar} > 0). 

1936 

1937 @return: The I{unsigned}, (1st) eccentricity (C{float} or C{0}), M{sqrt(1 - (b / a)**2)}. 

1938 

1939 @note: The result is always I{non-negative} and C{0} for I{near-spherical} ellipsoids. 

1940 ''' 

1941 e2 = _a2b2e2(a, b, b2=False) 

1942 return Float(e=sqrt(fabs(e2)) if e2 else _0_0) # == sqrt(fabs((a - b) * (a + b))) / a 

1943 

1944 

1945def a_b2e2(a, b): 

1946 '''Return C{e2}, the I{1st eccentricity squared} for a given I{equatorial} and I{polar} radius. 

1947 

1948 @arg a: Equatorial radius (C{scalar} > 0). 

1949 @arg b: Polar radius (C{scalar} > 0). 

1950 

1951 @return: The I{signed}, (1st) eccentricity I{squared} (C{float} or C{0}), M{1 - (b / a)**2}. 

1952 

1953 @note: The result is positive for I{oblate}, negative for I{prolate} or C{0} 

1954 for I{near-spherical} ellipsoids. 

1955 ''' 

1956 return Float(e2=_a2b2e2(a, b, b2=False)) 

1957 

1958 

1959def a_b2e22(a, b): 

1960 '''Return C{e22}, the I{2nd eccentricity squared} for a given I{equatorial} and I{polar} radius. 

1961 

1962 @arg a: Equatorial radius (C{scalar} > 0). 

1963 @arg b: Polar radius (C{scalar} > 0). 

1964 

1965 @return: The I{signed}, 2nd eccentricity I{squared} (C{float} or C{0}), M{(a / b)**2 - 1}. 

1966 

1967 @note: The result is positive for I{oblate}, negative for I{prolate} or C{0} 

1968 for I{near-spherical} ellipsoids. 

1969 ''' 

1970 return Float(e22=_a2b2e2(a, b, a2=False)) 

1971 

1972 

1973def a_b2e32(a, b): 

1974 '''Return C{e32}, the I{3rd eccentricity squared} for a given I{equatorial} and I{polar} radius. 

1975 

1976 @arg a: Equatorial radius (C{scalar} > 0). 

1977 @arg b: Polar radius (C{scalar} > 0). 

1978 

1979 @return: The I{signed}, 3rd eccentricity I{squared} (C{float} or C{0}), 

1980 M{(a**2 - b**2) / (a**2 + b**2)}. 

1981 

1982 @note: The result is positive for I{oblate}, negative for I{prolate} or C{0} 

1983 for I{near-spherical} ellipsoids. 

1984 ''' 

1985 return Float(e32=_a2b2e2(a, b)) 

1986 

1987 

1988def _a2b2e2(a, b, a2=True, b2=True): 

1989 '''(INTERNAL) Helper for C{a_b2e}, C{a_b2e2}, C{a_b2e22} and C{a_b2e32}. 

1990 ''' 

1991 if _ispherical_a_b(a, b): 

1992 e2 = _0_0 

1993 else: # a > 0, b > 0 

1994 a, b = (_1_0, b / a) if a > b else (a / b, _1_0) 

1995 a2b2 = float(a - b) * (a + b) 

1996 e2 = _over(a2b2, (a**2 if a2 else _0_0) + 

1997 (b**2 if b2 else _0_0)) if a2b2 else _0_0 

1998 return e2 

1999 

2000 

2001def a_b2f(a, b): 

2002 '''Return C{f}, the I{flattening} for a given I{equatorial} and I{polar} radius. 

2003 

2004 @arg a: Equatorial radius (C{scalar} > 0). 

2005 @arg b: Polar radius (C{scalar} > 0). 

2006 

2007 @return: The flattening (C{scalar} or C{0}), M{(a - b) / a}. 

2008 

2009 @note: The result is positive for I{oblate}, negative for I{prolate} or C{0} 

2010 for I{near-spherical} ellipsoids. 

2011 ''' 

2012 f = 0 if _ispherical_a_b(a, b) else _over(float(a - b), a) 

2013 return _f_0_0 if _ispherical_f(f) else Float(f=f) 

2014 

2015 

2016def a_b2f_(a, b): 

2017 '''Return C{f_}, the I{inverse flattening} for a given I{equatorial} and I{polar} radius. 

2018 

2019 @arg a: Equatorial radius (C{scalar} > 0). 

2020 @arg b: Polar radius (C{scalar} > 0). 

2021 

2022 @return: The inverse flattening (C{scalar} or C{0}), M{a / (a - b)}. 

2023 

2024 @note: The result is positive for I{oblate}, negative for I{prolate} or C{0} 

2025 for I{near-spherical} ellipsoids. 

2026 ''' 

2027 f_ = 0 if _ispherical_a_b(a, b) else _over(a, float(a - b)) 

2028 return _f__0_0 if _ispherical_f_(f_) else Float(f_=f_) 

2029 

2030 

2031def a_b2f2(a, b): 

2032 '''Return C{f2}, the I{2nd flattening} for a given I{equatorial} and I{polar} radius. 

2033 

2034 @arg a: Equatorial radius (C{scalar} > 0). 

2035 @arg b: Polar radius (C{scalar} > 0). 

2036 

2037 @return: The I{signed}, 2nd flattening (C{scalar} or C{0}), M{(a - b) / b}. 

2038 

2039 @note: The result is positive for I{oblate}, negative for I{prolate} or C{0} 

2040 for I{near-spherical} ellipsoids. 

2041 ''' 

2042 t = 0 if _ispherical_a_b(a, b) else float(a - b) 

2043 return Float(f2=_0_0 if fabs(t) < EPS0 else _over(t, b)) 

2044 

2045 

2046def a_b2n(a, b): 

2047 '''Return C{n}, the I{3rd flattening} for a given I{equatorial} and I{polar} radius. 

2048 

2049 @arg a: Equatorial radius (C{scalar} > 0). 

2050 @arg b: Polar radius (C{scalar} > 0). 

2051 

2052 @return: The I{signed}, 3rd flattening (C{scalar} or C{0}), M{(a - b) / (a + b)}. 

2053 

2054 @note: The result is positive for I{oblate}, negative for I{prolate} or C{0} 

2055 for I{near-spherical} ellipsoids. 

2056 ''' 

2057 t = 0 if _ispherical_a_b(a, b) else float(a - b) 

2058 return Float(n=_0_0 if fabs(t) < EPS0 else _over(t, a + b)) 

2059 

2060 

2061def a_f2b(a, f): 

2062 '''Return C{b}, the I{polar} radius for a given I{equatorial} radius and I{flattening}. 

2063 

2064 @arg a: Equatorial radius (C{scalar} > 0). 

2065 @arg f: Flattening (C{scalar} < 1, negative for I{prolate}). 

2066 

2067 @return: The polar radius (C{float}), M{a * (1 - f)}. 

2068 ''' 

2069 b = a if _ispherical_f(f) else (a * (_1_0 - f)) 

2070 return Radius_(b=a if _ispherical_a_b(a, b) else b) 

2071 

2072 

2073def a_f_2b(a, f_): 

2074 '''Return C{b}, the I{polar} radius for a given I{equatorial} radius and I{inverse flattening}. 

2075 

2076 @arg a: Equatorial radius (C{scalar} > 0). 

2077 @arg f_: Inverse flattening (C{scalar} >>> 1). 

2078 

2079 @return: The polar radius (C{float}), M{a * (f_ - 1) / f_}. 

2080 ''' 

2081 b = a if _ispherical_f_(f_) else _over(a * (f_ - _1_0), f_) 

2082 return Radius_(b=a if _ispherical_a_b(a, b) else b) 

2083 

2084 

2085def b_f2a(b, f): 

2086 '''Return C{a}, the I{equatorial} radius for a given I{polar} radius and I{flattening}. 

2087 

2088 @arg b: Polar radius (C{scalar} > 0). 

2089 @arg f: Flattening (C{scalar} < 1, negative for I{prolate}). 

2090 

2091 @return: The equatorial radius (C{float}), M{b / (1 - f)}. 

2092 ''' 

2093 t = _1_0 - f 

2094 a = b if fabs(t) < EPS0 else _over(b, t) 

2095 return Radius_(a=b if _ispherical_a_b(a, b) else a) 

2096 

2097 

2098def b_f_2a(b, f_): 

2099 '''Return C{a}, the I{equatorial} radius for a given I{polar} radius and I{inverse flattening}. 

2100 

2101 @arg b: Polar radius (C{scalar} > 0). 

2102 @arg f_: Inverse flattening (C{scalar} >>> 1). 

2103 

2104 @return: The equatorial radius (C{float}), M{b * f_ / (f_ - 1)}. 

2105 ''' 

2106 t = f_ - _1_0 

2107 a = b if _ispherical_f_(f_) or fabs(t) < EPS0 \ 

2108 or fabs(t - f_) < EPS0 else _over(b * f_, t) 

2109 return Radius_(a=b if _ispherical_a_b(a, b) else a) 

2110 

2111 

2112def e2f(e): 

2113 '''Return C{f}, the I{flattening} for a given I{1st eccentricity}. 

2114 

2115 @arg e: The (1st) eccentricity (0 <= C{float} < 1) 

2116 

2117 @return: The flattening (C{scalar} or C{0}). 

2118 

2119 @see: Function L{e22f}. 

2120 ''' 

2121 return e22f(e**2) 

2122 

2123 

2124def e22f(e2): 

2125 '''Return C{f}, the I{flattening} for a given I{1st eccentricity squared}. 

2126 

2127 @arg e2: The (1st) eccentricity I{squared}, I{signed} (L{NINF} < C{float} < 1) 

2128 

2129 @return: The flattening (C{float} or C{0}), M{e2 / (sqrt(1 - e2) + 1)}. 

2130 ''' 

2131 return Float(f=_over(e2, sqrt(_1_0 - e2) + _1_0)) if e2 and e2 < _1_0 else _f_0_0 

2132 

2133 

2134def f2e2(f): 

2135 '''Return C{e2}, the I{1st eccentricity squared} for a given I{flattening}. 

2136 

2137 @arg f: Flattening (C{scalar} < 1, negative for I{prolate}). 

2138 

2139 @return: The I{signed}, (1st) eccentricity I{squared} (C{float} < 1), M{f * (2 - f)}. 

2140 

2141 @note: The result is positive for I{oblate}, negative for I{prolate} or C{0} 

2142 for I{near-spherical} ellipsoids. 

2143 

2144 @see: U{Eccentricity conversions<https://GeographicLib.SourceForge.io/ 

2145 C++/doc/classGeographicLib_1_1Ellipsoid.html>} and U{Flattening 

2146 <https://WikiPedia.org/wiki/Flattening>}. 

2147 ''' 

2148 return Float(e2=_0_0 if _ispherical_f(f) else (f * (_2_0 - f))) 

2149 

2150 

2151def f2e22(f): 

2152 '''Return C{e22}, the I{2nd eccentricity squared} for a given I{flattening}. 

2153 

2154 @arg f: Flattening (C{scalar} < 1, negative for I{prolate}). 

2155 

2156 @return: The I{signed}, 2nd eccentricity I{squared} (C{float} > -1 or C{INF}), 

2157 M{f * (2 - f) / (1 - f)**2}. 

2158 

2159 @note: The result is positive for I{oblate}, negative for I{prolate} or C{0} 

2160 for near-spherical ellipsoids. 

2161 

2162 @see: U{Eccentricity conversions<https://GeographicLib.SourceForge.io/ 

2163 C++/doc/classGeographicLib_1_1Ellipsoid.html>}. 

2164 ''' 

2165 # e2 / (1 - e2) == f * (2 - f) / (1 - f)**2 

2166 t = (_1_0 - f)**2 

2167 return Float(e22=INF if t < EPS0 else _over(f2e2(f), t)) # PYCHOK type 

2168 

2169 

2170def f2e32(f): 

2171 '''Return C{e32}, the I{3rd eccentricity squared} for a given I{flattening}. 

2172 

2173 @arg f: Flattening (C{scalar} < 1, negative for I{prolate}). 

2174 

2175 @return: The I{signed}, 3rd eccentricity I{squared} (C{float}), 

2176 M{f * (2 - f) / (1 + (1 - f)**2)}. 

2177 

2178 @note: The result is positive for I{oblate}, negative for I{prolate} or C{0} 

2179 for I{near-spherical} ellipsoids. 

2180 

2181 @see: U{Eccentricity conversions<https://GeographicLib.SourceForge.io/ 

2182 C++/doc/classGeographicLib_1_1Ellipsoid.html>}. 

2183 ''' 

2184 # e2 / (2 - e2) == f * (2 - f) / (1 + (1 - f)**2) 

2185 e2 = f2e2(f) 

2186 return Float(e32=_over(e2, _2_0 - e2)) 

2187 

2188 

2189def f_2f(f_): 

2190 '''Return C{f}, the I{flattening} for a given I{inverse flattening}. 

2191 

2192 @arg f_: Inverse flattening (C{scalar} >>> 1). 

2193 

2194 @return: The flattening (C{scalar} or C{0}), M{1 / f_}. 

2195 

2196 @note: The result is positive for I{oblate}, negative for I{prolate} or C{0} 

2197 for I{near-spherical} ellipsoids. 

2198 ''' 

2199 f = 0 if _ispherical_f_(f_) else _over(_1_0, f_) 

2200 return _f_0_0 if _ispherical_f(f) else Float(f=f) # PYCHOK type 

2201 

2202 

2203def f2f_(f): 

2204 '''Return C{f_}, the I{inverse flattening} for a given I{flattening}. 

2205 

2206 @arg f: Flattening (C{scalar} < 1, negative for I{prolate}). 

2207 

2208 @return: The inverse flattening (C{scalar} or C{0}), M{1 / f}. 

2209 

2210 @note: The result is positive for I{oblate}, negative for I{prolate} or C{0} 

2211 for I{near-spherical} ellipsoids. 

2212 ''' 

2213 f_ = 0 if _ispherical_f(f) else _over(_1_0, f) 

2214 return _f__0_0 if _ispherical_f_(f_) else Float(f_=f_) # PYCHOK type 

2215 

2216 

2217def f2f2(f): 

2218 '''Return C{f2}, the I{2nd flattening} for a given I{flattening}. 

2219 

2220 @arg f: Flattening (C{scalar} < 1, negative for I{prolate}). 

2221 

2222 @return: The I{signed}, 2nd flattening (C{scalar} or C{INF}), M{f / (1 - f)}. 

2223 

2224 @note: The result is positive for I{oblate}, negative for I{prolate} or C{0} 

2225 for I{near-spherical} ellipsoids. 

2226 

2227 @see: U{Eccentricity conversions<https://GeographicLib.SourceForge.io/ 

2228 C++/doc/classGeographicLib_1_1Ellipsoid.html>} and U{Flattening 

2229 <https://WikiPedia.org/wiki/Flattening>}. 

2230 ''' 

2231 t = _1_0 - f 

2232 return Float(f2=_0_0 if _ispherical_f(f) else 

2233 (INF if fabs(t) < EPS else _over(f, t))) # PYCHOK type 

2234 

2235 

2236def f2n(f): 

2237 '''Return C{n}, the I{3rd flattening} for a given I{flattening}. 

2238 

2239 @arg f: Flattening (C{scalar} < 1, negative for I{prolate}). 

2240 

2241 @return: The I{signed}, 3rd flattening (-1 <= C{float} < 1), 

2242 M{f / (2 - f)}. 

2243 

2244 @note: The result is positive for I{oblate}, negative for I{prolate} or C{0} 

2245 for I{near-spherical} ellipsoids. 

2246 

2247 @see: U{Eccentricity conversions<https://GeographicLib.SourceForge.io/ 

2248 C++/doc/classGeographicLib_1_1Ellipsoid.html>} and U{Flattening 

2249 <https://WikiPedia.org/wiki/Flattening>}. 

2250 ''' 

2251 return Float(n=_0_0 if _ispherical_f(f) else _over(f, float(_2_0 - f))) 

2252 

2253 

2254def n2e2(n): 

2255 '''Return C{e2}, the I{1st eccentricity squared} for a given I{3rd flattening}. 

2256 

2257 @arg n: The 3rd flattening (-1 <= C{scalar} < 1). 

2258 

2259 @return: The I{signed}, (1st) eccentricity I{squared} (C{float} or NINF), 

2260 M{4 * n / (1 + n)**2}. 

2261 

2262 @note: The result is positive for I{oblate}, negative for I{prolate} or C{0} 

2263 for I{near-spherical} ellipsoids. 

2264 

2265 @see: U{Flattening<https://WikiPedia.org/wiki/Flattening>}. 

2266 ''' 

2267 t = (n + _1_0)**2 

2268 return Float(e2=_0_0 if fabs(n) < EPS0 else 

2269 (NINF if t < EPS0 else _over(_4_0 * n, t))) 

2270 

2271 

2272def n2f(n): 

2273 '''Return C{f}, the I{flattening} for a given I{3rd flattening}. 

2274 

2275 @arg n: The 3rd flattening (-1 <= C{scalar} < 1). 

2276 

2277 @return: The flattening (C{scalar} or NINF), M{2 * n / (1 + n)}. 

2278 

2279 @see: U{Eccentricity conversions<https://GeographicLib.SourceForge.io/ 

2280 C++/doc/classGeographicLib_1_1Ellipsoid.html>} and U{Flattening 

2281 <https://WikiPedia.org/wiki/Flattening>}. 

2282 ''' 

2283 t = n + _1_0 

2284 f = 0 if fabs(n) < EPS0 else (NINF if t < EPS0 else _over(_2_0 * n, t)) 

2285 return _f_0_0 if _ispherical_f(f) else Float(f=f) 

2286 

2287 

2288def n2f_(n): 

2289 '''Return C{f_}, the I{inverse flattening} for a given I{3rd flattening}. 

2290 

2291 @arg n: The 3rd flattening (-1 <= C{scalar} < 1). 

2292 

2293 @return: The inverse flattening (C{scalar} or C{0}), M{1 / f}. 

2294 

2295 @see: L{n2f} and L{f2f_}. 

2296 ''' 

2297 return f2f_(n2f(n)) 

2298 

2299 

2300class Ellipsoids(_NamedEnum): 

2301 '''(INTERNAL) L{Ellipsoid} registry, I{must} be a sub-class 

2302 to accommodate the L{_LazyNamedEnumItem} properties. 

2303 ''' 

2304 def _Lazy(self, a, b, f_, **kwds): 

2305 '''(INTERNAL) Instantiate the L{Ellipsoid}. 

2306 ''' 

2307 return Ellipsoid(a, b=b, f_=f_, **kwds) 

2308 

2309Ellipsoids = Ellipsoids(Ellipsoid) # PYCHOK singleton 

2310'''Some pre-defined L{Ellipsoid}s, all I{lazily} instantiated.''' 

2311# <https://www.GNU.org/software/gama/manual/html_node/Supported-ellipsoids.html> 

2312# <https://GSSC.ESA.int/navipedia/index.php/Reference_Frames_in_GNSS> 

2313# <https://kb.OSU.edu/dspace/handle/1811/77986> 

2314# <https://www.IBM.com/docs/en/db2/11.5?topic=systems-supported-spheroids> 

2315# <https://w3.Energistics.org/archive/Epicentre/Epicentre_v3.0/DataModel/LogicalDictionary/StandardValues/ellipsoid.html> 

2316# <https://GitHub.com/locationtech/proj4j/blob/master/src/main/java/org/locationtech/proj4j/datum/Ellipsoid.java> 

2317Ellipsoids._assert( # <https://WikiPedia.org/wiki/Earth_ellipsoid> 

2318 Airy1830 = _lazy(_Airy1830_, *_T(6377563.396, _0_0, 299.3249646)), # b=6356256.909 

2319 AiryModified = _lazy(_AiryModified_, *_T(6377340.189, _0_0, 299.3249646)), # b=6356034.448 

2320# APL4_9 = _lazy('APL4_9', *_T(6378137.0, _0_0, 298.24985392)), # Appl. Phys. Lab. 1965 

2321# ANS = _lazy('ANS', *_T(6378160.0, _0_0, 298.25)), # Australian Nat. Spheroid 

2322# AN_SA96 = _lazy('AN_SA96', *_T(6378160.0, _0_0, 298.24985392)), # Australian Nat. South America 

2323 Australia1966 = _lazy('Australia1966', *_T(6378160.0, _0_0, 298.25)), # b=6356774.7192 

2324 ATS1977 = _lazy('ATS1977', *_T(6378135.0, _0_0, 298.257)), # "Average Terrestrial System" 

2325 Bessel1841 = _lazy(_Bessel1841_, *_T(6377397.155, 6356078.962818, 299.152812797)), 

2326 BesselModified = _lazy('BesselModified', *_T(6377492.018, _0_0, 299.1528128)), 

2327# BesselNamibia = _lazy('BesselNamibia', *_T(6377483.865, _0_0, 299.1528128)), 

2328 CGCS2000 = _lazy('CGCS2000', *_T(R_MA, _0_0, 298.257222101)), # BeiDou Coord System (BDC) 

2329# Clarke1858 = _lazy('Clarke1858', *_T(6378293.639, _0_0, 294.260676369)), 

2330 Clarke1866 = _lazy(_Clarke1866_, *_T(6378206.4, 6356583.8, 294.978698214)), 

2331 Clarke1880 = _lazy('Clarke1880', *_T(6378249.145, 6356514.86954978, 293.465)), 

2332 Clarke1880IGN = _lazy(_Clarke1880IGN_, *_T(6378249.2, 6356515.0, 293.466021294)), 

2333 Clarke1880Mod = _lazy('Clarke1880Mod', *_T(6378249.145, 6356514.96639549, 293.466307656)), # aka Clarke1880Arc 

2334 CPM1799 = _lazy('CPM1799', *_T(6375738.7, 6356671.92557493, 334.39)), # Comm. des Poids et Mesures 

2335 Delambre1810 = _lazy('Delambre1810', *_T(6376428.0, 6355957.92616372, 311.5)), # Belgium 

2336 Engelis1985 = _lazy('Engelis1985', *_T(6378136.05, 6356751.32272154, 298.2566)), 

2337# Everest1830 = _lazy('Everest1830', *_T(6377276.345, _0_0, 300.801699997)), 

2338# Everest1948 = _lazy('Everest1948', *_T(6377304.063, _0_0, 300.801699997)), 

2339# Everest1956 = _lazy('Everest1956', *_T(6377301.243, _0_0, 300.801699997)), 

2340 Everest1969 = _lazy('Everest1969', *_T(6377295.664, 6356094.667915, 300.801699997)), 

2341 Everest1975 = _lazy('Everest1975', *_T(6377299.151, 6356098.14512013, 300.8017255)), 

2342 Fisher1968 = _lazy('Fisher1968', *_T(6378150.0, 6356768.33724438, 298.3)), 

2343# Fisher1968Mod = _lazy('Fisher1968Mod', *_T(6378155.0, _0_0, 298.3)), 

2344 GEM10C = _lazy('GEM10C', *_T(R_MA, 6356752.31424783, 298.2572236)), 

2345 GPES = _lazy('GPES', *_T(6378135.0, 6356750.0, _0_0)), # "Gen. Purpose Earth Spheroid" 

2346 GRS67 = _lazy('GRS67', *_T(6378160.0, _0_0, 298.247167427)), # Lucerne b=6356774.516 

2347# GRS67Truncated = _lazy('GRS67Truncated', *_T(6378160.0, _0_0, 298.25)), 

2348 GRS80 = _lazy(_GRS80_, *_T(R_MA, 6356752.314140347, 298.25722210088)), # IUGG, ITRS, ETRS89 

2349# Hayford1924 = _lazy('Hayford1924', *_T(6378388.0, 6356911.94612795, None)), # aka Intl1924 f_=297 

2350 Helmert1906 = _lazy('Helmert1906', *_T(6378200.0, 6356818.16962789, 298.3)), 

2351# Hough1960 = _lazy('Hough1960', *_T(6378270.0, _0_0, 297.0)), 

2352 IAU76 = _lazy('IAU76', *_T(6378140.0, _0_0, 298.257)), # Int'l Astronomical Union 

2353 IERS1989 = _lazy('IERS1989', *_T(6378136.0, _0_0, 298.257)), # b=6356751.302 

2354 IERS1992TOPEX = _lazy('IERS1992TOPEX', *_T(6378136.3, 6356751.61659215, 298.257223563)), # IERS/TOPEX/Poseidon/McCarthy 

2355 IERS2003 = _lazy('IERS2003', *_T(6378136.6, 6356751.85797165, 298.25642)), 

2356 Intl1924 = _lazy(_Intl1924_, *_T(6378388.0, _0_0, 297.0)), # aka Hayford b=6356911.9462795 

2357 Intl1967 = _lazy('Intl1967', *_T(6378157.5, 6356772.2, 298.24961539)), # New Int'l 

2358 Krassovski1940 = _lazy(_Krassovski1940_, *_T(6378245.0, 6356863.01877305, 298.3)), # spelling 

2359 Krassowsky1940 = _lazy(_Krassowsky1940_, *_T(6378245.0, 6356863.01877305, 298.3)), # spelling 

2360# Kaula = _lazy('Kaula', *_T(6378163.0, _0_0, 298.24)), # Kaula 1961 

2361# Lerch = _lazy('Lerch', *_T(6378139.0, _0_0, 298.257)), # Lerch 1979 

2362 Maupertuis1738 = _lazy('Maupertuis1738', *_T(6397300.0, 6363806.28272251, 191.0)), # France 

2363 Mercury1960 = _lazy('Mercury1960', *_T(6378166.0, 6356784.28360711, 298.3)), 

2364 Mercury1968Mod = _lazy('Mercury1968Mod', *_T(6378150.0, 6356768.33724438, 298.3)), 

2365# MERIT = _lazy('MERIT', *_T(6378137.0, _0_0, 298.257)), # MERIT 1983 

2366# NWL10D = _lazy('NWL10D', *_T(6378135.0, _0_0, 298.26)), # Naval Weapons Lab. 

2367 NWL1965 = _lazy('NWL1965', *_T(6378145.0, 6356759.76948868, 298.25)), # Naval Weapons Lab. 

2368# NWL9D = _lazy('NWL9D', *_T(6378145.0, 6356759.76948868, 298.25)), # NWL1965 

2369 OSU86F = _lazy('OSU86F', *_T(6378136.2, 6356751.51693008, 298.2572236)), 

2370 OSU91A = _lazy('OSU91A', *_T(6378136.3, 6356751.6165948, 298.2572236)), 

2371# Plessis1817 = _lazy('Plessis1817', *_T(6397523.0, 6355863.0, 153.56512242)), # XXX incorrect? 

2372 Plessis1817 = _lazy('Plessis1817', *_T(6376523.0, 6355862.93325557, 308.64)), # XXX IGN France 1972 

2373# Prolate = _lazy('Prolate', *_T(6356752.3, R_MA, _0_0)), 

2374 PZ90 = _lazy('PZ90', *_T(6378136.0, _0_0, 298.257839303)), # GLOSNASS PZ-90 and PZ-90.11 

2375# SEAsia = _lazy('SEAsia', *_T(6378155.0, _0_0, 298.3)), # SouthEast Asia 

2376 SGS85 = _lazy('SGS85', *_T(6378136.0, 6356751.30156878, 298.257)), # Soviet Geodetic System 

2377 SoAmerican1969 = _lazy('SoAmerican1969', *_T(6378160.0, 6356774.71919531, 298.25)), # South American 

2378 Sphere = _lazy(_Sphere_, *_T(R_M, R_M, _0_0)), # pseudo 

2379 SphereAuthalic = _lazy('SphereAuthalic', *_T(R_FM, R_FM, _0_0)), # pseudo 

2380 SpherePopular = _lazy('SpherePopular', *_T(R_MA, R_MA, _0_0)), # EPSG:3857 Spheroid 

2381 Struve1860 = _lazy('Struve1860', *_T(6378298.3, 6356657.14266956, 294.73)), 

2382# Walbeck = _lazy('Walbeck', *_T(6376896.0, _0_0, 302.78)), 

2383# WarOffice = _lazy('WarOffice', *_T(6378300.0, _0_0, 296.0)), 

2384 WGS60 = _lazy('WGS60', *_T(6378165.0, 6356783.28695944, 298.3)), 

2385 WGS66 = _lazy('WGS66', *_T(6378145.0, 6356759.76948868, 298.25)), 

2386 WGS72 = _lazy(_WGS72_, *_T(6378135.0, _0_0, 298.26)), # b=6356750.52 

2387 WGS84 = _lazy(_WGS84_, *_T(R_MA, _0_0, _f__WGS84)), # GPS b=6356752.3142451793 

2388# U{NOAA/NOS/NGS/inverse<https://GitHub.com/noaa-ngs/inverse/blob/main/invers3d.f>} 

2389 WGS84_NGS = _lazy('WGS84_NGS', *_T(R_MA, _0_0, 298.257222100882711243162836600094)) 

2390) 

2391 

2392_EWGS84 = Ellipsoids.WGS84 # (INTERNAL) shared 

2393 

2394if __name__ == _DMAIN_: 

2395 

2396 from pygeodesy.interns import _COMMA_, _NL_, _NLATvar_ 

2397 from pygeodesy import nameof, printf 

2398 

2399 for E in (_EWGS84, Ellipsoids.GRS80, # NAD83, 

2400 Ellipsoids.Sphere, Ellipsoids.SpherePopular, 

2401 Ellipsoid(_EWGS84.b, _EWGS84.a, name='_Prolate')): 

2402 e = f2n(E.f) - E.n 

2403 printf('# %s: %s', _DOT_('Ellipsoids', E.name), E.toStr(prec=10, terse=0), nl=1) 

2404 printf('# e=%s, f_=%s, f=%s, n=%s (%s)', fstr(E.e, prec=13, fmt=Fmt.e), 

2405 fstr(E.f_, prec=13, fmt=Fmt.e), 

2406 fstr(E.f, prec=13, fmt=Fmt.e), 

2407 fstr(E.n, prec=13, fmt=Fmt.e), 

2408 fstr(e, prec=9, fmt=Fmt.e)) 

2409 printf('# %s %s', Ellipsoid.AlphaKs.name, fstr(E.AlphaKs, prec=20)) 

2410 printf('# %s %s', Ellipsoid.BetaKs.name, fstr(E.BetaKs, prec=20)) 

2411 printf('# %s %s', nameof(Ellipsoid.KsOrder), E.KsOrder) # property 

2412 

2413 # __doc__ of this file, force all into registry 

2414 t = [NN] + Ellipsoids.toRepr(all=True, asorted=True).split(_NL_) 

2415 printf(_NLATvar_.join(i.strip(_COMMA_) for i in t)) 

2416 

2417# % python3.13 -m pygeodesy.ellipsoids 

2418 

2419# Ellipsoids.WGS84: name='WGS84', a=6378137, f=0.0033528107, f_=298.257223563, b=6356752.3142451793, f2=0.0033640898, n=0.0016792204, e=0.0818191908, e2=0.00669438, e21=0.99330562, e22=0.0067394967, e32=0.0033584313, A=6367449.1458234144, L=10001965.7293127235, R1=6371008.7714150595, R2=6371007.1809184738, R3=6371000.7900091587, Rbiaxial=6367453.6345163295, Rtriaxial=6372797.5559594007 

2420# e=8.1819190842622e-02, f_=2.98257223563e+02, f=3.3528106647475e-03, n=1.6792203863837e-03 (0.0e+00) 

2421# AlphaKs 0.00083773182062446994, 0.00000076085277735725, 0.00000000119764550324, 0.00000000000242917068, 0.00000000000000571182, 0.0000000000000000148, 0.00000000000000000004, 0.0 

2422# BetaKs 0.00083773216405794875, 0.0000000590587015222, 0.00000000016734826653, 0.00000000000021647981, 0.00000000000000037879, 0.00000000000000000072, 0.0, 0.0 

2423# KsOrder 8 

2424 

2425# Ellipsoids.GRS80: name='GRS80', a=6378137, f=0.0033528107, f_=298.2572221009, b=6356752.3141403468, f2=0.0033640898, n=0.0016792204, e=0.081819191, e2=0.00669438, e21=0.99330562, e22=0.0067394968, e32=0.0033584313, A=6367449.1457710434, L=10001965.7292304561, R1=6371008.7713801153, R2=6371007.1808835147, R3=6371000.7899741363, Rbiaxial=6367453.6344640013, Rtriaxial=6372797.5559332585 

2426# e=8.1819191042833e-02, f_=2.9825722210088e+02, f=3.3528106811837e-03, n=1.6792203946295e-03 (0.0e+00) 

2427# AlphaKs 0.00083773182472890429, 0.00000076085278481561, 0.00000000119764552086, 0.00000000000242917073, 0.00000000000000571182, 0.0000000000000000148, 0.00000000000000000004, 0.0 

2428# BetaKs 0.0008377321681623882, 0.00000005905870210374, 0.000000000167348269, 0.00000000000021647982, 0.00000000000000037879, 0.00000000000000000072, 0.0, 0.0 

2429# KsOrder 8 

2430 

2431# Ellipsoids.Sphere: name='Sphere', a=6371008.7714149999, f=0, f_=0, b=6371008.7714149999, f2=0, n=0, e=0, e2=0, e21=1, e22=0, e32=0, A=6371008.7714149999, L=10007557.1761167478, R1=6371008.7714149999, R2=6371008.7714149999, R3=6371008.7714149999, Rbiaxial=6371008.7714149999, Rtriaxial=6371008.7714149999 

2432# e=0.0e+00, f_=0.0e+00, f=0.0e+00, n=0.0e+00 (0.0e+00) 

2433# AlphaKs 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 

2434# BetaKs 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 

2435# KsOrder 8 

2436 

2437# Ellipsoids.SpherePopular: name='SpherePopular', a=6378137, f=0, f_=0, b=6378137, f2=0, n=0, e=0, e2=0, e21=1, e22=0, e32=0, A=6378137, L=10018754.171394622, R1=6378137, R2=6378137, R3=6378137, Rbiaxial=6378137, Rtriaxial=6378137 

2438# e=0.0e+00, f_=0.0e+00, f=0.0e+00, n=0.0e+00 (0.0e+00) 

2439# AlphaKs 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 

2440# BetaKs 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 

2441# KsOrder 8 

2442 

2443# Ellipsoids._Prolate: name='_Prolate', a=6356752.3142451793, f=-0.0033640898, f_=-297.257223563, b=6378137, f2=-0.0033528107, n=-0.0016792204, e=0.0820944379, e2=-0.0067394967, e21=1.0067394967, e22=-0.00669438, e32=-0.0033584313, A=6367449.1458234144, L=10035500.5204500332, R1=6363880.5428301189, R2=6363878.9413582645, R3=6363872.5644020075, Rbiaxial=6367453.6345163295, Rtriaxial=6362105.2243882557 

2444# e=8.2094437949696e-02, f_=-2.97257223563e+02, f=-3.3640898209765e-03, n=-1.6792203863837e-03 (0.0e+00) 

2445# AlphaKs -0.00084149152514366627, 0.00000076653480614871, -0.00000000120934503389, 0.0000000000024576225, -0.00000000000000578863, 0.00000000000000001502, -0.00000000000000000004, 0.0 

2446# BetaKs -0.00084149187224351817, 0.00000005842735196773, -0.0000000001680487236, 0.00000000000021706261, -0.00000000000000038002, 0.00000000000000000073, -0.0, 0.0 

2447# KsOrder 8 

2448 

2449# **) MIT License 

2450# 

2451# Copyright (C) 2016-2025 -- mrJean1 at Gmail -- All Rights Reserved. 

2452# 

2453# Permission is hereby granted, free of charge, to any person obtaining a 

2454# copy of this software and associated documentation files (the "Software"), 

2455# to deal in the Software without restriction, including without limitation 

2456# the rights to use, copy, modify, merge, publish, distribute, sublicense, 

2457# and/or sell copies of the Software, and to permit persons to whom the 

2458# Software is furnished to do so, subject to the following conditions: 

2459# 

2460# The above copyright notice and this permission notice shall be included 

2461# in all copies or substantial portions of the Software. 

2462# 

2463# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 

2464# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 

2465# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 

2466# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 

2467# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 

2468# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 

2469# OTHER DEALINGS IN THE SOFTWARE.