Coverage for pygeodesy/rhumb/ekx.py: 98%

226 statements  

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

1 

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

3 

4u'''A pure Python version of I{Karney}'s I{elliptic functions}, I{Krüger series expansion}, C++ 

5classes U{Rhumb<https://GeographicLib.SourceForge.io/C++/doc/classGeographicLib_1_1Rhumb.html>} and 

6and U{RhumbLine<https://GeographicLib.SourceForge.io/C++/doc/classGeographicLib_1_1RhumbLine.html>} 

7from I{GeographicLib version 2.0}, kept for backward compatibility. 

8 

9Class L{RhumbLine} has been enhanced with methods C{Intersecant2}, C{Intersection} and C{PlumbTo} to 

10iteratively find the intersection of a rhumb line and a circle or an other rhumb line, respectively 

11a perpendicular geodesic or other rhumb line. 

12 

13For more details, see the C++ U{GeographicLib<https://GeographicLib.SourceForge.io/C++/doc/index.html>} 

14documentation, especially the U{Class List<https://GeographicLib.SourceForge.io/C++/doc/annotated.html>}, 

15the background information on U{Rhumb lines<https://GeographicLib.SourceForge.io/C++/doc/rhumb.html>}, 

16the utily U{RhumbSolve<https://GeographicLib.SourceForge.io/C++/doc/RhumbSolve.1.html>} and U{Online 

17rhumb line calculations<https://GeographicLib.SourceForge.io/cgi-bin/RhumbSolve>}. 

18 

19Copyright (C) U{Charles Karney<mailto:Karney@Alum.MIT.edu>} (2014-2024) and licensed under the MIT/X11 

20License. For more information, see the U{GeographicLib<https://GeographicLib.SourceForge.io>} documentation. 

21''' 

22# make sure int/int division yields float quotient 

23from __future__ import division as _; del _ # noqa: E702 ; 

24 

25from pygeodesy.basics import copysign0, neg 

26from pygeodesy.constants import PI_2, _0_0s, _0_0, _0_5, _1_0, \ 

27 _2_0, _4_0, _720_0, _over, _1_over 

28# from pygeodesy.datums import _WGS84 # from .rhumb.bases 

29# from pygeodesy.deprecated import RhumbOrder2Tuple # _MODS 

30from pygeodesy.errors import RhumbError, _xkwds_pop2, _Xorder 

31from pygeodesy.fmath import hypot, hypot1 

32# from pygeodesy.fsums import fsum1f_ # _MODS 

33# from pygeodesy.karney import Caps # from .rhumb.bases 

34from pygeodesy.ktm import _Xs, _AlpCoeffs, _BetCoeffs # PYCHOK used! 

35from pygeodesy.lazily import _ALL_DOCS, _ALL_LAZY, _ALL_MODS as _MODS 

36from pygeodesy.props import deprecated_method, Property, Property_RO, \ 

37 property_RO 

38from pygeodesy.rhumb.bases import RhumbBase, RhumbLineBase, \ 

39 Caps, _update_all_rls, _WGS84 

40from pygeodesy.utily import atan1, sincos2_ 

41 

42from math import asinh, atan, cos, cosh, radians, sin, sinh, sqrt, tan # as _tan 

43 

44__all__ = _ALL_LAZY.rhumb_ekx 

45__version__ = '25.05.12' 

46 

47 

48class Rhumb(RhumbBase): 

49 '''Class to solve the I{direct} and I{inverse rhumb} problems, based on 

50 I{elliptic functions} or I{Krüger series expansion} 

51 

52 @see: The U{Detailed Description<https://GeographicLib.SourceForge.io/C++/doc/ 

53 classGeographicLib_1_1Rhumb.html>} of I{Karney}'s C++ C{Rhumb Class}. 

54 ''' 

55 _mRA = 6 # see .RAorder 

56 

57 def __init__(self, a_earth=_WGS84, f=None, exact=True, **RA_TMorder_name): 

58 '''New C{Rhumb}. 

59 

60 @kwarg a_earth: This rhumb's earth model (L{Datum}, L{Ellipsoid}, 

61 L{Ellipsoid2}, L{a_f2Tuple}, 2-tuple C{(a, f)}) or 

62 the (equatorial) radius (C{meter}, conventionally). 

63 @kwarg f: The ellipsoid's flattening (C{scalar}), required if B{C{a_earth}} 

64 is C{scalar}, ignored otherwise. 

65 @kwarg exact: If C{True}, use an addition theorem for elliptic integrals 

66 to compute I{Divided differences}, otherwise use the I{Krüger} 

67 series expansion (C{bool} or C{None}), see also properties 

68 C{exact} and C{TMorder}. 

69 @kwarg RA_TMorder_name: Optional C{B{name}=NN} (C{str}) and optional keyword 

70 arguments B{C{RAorder}=6} and B{C{TMorder}=6} to set the respective 

71 C{order}, see properties C{RAorder} and C{TMorder}. 

72 

73 @raise RhumbError: Invalid B{C{a_earth}}, B{C{f}}, B{C{RAorder}} or B{C{TMorder}}. 

74 ''' 

75 if RA_TMorder_name: 

76 M = self._mRA 

77 m, kwds = _xkwds_pop2(RA_TMorder_name, RAorder=M) 

78 if m != M: 

79 self.RAorder = m 

80 else: 

81 kwds = {} 

82 RhumbBase.__init__(self, a_earth, f, exact, kwds) 

83 

84 @Property_RO 

85 def _A2(self): # Conformal2RectifyingCoeffs 

86 m = self.TMorder 

87 return _Xs(_AlpCoeffs, m, self.ellipsoid), m 

88 

89 @Property_RO 

90 def _B2(self): # Rectifying2ConformalCoeffs 

91 m = self.TMorder 

92 return _Xs(_BetCoeffs, m, self.ellipsoid), m 

93 

94 def _DConformal2Rectifying(self, x, y): # radians 

95 return _1_0 + (_sincosSeries(True, x, y, *self._A2) if self.f else _0_0) 

96 

97 @deprecated_method 

98 def Direct7(self, lat1, lon1, azi12, s12, outmask=Caps.LATITUDE_LONGITUDE_AREA): # PYCHOK no cover 

99 '''DEPRECATED, use method L{Rhumb.Direct8}. 

100 

101 @return: A I{DEPRECATED} L{Rhumb7Tuple}. 

102 ''' 

103 return self.Direct8(lat1, lon1, azi12, s12, outmask=outmask)._to7Tuple() 

104 

105 def _DIsometrict(self, phix, phiy, tphix, tphiy, _Dtan_phix_phiy): 

106 E = self.ellipsoid 

107 return _Dtan_phix_phiy * _Dasinh(tphix, tphiy) - \ 

108 _Dsin(phix, phiy) * _DeatanhE(sin(phix), sin(phiy), E) 

109 

110 def _DIsometric2Rectifyingd(self, psix, psiy): # degrees 

111 if self.exact: 

112 E = self.ellipsoid 

113 phix, phiy, tphix, tphiy = _Eaux4(E.auxIsometric, psix, psiy) 

114 t = _Dtant(phix - phiy, tphix, tphiy) 

115 r = _over(self._DRectifyingt( tphix, tphiy, t), 

116 self._DIsometrict(phix, phiy, tphix, tphiy, t)) 

117 else: 

118 x, y = radians(psix), radians(psiy) 

119 r = self._DConformal2Rectifying(_gd(x), _gd(y)) * _Dgd(x, y) 

120 return r 

121 

122 def _DRectifyingt(self, tphix, tphiy, _Dtan_phix_phiy): 

123 E = self.ellipsoid 

124 tbetx = E.f1 * tphix 

125 tbety = E.f1 * tphiy 

126 return (E.f1 * _Dtan_phix_phiy * E.b * PI_2 

127 * _DfEt( tbetx, tbety, self._eF) 

128 * _Datan(tbetx, tbety)) / E.L 

129 

130 def _DRectifying2Conformal(self, x, y): # radians 

131 return _1_0 - (_sincosSeries(True, x, y, *self._B2) if self.f else _0_0) 

132 

133 def _DRectifying2Isometricd(self, mux, muy): # degrees 

134 E = self.ellipsoid 

135 phix, phiy, tphix, tphiy = _Eaux4(E.auxRectifying, mux, muy) 

136 if self.exact: 

137 t = _Dtant(phix - phiy, tphix, tphiy) 

138 r = _over(self._DIsometrict(phix, phiy, tphix, tphiy, t), 

139 self._DRectifyingt( tphix, tphiy, t)) 

140 else: 

141 r = self._DRectifying2Conformal(radians(mux), radians(muy)) * \ 

142 _Dgdinv(E.es_taupf(tphix), E.es_taupf(tphiy)) 

143 return r 

144 

145 @Property_RO 

146 def _eF(self): 

147 '''(INTERNAL) Get the ellipsoid's elliptic function. 

148 ''' 

149 # .k2 = 0.006739496742276434 

150 return self.ellipsoid._elliptic_e12 # _MODS.elliptic.Elliptic(-self.ellipsoid._e12) 

151 

152 def _Inverse4(self, lon12, r, outmask): 

153 '''(INTERNAL) See method C{RhumbBase.Inverse}. 

154 ''' 

155 E, Cs = self.ellipsoid, Caps 

156 psi1 = E.auxIsometric(r.lat1) 

157 psi2 = E.auxIsometric(r.lat2) 

158 psi12 = psi2 - psi1 # degrees 

159 if (outmask & Cs.DISTANCE): 

160 a = s = hypot(lon12, psi12) 

161 if a: 

162 a *= self._DIsometric2Rectifyingd(psi2, psi1) 

163 s = self._mpd * a # == E._Lpd 

164 a = copysign0(a, s) 

165 r.set_(a12=a, s12=s) 

166 

167 if ((outmask | self._debug) & Cs._DEBUG_INVERSE): # PYCHOK no cover 

168 r.set_(a=E.a, f=E.f, f1=E.f1, L=E.L, 

169 b=E.b, e=E.e, e2=E.e2, k2=self._eF.k2, 

170 lon12=lon12, psi1=psi1, exact=self.exact, 

171 psi12=psi12, psi2=psi2) 

172 return lon12, psi12, psi1, psi2 

173 

174 @deprecated_method 

175 def Inverse7(self, lat1, lon1, azi12, s12, outmask=Caps.AZIMUTH_DISTANCE_AREA): # PYCHOK no cover 

176 '''DEPRECATED, use method L{Rhumb.Inverse8}. 

177 

178 @return: A I{DEPRECATED} L{Rhumb7Tuple}. 

179 ''' 

180 return self.Inverse8(lat1, lon1, azi12, s12, outmask=outmask)._to7Tuple() 

181 

182 @Property_RO 

183 def _mpd(self): # meter per degree 

184 return self.ellipsoid._Lpd 

185 

186 @Property_RO 

187 def _mpr(self): # meter per radian 

188 return self.ellipsoid._Lpr # degrees(._Lpd) 

189 

190 @deprecated_method 

191 def orders(self, RAorder=6, TMorder=6): # PYCHOK no cover 

192 '''DEPRECATED, use properties C{RAorder} and/or C{TMorder}. 

193 

194 Get and set the I{RAorder} and/or I{TMorder}. 

195 

196 @kwarg RAorder: I{Rhumb Area} order (C{int}, 4, 5, 6, 7 

197 or 8). 

198 @kwarg TMorder: I{Transverse Mercator} order (C{int}, 4, 

199 5, 6, 7 or 8). 

200 

201 @return: DEPRECATED L{RhumbOrder2Tuple}C{(RAorder, TMorder)} 

202 with the previous C{RAorder} and C{TMorder} setting. 

203 ''' 

204 t = _MODS.deprecated.classes.RhumbOrder2Tuple(self.RAorder, self.TMorder) 

205 if RAorder != t.RAorder: # PYCHOK attr 

206 self.RAorder = RAorder 

207 if TMorder != t.TMorder: # PYCHOK attr 

208 self.TMorder = TMorder 

209 return t 

210 

211 @Property_RO 

212 def _RA2(self): 

213 # for WGS84: (0, -0.0005583633519275459, -3.743803759172812e-07, -4.633682270824446e-10, 

214 # RAorder 6: -7.709197397676237e-13, -1.5323287106694307e-15, -3.462875359099873e-18) 

215 m = self.RAorder 

216 return _Xs(_RACoeffs, m, self.ellipsoid, RA=True), m 

217 

218 @Property 

219 def RAorder(self): 

220 '''Get the I{Rhumb Area} order (C{int}, 4, 5, 6, 7 or 8). 

221 ''' 

222 return self._mRA 

223 

224 @RAorder.setter # PYCHOK setter! 

225 def RAorder(self, order): 

226 '''Set the I{Rhumb Area} order (C{int}, 4, 5, 6, 7 or 8). 

227 ''' 

228 m = _Xorder(_RACoeffs, RhumbError, RAorder=order) 

229 if self._mRA != m: 

230 _update_all_rls(self) 

231 self._mRA = m 

232 

233# _RhumbLine = RhumbLine # see further below 

234 

235 def _S12d(self, psi1, psi2, lon12): # degrees 

236 '''(INTERNAL) Compute the area C{S12}. 

237 ''' 

238 S = (self.ellipsoid.areax if self.exact else 

239 self.ellipsoid.area) * lon12 / _720_0 

240 if S: 

241 x, y = radians(psi1), radians(psi2) # _meanSinXi(x, y) 

242 s = _Dlog(cosh(x), cosh(y)) * _Dcosh(x, y) 

243 if self.f: 

244 s += _sincosSeries(False, _gd(x), _gd(y), *self._RA2) * _Dgd(x, y) 

245 S *= s 

246 return S 

247 

248 

249class RhumbLine(RhumbLineBase): 

250 '''Compute one or several points on a single rhumb line. 

251 

252 Class C{RhumbLine} facilitates the determination of points on 

253 a single rhumb line. The starting point (C{lat1}, C{lon1}) 

254 and the azimuth C{azi12} are specified once. 

255 ''' 

256 _Rhumb = Rhumb # rhumb.ekx.Rhumb 

257 

258 def __init__(self, rhumb, lat1=0, lon1=0, azi12=None, **caps_name): # PYCHOK signature 

259 '''New C{RhumbLine}. 

260 

261 @arg rhumb: The rhumb reference (L{Rhumb}). 

262 @kwarg lat1: Latitude of the start point (C{degrees90}). 

263 @kwarg lon1: Longitude of the start point (C{degrees180}). 

264 @kwarg azi12: Azimuth of this rhumb line (compass C{degrees}). 

265 @kwarg caps_name: Optional keyword arguments C{B{name}=NN} and C{B{caps}=0}, 

266 a bit-or'ed combination of L{Caps<pygeodesy.karney.Caps>} values 

267 specifying the required capabilities. Include C{Caps.LINE_OFF} 

268 if updates to the B{C{rhumb}} should I{not be reflected} in this 

269 rhumb line. 

270 ''' 

271 RhumbLineBase.__init__(self, rhumb, lat1, lon1, azi12, **caps_name) 

272 

273 @Property_RO 

274 def _dpm12(self): # PYCHOK no cover 

275 '''(INTERNAL) Get this rhumb line's parallel I{circle radius} (C{degree per meter}). 

276 ''' 

277 r = self._salp 

278 if r: 

279 r = _over(r, self.ellipsoid.circle4(self.lat1).radius) 

280 return r 

281 

282 @Property_RO 

283 def _mu1(self): 

284 '''(INTERNAL) Get the I{rectifying auxiliary} latitude (C{degrees}). 

285 ''' 

286 return self.ellipsoid.auxRectifying(self.lat1) 

287 

288 def _mu2lat(self, mu): 

289 '''(INTERNAL) Get the inverse I{rectifying auxiliary} latitude (C{degrees}). 

290 ''' 

291 return self.ellipsoid.auxRectifying(mu, inverse=True) 

292 

293 def _Position4(self, unused, mu2, s12, mu12): 

294 '''(INTERNAL) See method C{RhumbLineBase._Position}. 

295 ''' 

296 psi1 = psi2 = self._psi1 

297 if mu12: # self._calp != 0 

298 lat2 = self._mu2lat(mu2) 

299 psi12 = self.rhumb._DRectifying2Isometricd(mu2, self._mu1) * mu12 

300 lon2 = self._talp * psi12 

301 psi2 += psi12 

302 else: # meridional 

303 lat2 = self.lat1 

304 lon2 = self._dpm12 * s12 

305 return lat2, lon2, psi1, psi2 

306 

307 @Property_RO 

308 def _psi1(self): 

309 '''(INTERNAL) Get the I{isometric auxiliary} latitude C{psi} (C{degrees}). 

310 ''' 

311 return self.ellipsoid.auxIsometric(self.lat1) 

312 

313 @property_RO 

314 def RAorder(self): 

315 '''Get this rhumb line's I{Rhumb Area} order (C{int}, 4, 5, 6, 7 or 8). 

316 ''' 

317 return self.rhumb.RAorder 

318 

319Rhumb._RhumbLine = RhumbLine # PYCHOK see RhumbBase._RhumbLine 

320 

321 

322# Use I{Divided Differences} to determine (mu2 - mu1) / (psi2 - psi1) accurately. 

323# Definition: _Df(x,y,d) = (f(x) - f(y)) / (x - y), @see W. M. Kahan & R. J. 

324# Fateman, "Symbolic computation of Divided Differences", SIGSAM Bull. 33(3), 

325# 7-28 (1999). U{ACM<https://DL.ACM.org/doi/pdf/10.1145/334714.334716> and @see 

326# U{UCB<https://www.CS.Berkeley.edu/~fateman/papers/divdiff.pdf>}, Dec 8, 1999. 

327 

328def _Dasinh(x, y): 

329 hx = hypot1(x) 

330 d = x - y 

331 if d: 

332 hx *= y 

333 hy = x * hypot1(y) 

334 t = (d * (x + y) / (hy + hx)) if (x * y) > 0 else (hy - hx) 

335 r = asinh(t) / d 

336 else: 

337 r = _1_0 / hx 

338 return r 

339 

340 

341def _Datan(x, y): 

342 xy = x * y 

343 r = xy + _1_0 

344 d = x - y 

345 if d: # 2 * xy > -1 == 2 * xy + 1 > 0 == xy + r > 0 == xy > -r 

346 r = (atan1(d, r) if xy > -r else (atan1(x) - atan1(y))) / d 

347 else: 

348 r = _1_over(r) 

349 return r 

350 

351 

352def _Dcosh(x, y): 

353 return _Dsincos(x, y, sinh, sinh) 

354 

355 

356def _DeatanhE(x, y, E): # see .albers._Datanhee 

357 # Deatanhe(x, y) = eatanhe((x - y) / (1 - e^2 * x * y)) / (x - y) 

358 e = _1_0 - E.e2 * x * y 

359 if e: # assert not isnear0(e) 

360 d = x - y 

361 e = (E._es_atanh(d / e) / d) if d else (E.e2 / e) 

362 return e 

363 

364 

365def _DfEt(tx, ty, eF): # tangents 

366 # eF = Elliptic(-E.e12) # -E.e2 / (1 - E.e2) 

367 r, x, y, = _1_0, atan(tx), atan(ty) 

368 d = x - y 

369 if (x * y) > 0: 

370 # See U{DLMF<https://DLMF.NIST.gov/19.11>}: 19.11.2 and 19.11.4 

371 # letting theta -> x, phi -> -y, psi -> z 

372 # (E(x) - E(y)) / d = E(z)/d - k2 * sin(x) * sin(y) * sin(z)/d 

373 # tan(z/2) = (sin(x)*Delta(y) - sin(y)*Delta(x)) / (cos(x) + cos(y)) 

374 # = d * Dsin(x,y) * (sin(x) + sin(y))/(cos(x) + cos(y)) / 

375 # (sin(x)*Delta(y) + sin(y)*Delta(x)) 

376 # = t = d * Dt 

377 # sin(z) = 2*t/(1+t^2); cos(z) = (1-t^2)/(1+t^2) 

378 # Alt (this only works for |z| <= pi/2 -- however, this conditions 

379 # holds if x*y > 0): 

380 # sin(z) = d * Dsin(x,y) * (sin(x) + sin(y)) / 

381 # (sin(x)*cos(y)*Delta(y) + sin(y)*cos(x)*Delta(x)) 

382 # cos(z) = sqrt((1-sin(z))*(1+sin(z))) 

383 sx, cx, sy, cy = sincos2_(x, y) 

384 D = (cx + cy) * (eF.fDelta(sy, cy) * sx + 

385 eF.fDelta(sx, cx) * sy) 

386 D = (sx + sy) * _Dsin(x, y) / D 

387 t = D * d 

388 t2 = _1_0 + t**2 

389 D *= _2_0 / t2 

390 s = D * d 

391 if s: 

392 c = (t + _1_0) * (_1_0 - t) / t2 

393 r = eF.fE(s, c, eF.fDelta(s, c)) / s 

394 r = D * (r - eF.k2 * sx * sy) 

395 elif d: 

396 r = (eF.fE(x) - eF.fE(y)) / d 

397 return r 

398 

399 

400def _Dgd(x, y): 

401 return _Datan(sinh(x), sinh(y)) * _Dsinh(x, y) 

402 

403 

404def _Dgdinv(x, y): # x, y are tangents 

405 return _Dasinh(x, y) / _Datan(x, y) 

406 

407 

408def _Dlog(x, y): 

409 d = (x - y) * _0_5 

410 # Changed atanh(t / (x + y)) to asinh(t / (2 * sqrt(x*y))) to 

411 # avoid taking atanh(1) when x is large and y is 1. This also 

412 # fixes bogus results being returned for the area when an endpoint 

413 # is at a pole. N.B. this routine is invoked with positive x 

414 # and y, so the sqrt is always taken of a positive quantity. 

415 return (asinh(d / sqrt(x * y)) / d) if d else _1_over(x) 

416 

417 

418def _Dsin(x, y): 

419 return _Dsincos(x, y, sin, cos) 

420 

421 

422def _Dsincos(x, y, sin_, cos_): 

423 r = cos_((x + y) * _0_5) 

424 d = (x - y) * _0_5 

425 if d: 

426 r *= sin_(d) / d 

427 return r 

428 

429 

430def _Dsinh(x, y): 

431 return _Dsincos(x, y, sinh, cosh) 

432 

433 

434def _Dtan(x, y): # PYCHOK no cover 

435 return _Dtant(x - y, tan(x), tan(y)) 

436 

437 

438def _Dtant(dxy, tx, ty): 

439 txy = tx * ty 

440 r = txy + _1_0 

441 if dxy: # 2 * txy > -1 == 2 * txy + 1 > 0 == txy + r > 0 == txy > -r 

442 r = ((tan(dxy) * r) if txy > -r else (tx - ty)) / dxy 

443 return r 

444 

445 

446def _Eaux4(E_aux, mu_psi_x, mu_psi_y): # degrees 

447 # get inverse auxiliary lats in radians and tangents 

448 phix = radians(E_aux(mu_psi_x, inverse=True)) 

449 phiy = radians(E_aux(mu_psi_y, inverse=True)) 

450 return phix, phiy, tan(phix), tan(phiy) 

451 

452 

453def _gd(x): 

454 return atan(sinh(x)) 

455 

456 

457def _sincosSeries(sinp, x, y, C, n): 

458 # N.B. C[] has n+1 elements of which 

459 # C[0] is ignored and n >= 0 

460 # Use Clenshaw summation to evaluate 

461 # m = (g(x) + g(y)) / 2 -- mean value 

462 # s = (g(x) - g(y)) / (x - y) -- average slope 

463 # where 

464 # g(x) = sum(C[j] * SC(2 * j * x), j = 1..n) 

465 # SC = sinp ? sin : cos 

466 # CS = sinp ? cos : sin 

467 # ... 

468 d, _neg = (x - y), neg 

469 sp, cp, sd, cd = sincos2_(x + y, d) 

470 sd = (sd / d) if d else _1_0 

471 s = _neg(sp * sd) # negative 

472 # 2x2 matrices in row-major order 

473 a1 = s * d**2 

474 a2 = s * _4_0 

475 a0 = a3 = _2_0 * cp * cd # m 

476 b2 = b1 = _0_0s(4) 

477 if n > 0: 

478 b1 = C[n], _0_0, _0_0, C[n] 

479 

480 _fsum = _MODS.fsums.fsum1f_ 

481 for j in range(n - 1, 0, -1): # C[0] unused 

482 b1, b2, Cj = b2, b1, C[j] 

483 # b1 = a * b2 - b1 + C[j] * I 

484 m0, m1, m2, m3 = b2 

485 n0, n1, n2, n3 = map(_neg, b1) 

486 b1 = (_fsum(a0 * m0, a1 * m2, n0, Cj), 

487 _fsum(a0 * m1, a1 * m3, n1), 

488 _fsum(a2 * m0, a3 * m2, n2), 

489 _fsum(a2 * m1, a3 * m3, n3, Cj)) 

490 # Here are the full expressions for m and s 

491 # f01, f02, f11, f12 = (0, 0, cd * sp, 2 * sd * cp) if sinp else \ 

492 # (1, 0, cd * cp, -2 * sd * sp) 

493 # m = -b2[1] * f02 + (C[0] - b2[0]) * f01 + b1[0] * f11 + b1[1] * f12 

494 # s = -b2[2] * f01 + (C[0] - b2[3]) * f02 + b1[2] * f11 + b1[3] * f12 

495 cd *= b1[2] 

496 sd *= b1[3] * _2_0 

497 s = _fsum(cd * sp, sd * cp) if sinp else \ 

498 _fsum(cd * cp, _neg(sd * sp), _neg(b2[2])) 

499 return s 

500 

501 

502_RACoeffs = { # Generated by Maxima on 2015-05-15 08:24:04-04:00 

503 4: ( # GEOGRAPHICLIB_RHUMBAREA_ORDER == 4 

504 691, 7860, -20160, 18900, 0, 56700, # R[0]/n^0, polynomial(n), order 4 

505 1772, -5340, 6930, -4725, 14175, # R[1]/n^1, polynomial(n), order 3 

506 -1747, 1590, -630, 4725, # PYCHOK R[2]/n^2, polynomial(n), order 2 

507 104, -31, 315, # R[3]/n^3, polynomial(n), order 1 

508 -41, 420), # PYCHOK R[4]/n^4, polynomial(n), order 0, count = 20 

509 5: ( # GEOGRAPHICLIB_RHUMBAREA_ORDER == 5 

510 -79036, 22803, 259380, -665280, 623700, 0, 1871100, # PYCHOK R[0]/n^0, polynomial(n), order 5 

511 41662, 58476, -176220, 228690, -155925, 467775, # PYCHOK R[1]/n^1, polynomial(n), order 4 

512 18118, -57651, 52470, -20790, 155925, # PYCHOK R[2]/n^2, polynomial(n), order 3 

513 -23011, 17160, -5115, 51975, # PYCHOK R[3]/n^3, polynomial(n), order 2 

514 5480, -1353, 13860, # PYCHOK R[4]/n^4, polynomial(n), order 1 

515 -668, 5775), # PYCHOK R[5]/n^5, polynomial(n), order 0, count = 27 

516 6: ( # GEOGRAPHICLIB_RHUMBAREA_ORDER == 6 

517 128346268, -107884140, 31126095, 354053700, -908107200, 851350500, 0, 2554051500, # R[0]/n^0, polynomial(n), order 6 

518 -114456994, 56868630, 79819740, -240540300, 312161850, -212837625, 638512875, # PYCHOK R[1]/n^1, polynomial(n), order 5 

519 51304574, 24731070, -78693615, 71621550, -28378350, 212837625, # R[2]/n^2, polynomial(n), order 4 

520 1554472, -6282003, 4684680, -1396395, 14189175, # R[3]/n^3, polynomial(n), order 3 

521 -4913956, 3205800, -791505, 8108100, # PYCHOK R[4]/n^4, polynomial(n), order 2 

522 1092376, -234468, 2027025, # R[5]/n^5, polynomial(n), order 1 

523 -313076, 2027025), # PYCHOK R[6]/n^6, polynomial(n), order 0, count = 35 

524 7: ( # GEOGRAPHICLIB_RHUMBAREA_ORDER == 7 

525 -317195588, 385038804, -323652420, 93378285, 1062161100, -2724321600, 2554051500, 0, 7662154500, # PYCHOK R[0]/n^0, polynomial(n), order 7 

526 258618446, -343370982, 170605890, 239459220, -721620900, 936485550, -638512875, 1915538625, # PYCHOK R[1]/n^1, polynomial(n), order 6 

527 -248174686, 153913722, 74193210, -236080845, 214864650, -85135050, 638512875, # PYCHOK R[2]/n^2, polynomial(n), order 5 

528 114450437, 23317080, -94230045, 70270200, -20945925, 212837625, # PYCHOK R[3]/n^3, polynomial(n), order 4 

529 15445736, -103193076, 67321800, -16621605, 170270100, # PYCHOK R[4]/n^4, polynomial(n), order 3 

530 -27766753, 16385640, -3517020, 30405375, # PYCHOK R[4]/n^4, polynomial(n), order 3 

531 4892722, -939228, 6081075, # PYCHOK R[4]/n^4, polynomial(n), order 3 

532 -3189007, 14189175), # PYCHOK R[7]/n^7, polynomial(n), order 0, count = 44 

533 8: ( # GEOGRAPHICLIB_RHUMBAREA_ORDER == 8 

534 71374704821, -161769749880, 196369790040, -165062734200, 47622925350, 541702161000, -1389404016000, 1302566265000, 0, 3907698795000, # R[0]/n^0, polynomial(n), order 8 

535 -13691187484, 65947703730, -87559600410, 43504501950, 61062101100, -184013329500, 238803815250, -162820783125, 488462349375, # PYCHOK R[1]/n^1, polynomial(n), order 7 

536 30802104839, -63284544930, 39247999110, 18919268550, -60200615475, 54790485750, -21709437750, 162820783125, # R[2]/n^2, polynomial(n), order 6 

537 -8934064508, 5836972287, 1189171080, -4805732295, 3583780200, -1068242175, 10854718875, # PYCHOK R[3]/n^3, polynomial(n), order 5 

538 50072287748, 3938662680, -26314234380, 17167059000, -4238509275, 43418875500, # R[4]/n^4, polynomial(n), order 4 

539 359094172, -9912730821, 5849673480, -1255576140, 10854718875, # R[5]/n^5, polynomial(n), order 3 

540 -16053944387, 8733508770, -1676521980, 10854718875, # PYCHOK R[6]/n^6, polynomial(n), order 2 

541 930092876, -162639357, 723647925, # R[7]/n^7, polynomial(n), order 1 

542 -673429061, 1929727800) # PYCHOK R[8]/n^8, polynomial(n), order 0, count = 54 

543} 

544 

545__all__ += _ALL_DOCS(Caps) 

546 

547# **) MIT License 

548# 

549# Copyright (C) 2022-2025 -- mrJean1 at Gmail -- All Rights Reserved. 

550# 

551# Permission is hereby granted, free of charge, to any person obtaining a 

552# copy of this software and associated documentation files (the "Software"), 

553# to deal in the Software without restriction, including without limitation 

554# the rights to use, copy, modify, merge, publish, distribute, sublicense, 

555# and/or sell copies of the Software, and to permit persons to whom the 

556# Software is furnished to do so, subject to the following conditions: 

557# 

558# The above copyright notice and this permission notice shall be included 

559# in all copies or substantial portions of the Software. 

560# 

561# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 

562# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 

563# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 

564# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 

565# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 

566# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 

567# OTHER DEALINGS IN THE SOFTWARE.