Coverage for pygeodesy/rhumbx.py: 98%
242 statements
« prev ^ index » next coverage.py v7.2.2, created at 2023-11-12 13:23 -0500
« prev ^ index » next coverage.py v7.2.2, created at 2023-11-12 13:23 -0500
2# -*- coding: utf-8 -*-
4u'''A pure Python version of I{Karney}'s C++ classes U{Rhumb
5<https://GeographicLib.SourceForge.io/C++/doc/classGeographicLib_1_1Rhumb.html>} and U{RhumbLine
6<https://GeographicLib.SourceForge.io/C++/doc/classGeographicLib_1_1RhumbLine.html>} from
7I{GeographicLib version 2.0}.
9Class L{RhumbLine} has been enhanced with methods C{intersection2} and C{nearestOn4} to iteratively
10find the intersection of two rhumb lines, respectively the nearest point on a rumb line along a
11geodesic or perpendicular rhumb line from an other point.
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>}.
19Copyright (C) U{Charles Karney<mailto:Karney@Alum.MIT.edu>} (2014-2022) 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 _ # PYCHOK semicolon
25from pygeodesy.basics import copysign0, neg, _zip
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 .karney
29from pygeodesy.errors import RhumbError, _Xorder
30from pygeodesy.fmath import hypot, hypot1
31# from pygeodesy.fsums import fsum1f_ # _MODS
32# from pygeodesy.interns import NN # from .karney
33from pygeodesy.karney import Caps, _GTuple, NN, _WGS84
34from pygeodesy.ktm import KTransverseMercator, _Xs, \
35 _AlpCoeffs, _BetCoeffs # PYCHOK used!
36from pygeodesy.lazily import _ALL_DOCS, _ALL_LAZY, _ALL_MODS as _MODS
37from pygeodesy.props import deprecated_method, Property, Property_RO, property_RO
38from pygeodesy.rhumbBase import RhumbBase, RhumbLineBase, Int, _update_all_rls
39# from pygeodesy.units import Int # from .rhumbBase
40from pygeodesy.utily import atan1, sincos2_
42from math import asinh, atan, cos, cosh, fabs, radians, sin, sinh, sqrt, tan
44__all__ = _ALL_LAZY.rhumbx
45__version__ = '23.10.27'
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.
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
57 def __init__(self, a_earth=_WGS84, f=None, exact=True, name=NN, **RA_TMorder):
58 '''New C{rhumbx.Rhumb}.
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}), iff B{C{a_earth}} is
64 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 name: Optional name (C{str}).
70 @kwarg RA_TMorder: Optional keyword arguments B{C{RAorder}} and B{C{TMorder}}
71 to set the respective C{order}, see properties C{RAorder}
72 and C{TMorder} and method C{orders}.
74 @raise RhumbError: Invalid B{C{a_earth}}, B{C{f}} or B{C{RA_TMorder}}.
75 '''
76 RhumbBase.__init__(self, a_earth, f, exact, name)
77 if RA_TMorder:
78 self.orders(**RA_TMorder)
80 @Property_RO
81 def _A2(self): # Conformal2RectifyingCoeffs
82 m = self.TMorder
83 return _Xs(_AlpCoeffs, m, self.ellipsoid), m
85 @Property_RO
86 def _B2(self): # Rectifying2ConformalCoeffs
87 m = self.TMorder
88 return _Xs(_BetCoeffs, m, self.ellipsoid), m
90 def _DConformal2Rectifying(self, x, y): # radians
91 return _1_0 + (_sincosSeries(True, x, y, *self._A2) if self.f else _0_0)
93 @deprecated_method
94 def Direct7(self, lat1, lon1, azi12, s12, outmask=Caps.LATITUDE_LONGITUDE_AREA):
95 '''DEPRECATED, use method L{Rhumb.Direct8}.
97 @return: A I{DEPRECATED} L{Rhumb7Tuple}.
98 '''
99 return self.Direct8(lat1, lon1, azi12, s12, outmask=outmask)._to7Tuple()
101 def _DIsometrict(self, phix, phiy, tphix, tphiy, _Dtan_phix_phiy):
102 E = self.ellipsoid
103 return _Dtan_phix_phiy * _Dasinh(tphix, tphiy) - \
104 _Dsin(phix, phiy) * _DeatanhE(sin(phix), sin(phiy), E)
106 def _DIsometric2Rectifyingd(self, psix, psiy): # degrees
107 if self.exact:
108 E = self.ellipsoid
109 phix, phiy, tphix, tphiy = _Eaux4(E.auxIsometric, psix, psiy)
110 t = _Dtant(phix - phiy, tphix, tphiy)
111 r = _over(self._DRectifyingt( tphix, tphiy, t),
112 self._DIsometrict(phix, phiy, tphix, tphiy, t))
113 else:
114 x, y = radians(psix), radians(psiy)
115 r = self._DConformal2Rectifying(_gd(x), _gd(y)) * _Dgd(x, y)
116 return r
118 def _DRectifyingt(self, tphix, tphiy, _Dtan_phix_phiy):
119 E = self.ellipsoid
120 tbetx = E.f1 * tphix
121 tbety = E.f1 * tphiy
122 return (E.f1 * _Dtan_phix_phiy * E.b * PI_2
123 * _DfEt( tbetx, tbety, self._eF)
124 * _Datan(tbetx, tbety)) / E.L
126 def _DRectifying2Conformal(self, x, y): # radians
127 return _1_0 - (_sincosSeries(True, x, y, *self._B2) if self.f else _0_0)
129 def _DRectifying2Isometricd(self, mux, muy): # degrees
130 E = self.ellipsoid
131 phix, phiy, tphix, tphiy = _Eaux4(E.auxRectifying, mux, muy)
132 if self.exact:
133 t = _Dtant(phix - phiy, tphix, tphiy)
134 r = _over(self._DIsometrict(phix, phiy, tphix, tphiy, t),
135 self._DRectifyingt( tphix, tphiy, t))
136 else:
137 r = self._DRectifying2Conformal(radians(mux), radians(muy)) * \
138 _Dgdinv(E.es_taupf(tphix), E.es_taupf(tphiy))
139 return r
141 @Property_RO
142 def _eF(self):
143 '''(INTERNAL) Get the ellipsoid's elliptic function.
144 '''
145 # .k2 = 0.006739496742276434
146 return self.ellipsoid._elliptic_e12 # _MODS.elliptic.Elliptic(-self.ellipsoid._e12)
148 def _Inverse4(self, lon12, r, outmask):
149 '''(INTERNAL) See method C{RhumbBase.Inverse}.
150 '''
151 E, Cs = self.ellipsoid, Caps
152 psi1 = E.auxIsometric(r.lat1)
153 psi2 = E.auxIsometric(r.lat2)
154 psi12 = psi2 - psi1 # degrees
155 if (outmask & Cs.DISTANCE):
156 a = s = hypot(lon12, psi12)
157 if a:
158 a *= self._DIsometric2Rectifyingd(psi2, psi1)
159 s = self._mpd * a # == E._Lpd
160 a = copysign0(a, s)
161 r.set_(a12=a, s12=s)
163 if ((outmask | self._debug) & Cs._DEBUG_INVERSE): # PYCHOK no cover
164 r.set_(a=E.a, f=E.f, f1=E.f1, L=E.L,
165 b=E.b, e=E.e, e2=E.e2, k2=self._eF.k2,
166 lon12=lon12, psi1=psi1, exact=self.exact,
167 psi12=psi12, psi2=psi2)
168 return lon12, psi12, psi1, psi2
170 @deprecated_method
171 def Inverse7(self, lat1, lon1, azi12, s12, outmask=Caps.AZIMUTH_DISTANCE_AREA):
172 '''DEPRECATED, use method L{Rhumb.Inverse8}.
174 @return: A I{DEPRECATED} L{Rhumb7Tuple}.
175 '''
176 return self.Inverse8(lat1, lon1, azi12, s12, outmask=outmask)._to7Tuple()
178 @Property_RO
179 def _mpd(self): # meter per degree
180 return self.ellipsoid._Lpd
182 @Property_RO
183 def _mpr(self): # meter per radian
184 return self.ellipsoid._Lpr # degrees(._Lpd)
186 @deprecated_method
187 def orders(self, RAorder=None, TMorder=None): # PYCHOK expected
188 '''DEPRECATED, use properties C{RAorder} and/or C{TMorder}.
190 Get and set the I{RAorder} and/or I{TMorder}.
192 @kwarg RAorder: I{Rhumb Area} order (C{int}, 4, 5, 6, 7
193 or 8).
194 @kwarg TMorder: I{Transverse Mercator} order (C{int}, 4,
195 5, 6, 7 or 8).
197 @return: L{RhumbOrder2Tuple}C{(RAorder, TMorder)} with
198 the previous C{RAorder} and C{TMorder} setting.
199 '''
200 t = RhumbOrder2Tuple(self.RAorder, self.TMorder)
201 if RAorder not in (None, t.RAorder): # PYCHOK attr
202 self.RAorder = RAorder
203 if TMorder not in (None, t.TMorder): # PYCHOK attr
204 self.TMorder = TMorder
205 return t
207 @Property_RO
208 def _RA2(self):
209 # for WGS84: (0, -0.0005583633519275459, -3.743803759172812e-07, -4.633682270824446e-10,
210 # RAorder 6: -7.709197397676237e-13, -1.5323287106694307e-15, -3.462875359099873e-18)
211 m = self.RAorder
212 return _Xs(_RACoeffs, m, self.ellipsoid, RA=True), m
214 @Property
215 def RAorder(self):
216 '''Get the I{Rhumb Area} order (C{int}, 4, 5, 6, 7 or 8).
217 '''
218 return self._mRA
220 @RAorder.setter # PYCHOK setter!
221 def RAorder(self, order):
222 '''Set the I{Rhumb Area} order (C{int}, 4, 5, 6, 7 or 8).
223 '''
224 m = _Xorder(_RACoeffs, RhumbError, RAorder=order)
225 if self._mRA != m:
226 _update_all_rls(self)
227 self._mRA = m
229# _RhumbLine = RhumbLine # see further below
231 def _S12d(self, psi1, psi2, lon12): # degrees
232 '''(INTERNAL) Compute the area C{S12}.
233 '''
234 S = (self.ellipsoid.areax if self.exact else
235 self.ellipsoid.area) * lon12 / _720_0
236 if S:
237 x, y = radians(psi1), radians(psi2) # _meanSinXi(x, y)
238 s = _Dlog(cosh(x), cosh(y)) * _Dcosh(x, y)
239 if self.f:
240 s += _sincosSeries(False, _gd(x), _gd(y), *self._RA2) * _Dgd(x, y)
241 S *= s
242 return S
245class RhumbLine(RhumbLineBase):
246 '''Compute one or several points on a single rhumb line.
248 Class C{RhumbLine} facilitates the determination of points on
249 a single rhumb line. The starting point (C{lat1}, C{lon1})
250 and the azimuth C{azi12} are specified once.
252 Method C{RhumbLine.Position} returns the location of an other
253 point at distance C{s12} along and the area C{S12} under the
254 rhumb line.
256 Method C{RhumbLine.intersection2} finds the intersection between
257 two rhumb lines.
259 Method C{RhumbLine.nearestOn4} computes the nearest point on and
260 the distance to a rhumb line in different ways.
261 '''
262 _Rhumb = Rhumb # rhumbx.Rhumb
264 def __init__(self, rhumb, lat1=0, lon1=0, azi12=None, **caps_name): # PYCHOK signature
265 '''New C{rhumbx.RhumbLine}.
267 @arg rhumb: The rhumb reference (C{rhumbx.Rhumb}).
268 @kwarg lat1: Latitude of the start point (C{degrees90}).
269 @kwarg lon1: Longitude of the start point (C{degrees180}).
270 @kwarg azi12: Azimuth of this rhumb line (compass C{degrees}).
271 @kwarg caps_name: Optional keyword arguments C{B{name}=NN} and
272 C{B{caps}=0}, a bit-or'ed combination of L{Caps}
273 values specifying the required capabilities. Include
274 C{Caps.LINE_OFF} if updates to the B{C{rhumb}} should
275 I{not} be reflected in this rhumb line.
276 '''
277 RhumbLineBase.__init__(self, rhumb, lat1, lon1, azi12, **caps_name)
279 @Property_RO
280 def _dpm12(self): # PYCHOK no cover
281 '''(INTERNAL) Get this rhumb line's parallel I{circle radius} (C{degree per meter}).
282 '''
283 r = self._salp
284 if r:
285 r = _over(r, self.ellipsoid.circle4(self.lat1).radius)
286 return r
288 @Property_RO
289 def _mu1(self):
290 '''(INTERNAL) Get the I{rectifying auxiliary} latitude (C{degrees}).
291 '''
292 return self.ellipsoid.auxRectifying(self.lat1)
294 def _mu2lat(self, mu):
295 '''(INTERNAL) Get the inverse I{rectifying auxiliary} latitude (C{degrees}).
296 '''
297 return self.ellipsoid.auxRectifying(mu, inverse=True)
299 def _Position4(self, unused, mu2, s12, mu12):
300 '''(INTERNAL) See method C{RhumbLineBase._Position}.
301 '''
302 psi1 = psi2 = self._psi1
303 if mu12: # self._calp != 0
304 lat2 = self._mu2lat(mu2)
305 psi12 = self.rhumb._DRectifying2Isometricd(mu2, self._mu1) * mu12
306 lon2 = self._talp * psi12
307 psi2 += psi12
308 else: # meridional
309 lat2 = self.lat1
310 lon2 = self._dpm12 * s12
311 return lat2, lon2, psi1, psi2
313 @Property_RO
314 def _psi1(self):
315 '''(INTERNAL) Get the I{isometric auxiliary} latitude C{psi} (C{degrees}).
316 '''
317 return self.ellipsoid.auxIsometric(self.lat1)
319 @property_RO
320 def RAorder(self):
321 '''Get this rhumb line's I{Rhumb Area} order (C{int}, 4, 5, 6, 7 or 8).
322 '''
323 return self.rhumb.RAorder
325Rhumb._RhumbLine = RhumbLine # PYCHOK see RhumbBase._RhumbLine
328class RhumbOrder2Tuple(_GTuple):
329 '''2-Tuple C{(RAorder, TMorder)} with a I{Rhumb Area} and
330 I{Transverse Mercator} order, both C{int}, DEPRECATED.
331 '''
332 _Names_ = (Rhumb.RAorder.name, Rhumb.TMorder.name)
333 _Units_ = ( Int, Int)
336# Use I{Divided Differences} to determine (mu2 - mu1) / (psi2 - psi1) accurately.
337# Definition: _Df(x,y,d) = (f(x) - f(y)) / (x - y), @see W. M. Kahan & R. J.
338# Fateman, "Symbolic computation of Divided Differences", SIGSAM Bull. 33(3),
339# 7-28 (1999). U{ACM<https://DL.ACM.org/doi/pdf/10.1145/334714.334716> and @see
340# U{UCB<https://www.CS.Berkeley.edu/~fateman/papers/divdiff.pdf>}, Dec 8, 1999.
342def _Dasinh(x, y):
343 hx = hypot1(x)
344 d = x - y
345 if d:
346 hx *= y
347 hy = x * hypot1(y)
348 t = (d * (x + y) / (hy + hx)) if (x * y) > 0 else (hy - hx)
349 r = asinh(t) / d
350 else:
351 r = _1_0 / hx
352 return r
355def _Datan(x, y):
356 xy = x * y
357 r = xy + _1_0
358 d = x - y
359 if d: # 2 * xy > -1 == 2 * xy + 1 > 0 == xy + r > 0 == xy > -r
360 r = (atan1(d, r) if xy > -r else (atan1(x) - atan1(y))) / d
361 else:
362 r = _1_over(r)
363 return r
366def _Dcosh(x, y):
367 return _Dsincos(x, y, sinh, sinh)
370def _DeatanhE(x, y, E): # see .albers._Datanhee
371 # Deatanhe(x, y) = eatanhe((x - y) / (1 - e^2 * x * y)) / (x - y)
372 e = _1_0 - E.e2 * x * y
373 if e: # assert not isnear0(e)
374 d = x - y
375 e = (E._es_atanh(d / e) / d) if d else (E.e2 / e)
376 return e
379def _DfEt(tx, ty, eF): # tangents
380 # eF = Elliptic(-E.e12) # -E.e2 / (1 - E.e2)
381 r, x, y, = _1_0, atan(tx), atan(ty)
382 d = x - y
383 if (x * y) > 0:
384 # See U{DLMF<https://DLMF.NIST.gov/19.11>}: 19.11.2 and 19.11.4
385 # letting theta -> x, phi -> -y, psi -> z
386 # (E(x) - E(y)) / d = E(z)/d - k2 * sin(x) * sin(y) * sin(z)/d
387 # tan(z/2) = (sin(x)*Delta(y) - sin(y)*Delta(x)) / (cos(x) + cos(y))
388 # = d * Dsin(x,y) * (sin(x) + sin(y))/(cos(x) + cos(y)) /
389 # (sin(x)*Delta(y) + sin(y)*Delta(x))
390 # = t = d * Dt
391 # sin(z) = 2*t/(1+t^2); cos(z) = (1-t^2)/(1+t^2)
392 # Alt (this only works for |z| <= pi/2 -- however, this conditions
393 # holds if x*y > 0):
394 # sin(z) = d * Dsin(x,y) * (sin(x) + sin(y)) /
395 # (sin(x)*cos(y)*Delta(y) + sin(y)*cos(x)*Delta(x))
396 # cos(z) = sqrt((1-sin(z))*(1+sin(z)))
397 sx, cx, sy, cy = sincos2_(x, y)
398 D = (cx + cy) * (eF.fDelta(sy, cy) * sx +
399 eF.fDelta(sx, cx) * sy)
400 D = (sx + sy) * _Dsin(x, y) / D
401 t = D * d
402 t2 = _1_0 + t**2
403 D *= _2_0 / t2
404 s = D * d
405 if s:
406 c = (t + _1_0) * (_1_0 - t) / t2
407 r = eF.fE(s, c, eF.fDelta(s, c)) / s
408 r = D * (r - eF.k2 * sx * sy)
409 elif d:
410 r = (eF.fE(x) - eF.fE(y)) / d
411 return r
414def _Dgd(x, y):
415 return _Datan(sinh(x), sinh(y)) * _Dsinh(x, y)
418def _Dgdinv(x, y): # x, y are tangents
419 return _Dasinh(x, y) / _Datan(x, y)
422def _Dlog(x, y):
423 d = (x - y) * _0_5
424 # Changed atanh(t / (x + y)) to asinh(t / (2 * sqrt(x*y))) to
425 # avoid taking atanh(1) when x is large and y is 1. This also
426 # fixes bogus results being returned for the area when an endpoint
427 # is at a pole. N.B. this routine is invoked with positive x
428 # and y, so the sqrt is always taken of a positive quantity.
429 return (asinh(d / sqrt(x * y)) / d) if d else _1_over(x)
432def _Dsin(x, y):
433 return _Dsincos(x, y, sin, cos)
436def _Dsincos(x, y, sin_, cos_):
437 r = cos_((x + y) * _0_5)
438 d = (x - y) * _0_5
439 if d:
440 r *= sin_(d) / d
441 return r
444def _Dsinh(x, y):
445 return _Dsincos(x, y, sinh, cosh)
448def _Dtan(x, y): # PYCHOK no cover
449 return _Dtant(x - y, tan(x), tan(y))
452def _Dtant(dxy, tx, ty):
453 txy = tx * ty
454 r = txy + _1_0
455 if dxy: # 2 * txy > -1 == 2 * txy + 1 > 0 == txy + r > 0 == txy > -r
456 r = ((tan(dxy) * r) if txy > -r else (tx - ty)) / dxy
457 return r
460def _Eaux4(E_aux, mu_psi_x, mu_psi_y): # degrees
461 # get inverse auxiliary lats in radians and tangents
462 phix = radians(E_aux(mu_psi_x, inverse=True))
463 phiy = radians(E_aux(mu_psi_y, inverse=True))
464 return phix, phiy, tan(phix), tan(phiy)
467def _gd(x):
468 return atan(sinh(x))
471def _sincosSeries(sinp, x, y, C, n):
472 # N.B. C[] has n+1 elements of which
473 # C[0] is ignored and n >= 0
474 # Use Clenshaw summation to evaluate
475 # m = (g(x) + g(y)) / 2 -- mean value
476 # s = (g(x) - g(y)) / (x - y) -- average slope
477 # where
478 # g(x) = sum(C[j] * SC(2 * j * x), j = 1..n)
479 # SC = sinp ? sin : cos
480 # CS = sinp ? cos : sin
481 # ...
482 d, _neg = (x - y), neg
483 sp, cp, sd, cd = sincos2_(x + y, d)
484 sd = (sd / d) if d else _1_0
485 s = _neg(sp * sd) # negative
486 # 2x2 matrices in row-major order
487 a1 = s * d**2
488 a2 = s * _4_0
489 a0 = a3 = _2_0 * cp * cd # m
490 b2 = b1 = _0_0s(4)
491 if n > 0:
492 b1 = C[n], _0_0, _0_0, C[n]
494 _fsum = _MODS.fsums.fsum1f_
495 for j in range(n - 1, 0, -1): # C[0] unused
496 b1, b2, Cj = b2, b1, C[j]
497 # b1 = a * b2 - b1 + C[j] * I
498 m0, m1, m2, m3 = b2
499 n0, n1, n2, n3 = map(_neg, b1)
500 b1 = (_fsum(a0 * m0, a1 * m2, n0, Cj),
501 _fsum(a0 * m1, a1 * m3, n1),
502 _fsum(a2 * m0, a3 * m2, n2),
503 _fsum(a2 * m1, a3 * m3, n3, Cj))
504 # Here are the full expressions for m and s
505 # f01, f02, f11, f12 = (0, 0, cd * sp, 2 * sd * cp) if sinp else \
506 # (1, 0, cd * cp, -2 * sd * sp)
507 # m = -b2[1] * f02 + (C[0] - b2[0]) * f01 + b1[0] * f11 + b1[1] * f12
508 # s = -b2[2] * f01 + (C[0] - b2[3]) * f02 + b1[2] * f11 + b1[3] * f12
509 cd *= b1[2]
510 sd *= b1[3] * _2_0
511 s = _fsum(cd * sp, sd * cp) if sinp else \
512 _fsum(cd * cp, _neg(sd * sp), _neg(b2[2]))
513 return s
516_RACoeffs = { # Generated by Maxima on 2015-05-15 08:24:04-04:00
517 4: ( # GEOGRAPHICLIB_RHUMBAREA_ORDER == 4
518 691, 7860, -20160, 18900, 0, 56700, # R[0]/n^0, polynomial(n), order 4
519 1772, -5340, 6930, -4725, 14175, # R[1]/n^1, polynomial(n), order 3
520 -1747, 1590, -630, 4725, # PYCHOK R[2]/n^2, polynomial(n), order 2
521 104, -31, 315, # R[3]/n^3, polynomial(n), order 1
522 -41, 420), # PYCHOK R[4]/n^4, polynomial(n), order 0, count = 20
523 5: ( # GEOGRAPHICLIB_RHUMBAREA_ORDER == 5
524 -79036, 22803, 259380, -665280, 623700, 0, 1871100, # PYCHOK R[0]/n^0, polynomial(n), order 5
525 41662, 58476, -176220, 228690, -155925, 467775, # PYCHOK R[1]/n^1, polynomial(n), order 4
526 18118, -57651, 52470, -20790, 155925, # PYCHOK R[2]/n^2, polynomial(n), order 3
527 -23011, 17160, -5115, 51975, # PYCHOK R[3]/n^3, polynomial(n), order 2
528 5480, -1353, 13860, # PYCHOK R[4]/n^4, polynomial(n), order 1
529 -668, 5775), # PYCHOK R[5]/n^5, polynomial(n), order 0, count = 27
530 6: ( # GEOGRAPHICLIB_RHUMBAREA_ORDER == 6
531 128346268, -107884140, 31126095, 354053700, -908107200, 851350500, 0, 2554051500, # R[0]/n^0, polynomial(n), order 6
532 -114456994, 56868630, 79819740, -240540300, 312161850, -212837625, 638512875, # PYCHOK R[1]/n^1, polynomial(n), order 5
533 51304574, 24731070, -78693615, 71621550, -28378350, 212837625, # R[2]/n^2, polynomial(n), order 4
534 1554472, -6282003, 4684680, -1396395, 14189175, # R[3]/n^3, polynomial(n), order 3
535 -4913956, 3205800, -791505, 8108100, # PYCHOK R[4]/n^4, polynomial(n), order 2
536 1092376, -234468, 2027025, # R[5]/n^5, polynomial(n), order 1
537 -313076, 2027025), # PYCHOK R[6]/n^6, polynomial(n), order 0, count = 35
538 7: ( # GEOGRAPHICLIB_RHUMBAREA_ORDER == 7
539 -317195588, 385038804, -323652420, 93378285, 1062161100, -2724321600, 2554051500, 0, 7662154500, # PYCHOK R[0]/n^0, polynomial(n), order 7
540 258618446, -343370982, 170605890, 239459220, -721620900, 936485550, -638512875, 1915538625, # PYCHOK R[1]/n^1, polynomial(n), order 6
541 -248174686, 153913722, 74193210, -236080845, 214864650, -85135050, 638512875, # PYCHOK R[2]/n^2, polynomial(n), order 5
542 114450437, 23317080, -94230045, 70270200, -20945925, 212837625, # PYCHOK R[3]/n^3, polynomial(n), order 4
543 15445736, -103193076, 67321800, -16621605, 170270100, # PYCHOK R[4]/n^4, polynomial(n), order 3
544 -27766753, 16385640, -3517020, 30405375, # PYCHOK R[4]/n^4, polynomial(n), order 3
545 4892722, -939228, 6081075, # PYCHOK R[4]/n^4, polynomial(n), order 3
546 -3189007, 14189175), # PYCHOK R[7]/n^7, polynomial(n), order 0, count = 44
547 8: ( # GEOGRAPHICLIB_RHUMBAREA_ORDER == 8
548 71374704821, -161769749880, 196369790040, -165062734200, 47622925350, 541702161000, -1389404016000, 1302566265000, 0, 3907698795000, # R[0]/n^0, polynomial(n), order 8
549 -13691187484, 65947703730, -87559600410, 43504501950, 61062101100, -184013329500, 238803815250, -162820783125, 488462349375, # PYCHOK R[1]/n^1, polynomial(n), order 7
550 30802104839, -63284544930, 39247999110, 18919268550, -60200615475, 54790485750, -21709437750, 162820783125, # R[2]/n^2, polynomial(n), order 6
551 -8934064508, 5836972287, 1189171080, -4805732295, 3583780200, -1068242175, 10854718875, # PYCHOK R[3]/n^3, polynomial(n), order 5
552 50072287748, 3938662680, -26314234380, 17167059000, -4238509275, 43418875500, # R[4]/n^4, polynomial(n), order 4
553 359094172, -9912730821, 5849673480, -1255576140, 10854718875, # R[5]/n^5, polynomial(n), order 3
554 -16053944387, 8733508770, -1676521980, 10854718875, # PYCHOK R[6]/n^6, polynomial(n), order 2
555 930092876, -162639357, 723647925, # R[7]/n^7, polynomial(n), order 1
556 -673429061, 1929727800) # PYCHOK R[8]/n^8, polynomial(n), order 0, count = 54
557}
559__all__ += _ALL_DOCS(Caps, Rhumb, RhumbLine)
561if __name__ == '__main__':
563 from pygeodesy.lazily import printf
565 def _re(fmt, r3, x3):
566 e3 = []
567 for r, x in _zip(r3, x3): # strict=True
568 e = fabs(r - x) / fabs(x)
569 e3.append('%.g' % (e,))
570 printf((fmt % r3) + ' rel errors: ' + ', '.join(e3))
572 # <https://GeographicLib.SourceForge.io/cgi-bin/RhumbSolve> version 2.0
573 rhumb = Rhumb(exact=True) # WGS84 default
574 printf('# %r\n', rhumb)
575 r = rhumb.Direct8(40.6, -73.8, 51, 5.5e6) # from JFK about NE
576 _re('# JFK NE lat2=%.8f, lon2=%.8f, S12=%.1f', (r.lat2, r.lon2, r.S12), (71.68889988, 0.25551982, 44095641862956.148438))
577 r = rhumb.Inverse8(40.6, -73.8, 51.6, -0.5) # JFK to LHR
578 _re('# JFK-LHR azi12=%.8f, s12=%.3f S12=%.1f', (r.azi12, r.s12, r.S12), (77.76838971, 5771083.383328, 37395209100030.367188))
579 r = rhumb.Inverse8(40.6, -73.8, 35.8, 140.3) # JFK to Tokyo Narita
580 _re('# JFK-NRT azi12=%.8f, s12=%.3f S12=%.1f', (r.azi12, r.s12, r.S12), (-92.388887981699639, 12782581.0676841792, -63760642939072.492))
582# % python3 -m pygeodesy.rhumbx
584# Rhumb(RAorder=6, TMorder=6, ellipsoid=Ellipsoid(name='WGS84', a=6378137, b=6356752.31424518, f_=298.25722356, f=0.00335281, f2=0.00336409, n=0.00167922, e=0.08181919, e2=0.00669438, e21=0.99330562, e22=0.0067395, e32=0.00335843, A=6367449.14582341, L=10001965.72931272, R1=6371008.77141506, R2=6371007.18091847, R3=6371000.79000916, Rbiaxial=6367453.63451633, Rtriaxial=6372797.5559594), exact=True)
586# JFK NE lat2=71.68889988, lon2=0.25551982, S12=44095641862956.1 rel errors: 4e-11, 2e-08, 5e-16
587# JFK-LHR azi12=77.76838971, s12=5771083.383 S12=37395209100030.4 rel errors: 3e-12, 5e-15, 0
588# JFK-NRT azi12=-92.38888798, s12=12782581.068 S12=-63760642939072.5 rel errors: 2e-16, 3e-16, 0
590# **) MIT License
591#
592# Copyright (C) 2022-2023 -- mrJean1 at Gmail -- All Rights Reserved.
593#
594# Permission is hereby granted, free of charge, to any person obtaining a
595# copy of this software and associated documentation files (the "Software"),
596# to deal in the Software without restriction, including without limitation
597# the rights to use, copy, modify, merge, publish, distribute, sublicense,
598# and/or sell copies of the Software, and to permit persons to whom the
599# Software is furnished to do so, subject to the following conditions:
600#
601# The above copyright notice and this permission notice shall be included
602# in all copies or substantial portions of the Software.
603#
604# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
605# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
606# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
607# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
608# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
609# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
610# OTHER DEALINGS IN THE SOFTWARE.