Coverage for pygeodesy/geodesicx/gxline.py: 97%

238 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2024-02-09 17:20 -0500

1 

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

3 

4u'''A pure Python version of I{Karney}'s C++ class U{GeodesicLineExact 

5<https://GeographicLib.SourceForge.io/C++/doc/classGeographicLib_1_1GeodesicLineExact.html>}. 

6 

7Class L{GeodesicLineExact} follows the naming, methods and return 

8values from class C{GeodesicLine} from I{Karney}'s Python U{geographiclib 

9<https://GeographicLib.SourceForge.io/1.52/python/index.html>}. 

10 

11Copyright (C) U{Charles Karney<mailto:Karney@Alum.MIT.edu>} (2008-2023) 

12and licensed under the MIT/X11 License. For more information, see the 

13U{GeographicLib<https://GeographicLib.SourceForge.io>} documentation. 

14''' 

15# make sure int/int division yields float quotient 

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

17 

18# A copy of comments from Karney's C{GeodesicLineExact.cpp}: 

19# 

20# This is a reformulation of the geodesic problem. The 

21# notation is as follows: 

22# - at a general point (no suffix or 1 or 2 as suffix) 

23# - phi = latitude 

24# - lambda = longitude 

25# - beta = latitude on auxiliary sphere 

26# - omega = longitude on auxiliary sphere 

27# - alpha = azimuth of great circle 

28# - sigma = arc length along great circle 

29# - s = distance 

30# - tau = scaled distance (= sigma at multiples of PI/2) 

31# - at northwards equator crossing 

32# - beta = phi = 0 

33# - omega = lambda = 0 

34# - alpha = alpha0 

35# - sigma = s = 0 

36# - a 12 suffix means a difference, e.g., s12 = s2 - s1. 

37# - s and c prefixes mean sin and cos 

38 

39# from pygeodesy.basics import _xinstanceof # from .karney 

40from pygeodesy.constants import NAN, _EPSmin, _EPSqrt as _TOL, \ 

41 _0_0, _1_0, _180_0, _2__PI, _copysign_1_0 

42from pygeodesy.errors import _xError, _xkwds_get 

43from pygeodesy.fsums import fsumf_, fsum1f_ 

44from pygeodesy.geodesicx.gxbases import _cosSeries, _GeodesicBase, \ 

45 _sincos12, _sin1cos2 

46# from pygeodesy.geodesicw import _Intersecant2 # _MODS 

47from pygeodesy.interns import NN, _COMMASPACE_ 

48from pygeodesy.lazily import _ALL_DOCS, _ALL_MODS as _MODS 

49from pygeodesy.karney import _around, _atan2d, Caps, GDict, _fix90, \ 

50 _K_2_0, _norm2, _norm180, _sincos2, \ 

51 _sincos2d, _xinstanceof 

52from pygeodesy.props import Property_RO, _update_all 

53# from pygeodesy.streprs import pairs # _MODS 

54from pygeodesy.utily import atan2d as _atan2d_reverse, sincos2 

55 

56from math import atan2, cos, degrees, fabs, floor, radians, sin 

57 

58__all__ = () 

59__version__ = '23.11.30' 

60 

61_glXs = [] # instances of C{[_]GeodesicLineExact} to be updated 

62# underflow guard, we require _TINY * EPS > 0, _TINY + EPS == EPS 

63_TINY = _EPSmin 

64# assert (_TINY * EPS) > 0 and (_TINY + EPS) == EPS 

65 

66 

67def _update_glXs(gX): # see GeodesicExact.C4order and -._ef_reset_k2 

68 '''(INTERNAL) Zap cached/memoized C{Property[_RO]}s of 

69 any L{GeodesicLineExact} instances tied to the given 

70 L{GeodesicExact} instance B{C{gX}}. 

71 ''' 

72 _xinstanceof(_MODS.geodesicx.GeodesicExact, gX=gX) 

73 for glX in _glXs: # PYCHOK use weakref? 

74 if glX._gX is gX: 

75 _update_all(glX) 

76 

77 

78class _GeodesicLineExact(_GeodesicBase): 

79 '''(INTERNAL) Base class for L{GeodesicLineExact}. 

80 ''' 

81 _a13 = _s13 = NAN 

82# _azi1 = _0_0 

83# _cchi1 = NAN 

84# _dn1 = NAN 

85 _gX = None # Exact only 

86# _k2 = NAN 

87# _lat1 = _lon1 = _0_0 

88# _salp0 = _calp0 = NAN 

89# _salp1 = _calp1 = NAN 

90# _somg1 = _comg1 = NAN 

91# _ssig1 = _csig1 = NAN 

92 

93 def __init__(self, gX, lat1, lon1, azi1, caps, _debug, *salp1_calp1, **name): # name=NN 

94 '''(INTERNAL) New C{[_]GeodesicLineExact} instance. 

95 ''' 

96 _xinstanceof(_MODS.geodesicx.GeodesicExact, gX=gX) 

97 Cs = Caps 

98 if _debug: # PYCHOK no cover 

99 self._debug |= _debug & Cs._DEBUG_ALL 

100 # _CapsBase.debug._update(self) 

101 if salp1_calp1: 

102 salp1, calp1 = salp1_calp1 

103 else: 

104 azi1 = _norm180(azi1) 

105 # guard against salp0 underflow, 

106 # also -0 is converted to +0 

107 salp1, calp1 = _sincos2d(_around(azi1)) 

108 if name: # *args, name=NN): Python3 

109 name = _xkwds_get(name, name=NN) 

110 if name: 

111 self.name = name 

112 

113 self._gX = gX # GeodesicExact only 

114 self._lat1 = lat1 = _fix90(lat1) 

115 self._lon1 = lon1 

116 self._azi1 = azi1 

117 self._salp1 = salp1 

118 self._calp1 = calp1 

119 # allow lat, azimuth and unrolling of lon 

120 self._caps = caps | Cs._LINE 

121 

122 sbet1, cbet1 = gX._sinf1cos2d(_around(lat1)) 

123 self._dn1 = gX._dn(sbet1, cbet1) 

124 # Evaluate alp0 from sin(alp1) * cos(bet1) = sin(alp0), with alp0 

125 # in [0, pi/2 - |bet1|]. Alt: calp0 = hypot(sbet1, calp1 * cbet1), 

126 # but the following is slightly better, consider the case salp1 = 0. 

127 self._salp0, self._calp0 = _sin1cos2(salp1, calp1, sbet1, cbet1) 

128 self._k2 = self._calp0**2 * gX.ep2 

129 # Evaluate sig with tan(bet1) = tan(sig1) * cos(alp1). 

130 # sig = 0 is nearest northward crossing of equator. 

131 # With bet1 = 0, alp1 = pi/2, we have sig1 = 0 (equatorial line). 

132 # With bet1 = pi/2, alp1 = -pi, sig1 = pi/2 

133 # With bet1 = -pi/2, alp1 = 0 , sig1 = -pi/2 

134 # Evaluate omg1 with tan(omg1) = sin(alp0) * tan(sig1). 

135 # With alp0 in (0, pi/2], quadrants for sig and omg coincide. 

136 # No atan2(0,0) ambiguity at poles since cbet1 = +epsilon. 

137 # With alp0 = 0, omg1 = 0 for alp1 = 0, omg1 = pi for alp1 = pi. 

138 self._somg1 = sbet1 * self._salp0 

139 self._comg1 = c = (cbet1 * calp1) if (sbet1 or calp1) else _1_0 

140 # Without normalization we have schi1 = somg1. 

141 self._cchi1 = gX.f1 * self._dn1 * c 

142 self._ssig1, self._csig1 = _norm2(sbet1, c) # sig1 in (-pi, pi] 

143 # _norm2(somg1, comg1) # no need to normalize! 

144 # _norm2(schi1?, cchi1) # no need to normalize! 

145 if not (caps & Cs.LINE_OFF): 

146 _glXs.append(self) 

147 # no need to pre-compute other attrs based on _Caps.X. All are 

148 # Property_RO's, computed once and cached/memoized until reset 

149 # when C4order is changed or Elliptic function reset is invoked. 

150 

151 def __del__(self): # XXX use weakref? 

152 if _glXs: # may be empty or None 

153 try: # PYCHOK no cover 

154 _glXs.remove(self) 

155 except (TypeError, ValueError): 

156 pass 

157 self._gX = None 

158 # _update_all(self) # throws TypeError during Python 2 cleanup 

159 

160 def _update(self, updated, *attrs, **unused): 

161 if updated: 

162 _update_all(self, *attrs) 

163 

164 @Property_RO 

165 def a1(self): 

166 '''Get the I{equatorial arc} (C{degrees}), the arc length between 

167 the northward equatorial crossing and the first point. 

168 ''' 

169 return _atan2d(self._ssig1, self._csig1) # or NAN 

170 

171 equatorarc = a1 

172 

173 @Property_RO 

174 def a13(self): 

175 '''Get the arc length to reference point 3 (C{degrees}). 

176 

177 @see: Methods L{Arc} and L{SetArc}. 

178 ''' 

179 return self._a13 

180 

181 def Arc(self): 

182 '''Return the arc length to reference point 3 (C{degrees} or C{NAN}). 

183 

184 @see: Method L{SetArc} and property L{a13}. 

185 ''' 

186 return self.a13 

187 

188 def ArcPosition(self, a12, outmask=Caps.STANDARD): 

189 '''Find the position on the line given B{C{a12}}. 

190 

191 @arg a12: Spherical arc length from the first point to the 

192 second point (C{degrees}). 

193 @kwarg outmask: Bit-or'ed combination of L{Caps} values specifying 

194 the quantities to be returned. 

195 

196 @return: A L{GDict} with up to 12 items C{lat1, lon1, azi1, lat2, 

197 lon2, azi2, m12, a12, s12, M12, M21, S12} with C{lat1}, 

198 C{lon1}, C{azi1} and arc length C{a12} always included, 

199 except when C{a12=NAN}. 

200 

201 @note: By default, C{B{outmask}=STANDARD}, meaning thc C{lat1}, 

202 C{lon1}, C{azi1}, C{lat2}, C{lon2}, C{azi2}, C{s12} and 

203 C{a12} entries are returned, except when C{a12=NAN}. 

204 ''' 

205 return self._GDictPosition(True, a12, outmask) 

206 

207 @Property_RO 

208 def azi0(self): 

209 '''Get the I{equatorial azimuth}, the azimuth of this geodesic line 

210 as it crosses the equator in a northward direction (C{degrees90}). 

211 ''' 

212 return _atan2d(*self.azi0_sincos2) # or NAN 

213 

214 equatorazimuth = azi0 

215 

216 @Property_RO 

217 def azi0_sincos2(self): 

218 '''Get the sine and cosine of the I{equatorial azimuth} (2-tuple C{(sin, cos)}). 

219 ''' 

220 return self._salp0, self._calp0 

221 

222 @Property_RO 

223 def azi1(self): 

224 '''Get the azimuth at the first point (compass C{degrees}). 

225 ''' 

226 return self._azi1 

227 

228 @Property_RO 

229 def azi1_sincos2(self): 

230 '''Get the sine and cosine of the first point's azimuth (2-tuple C{(sin, cos)}). 

231 ''' 

232 return self._salp1, self._calp1 

233 

234 @Property_RO 

235 def _B41(self): 

236 '''(INTERNAL) Cached/memoized. 

237 ''' 

238 return _cosSeries(self._C4a, self._ssig1, self._csig1) 

239 

240 @Property_RO 

241 def _C4a(self): 

242 '''(INTERNAL) Cached/memoized. 

243 ''' 

244 return self.geodesic._C4f_k2(self._k2) 

245 

246 @Property_RO 

247 def _caps_DISTANCE_IN(self): 

248 '''(INTERNAL) Get C{Caps.DISTANCE_IN} and C{_OUT}. 

249 ''' 

250 return self.caps & (Caps.DISTANCE_IN & Caps._OUT_MASK) 

251 

252 @Property_RO 

253 def _D0k2(self): 

254 '''(INTERNAL) Cached/memoized. 

255 ''' 

256 return self._eF.cD * _2__PI * self._k2 

257 

258 @Property_RO 

259 def _D1(self): 

260 '''(INTERNAL) Cached/memoized. 

261 ''' 

262 return self._eF.deltaD(self._ssig1, self._csig1, self._dn1) 

263 

264 def Distance(self): 

265 '''Return the distance to reference point 3 (C{meter} or C{NAN}). 

266 

267 @see: Method L{SetDistance} and property L{s13}. 

268 ''' 

269 return self.s13 

270 

271 @Property_RO 

272 def _E0b(self): 

273 '''(INTERNAL) Cached/memoized. 

274 ''' 

275 return self._eF.cE * _2__PI * self.geodesic.b 

276 

277 @Property_RO 

278 def _E1(self): 

279 '''(INTERNAL) Cached/memoized. 

280 ''' 

281 return self._eF.deltaE(self._ssig1, self._csig1, self._dn1) 

282 

283 @Property_RO 

284 def _eF(self): 

285 '''(INTERNAL) Cached/memoized C{Elliptic} function. 

286 ''' 

287 # see .gx.GeodesicExact._ef_reset_k2 

288 return _MODS.elliptic.Elliptic(k2=-self._k2, alpha2=-self.geodesic.ep2) 

289 

290 def _GDictPosition(self, arcmode, s12_a12, outmask=Caps.STANDARD): # MCCABE 17 

291 '''(INTERNAL) Generate a new position along the geodesic. 

292 

293 @return: A L{GDict} with up to 12 items C{lat1, lon1, azi1, lat2, 

294 lon2, azi2, m12, a12, s12, M12, M21, S12} with C{lat1}, 

295 C{lon1}, C{azi1} and arc length C{a12} always included, 

296 except when C{a12=NAN}. 

297 ''' 

298 

299 r = GDict(a12=NAN, s12=NAN) # note both a12 and s12, always 

300 if not (arcmode or self._caps_DISTANCE_IN): # PYCHOK no cover 

301 return r # Uninitialized or impossible distance requested 

302 

303 Cs = Caps 

304 if self._debug: # PYCHOK no cover 

305 outmask |= self._debug & Cs._DEBUG_DIRECT_LINE 

306 outmask &= self._caps & Cs._OUT_MASK 

307 

308 eF = self._eF 

309 gX = self.geodesic # ._gX 

310 

311 if arcmode: 

312 # s12_a12 is spherical arc length 

313 E2 = _0_0 

314 sig12 = radians(s12_a12) 

315 if _K_2_0: 

316 ssig12, csig12 = sincos2(sig12) # utily, no NEG0 

317 else: # PYCHOK no cover 

318 a = fabs(s12_a12) # 0 <= fabs(_remainder(s12_a12, _180_0)) <= 90 

319 a -= floor(a / _180_0) * _180_0 # 0 <= 0 < 180 

320 ssig12 = _0_0 if a == 0 else sin(sig12) 

321 csig12 = _0_0 if a == 90 else cos(sig12) 

322 else: # s12_a12 is distance 

323 t = s12_a12 / self._E0b 

324 s, c = _sincos2(t) # tau12 

325 # tau2 = tau1 + tau12 

326 E2 = -eF.deltaEinv(*_sincos12(-s, c, *self._stau1_ctau1)) 

327 sig12 = fsum1f_(self._E1, -E2, t) # == t - (E2 - E1) 

328 ssig12, csig12 = _sincos2(sig12) 

329 

330 salp0, calp0 = self._salp0, self._calp0 

331 ssig1, csig1 = self._ssig1, self._csig1 

332 

333 # sig2 = sig1 + sig12 

334 ssig2, csig2 = _sincos12(-ssig12, csig12, ssig1, csig1) 

335 dn2 = eF.fDelta(ssig2, csig2) 

336 # sin(bet2) = cos(alp0) * sin(sig2) and 

337 # cbet2 = hypot(salp0, calp0 * csig2). Alt: 

338 # cbet2 = hypot(csig2, salp0 * ssig2) 

339 sbet2, cbet2 = _sin1cos2(calp0, salp0, csig2, ssig2) 

340 if cbet2 == 0: # salp0 = 0, csig2 = 0, break degeneracy 

341 cbet2 = csig2 = _TINY 

342 # tan(alp0) = cos(sig2) * tan(alp2) 

343 salp2 = salp0 

344 calp2 = calp0 * csig2 # no need to normalize 

345 

346 if (outmask & Cs.DISTANCE): 

347 if arcmode: # or f_0_01 

348 E2 = eF.deltaE(ssig2, csig2, dn2) 

349 # AB1 = _E0 * (E2 - _E1) 

350 # s12 = _b * (_E0 * sig12 + AB1) 

351 # = _b * _E0 * (sig12 + (E2 - _E1)) 

352 # = _b * _E0 * (E2 - _E1 + sig12) 

353 s12 = self._E0b * fsum1f_(E2, -self._E1, sig12) 

354 else: 

355 s12 = s12_a12 

356 r.set_(s12=s12) 

357 

358 if (outmask & Cs._DEBUG_DIRECT_LINE): # PYCHOK no cover 

359 r.set_(sig12=sig12, dn2=dn2, b=gX.b, e2=gX.e2, f1=gX.f1, 

360 E0b=self._E0b, E1=self._E1, E2=E2, eFk2=eF.k2, eFa2=eF.alpha2) 

361 

362 if (outmask & Cs.LONGITUDE): 

363 schi1 = self._somg1 

364 cchi1 = self._cchi1 

365 schi2 = ssig2 * salp0 

366 cchi2 = gX.f1 * dn2 * csig2 # schi2 = somg2 without normalization 

367 lam12 = salp0 * self._H0e2_f1 * fsum1f_(eF.deltaH(ssig2, csig2, dn2), 

368 -self._H1, sig12) 

369 if (outmask & Cs.LONG_UNROLL): 

370 _a, t = atan2, _copysign_1_0(salp0) # east-going? 

371 tchi1 = t * schi1 

372 tchi2 = t * schi2 

373 chi12 = t * fsum1f_(_a(ssig1, csig1), -_a(ssig2, csig2), 

374 _a(tchi2, cchi2), -_a(tchi1, cchi1), sig12) 

375 lon2 = self.lon1 + degrees(chi12 - lam12) 

376 else: 

377 chi12 = atan2(*_sincos12(schi1, cchi1, schi2, cchi2)) 

378 lon2 = _norm180(self._lon1_norm180 + _norm180(degrees(chi12 - lam12))) 

379 r.set_(lon2=lon2) 

380 if (outmask & Cs._DEBUG_DIRECT_LINE): # PYCHOK no cover 

381 r.set_(ssig2=ssig2, chi12=chi12, H0e2_f1=self._H0e2_f1, 

382 csig2=csig2, lam12=lam12, H1=self._H1) 

383 

384 if (outmask & Cs.LATITUDE): 

385 r.set_(lat2=_atan2d(sbet2, gX.f1 * cbet2)) 

386 

387 if (outmask & Cs.AZIMUTH): 

388 r.set_(azi2=_atan2d_reverse(salp2, calp2, reverse=outmask & Cs.REVERSE2)) 

389 

390 if (outmask & Cs._REDUCEDLENGTH_GEODESICSCALE): 

391 dn1 = self._dn1 

392 J12 = self._D0k2 * fsumf_(eF.deltaD(ssig2, csig2, dn2), -self._D1, sig12) 

393 if (outmask & Cs._DEBUG_DIRECT_LINE): # PYCHOK no cover 

394 r.set_(ssig1=ssig1, dn1=dn1, D0k2=self._D0k2, 

395 csig1=csig1, J12=J12, D1=self._D1) 

396 if (outmask & Cs.REDUCEDLENGTH): 

397 # Add parens around (csig1 * ssig2) and (ssig1 * csig2) to 

398 # ensure accurate cancellation in the case of coincident points. 

399 r.set_(m12=gX.b * fsum1f_(dn2 * (csig1 * ssig2), 

400 -dn1 * (ssig1 * csig2), 

401 -J12 * (csig1 * csig2))) 

402 if (outmask & Cs.GEODESICSCALE): 

403 t = self._k2 * (ssig2 - ssig1) * (ssig2 + ssig1) / (dn2 + dn1) 

404 r.set_(M12=csig12 + ssig1 * (t * ssig2 - csig2 * J12) / dn1, 

405 M21=csig12 - ssig2 * (t * ssig1 - csig1 * J12) / dn2) 

406 

407 if (outmask & Cs.AREA): 

408 A4 = salp0 * calp0 

409 if A4: 

410 # tan(alp) = tan(alp0) * sec(sig) 

411 # tan(alp2-alp1) = (tan(alp2) - tan(alp1)) / (tan(alp2) * tan(alp1) + 1) 

412 # = calp0 * salp0 * (csig1 - csig2) / (salp0^2 + calp0^2 * csig1 * csig2) 

413 # If csig12 > 0, write 

414 # csig1 - csig2 = ssig12 * (csig1 * ssig12 / (1 + csig12) + ssig1) 

415 # else 

416 # csig1 - csig2 = csig1 * (1 - csig12) + ssig12 * ssig1 

417 # No need to normalize 

418 salp12 = (((ssig12 * csig1 / (_1_0 + csig12) + ssig1) * ssig12) if csig12 > 0 else 

419 (csig1 * (_1_0 - csig12) + ssig1 * ssig12)) * A4 

420 calp12 = salp0**2 + calp0**2 * csig1 * csig2 

421 A4 *= gX._e2a2 

422 B41 = self._B41 

423 B42 = _cosSeries(self._C4a, ssig2, csig2) 

424 S12 = (B42 - B41) * A4 

425 else: 

426 S12 = A4 = B41 = B42 = _0_0 

427 # alp12 = alp2 - alp1, used in atan2 so no need to normalize 

428 salp12, calp12 = _sincos12(self._salp1, self._calp1, salp2, calp2) 

429 # We used to include some patch up code that purported to deal 

430 # with nearly meridional geodesics properly. However, this turned 

431 # out to be wrong once salp1 = -0 was allowed (via InverseLine). 

432 # In fact, the calculation of {s,c}alp12 was already correct 

433 # (following the IEEE rules for handling signed zeros). So, 

434 # the patch up code was unnecessary (as well as dangerous). 

435 if (outmask & Cs._DEBUG_DIRECT_LINE): # PYCHOK no cover 

436 r.set_(salp12=salp12, salp0=salp0, B41=B41, A4=A4, 

437 calp12=calp12, calp0=calp0, B42=B42, c2=gX.c2) 

438 S12 += gX.c2 * atan2(salp12, calp12) 

439 r.set_(S12=S12) 

440 

441 r.set_(a12=s12_a12 if arcmode else degrees(sig12), 

442 lat1=self.lat1, # == _fix90(lat1) 

443 lon1=self.lon1 if (outmask & Cs.LONG_UNROLL) else self._lon1_norm180, 

444 azi1=_norm180(self.azi1)) 

445 return r 

446 

447 def _GenPosition(self, arcmode, s12_a12, outmask): 

448 '''(INTERNAL) Generate a new position along the geodesic. 

449 

450 @return: L{Direct9Tuple}C{(a12, lat2, lon2, azi2, 

451 s12, m12, M12, M21, S12)}. 

452 ''' 

453 r = self._GDictPosition(arcmode, s12_a12, outmask) 

454 return r.toDirect9Tuple() 

455 

456 def _GenSet(self, arcmode, s13_a13): 

457 '''(INTERNAL) Aka C++ C{GenSetDistance}. 

458 ''' 

459 if arcmode: 

460 self.SetArc(s13_a13) 

461 else: 

462 self.SetDistance(s13_a13) 

463 return self # for gx.GeodesicExact.InverseLine and -._GenDirectLine 

464 

465 @Property_RO 

466 def geodesic(self): 

467 '''Get the I{exact} geodesic (L{GeodesicExact}). 

468 ''' 

469 _xinstanceof(_MODS.geodesicx.GeodesicExact, geodesic=self._gX) 

470 return self._gX 

471 

472 def Intersecant2(self, lat0, lon0, radius, tol=_TOL): 

473 '''Compute the intersection(s) of this geodesic line and a circle. 

474 

475 @arg lat0: Latitude of the circle center (C{degrees}). 

476 @arg lon0: Longitude of the circle center (C{degrees}). 

477 @arg radius: Radius of the circle (C{meter}, conventionally). 

478 @kwarg tol: Convergence tolerance (C{scalar}). 

479 

480 @return: 2-Tuple C{(P, Q)} with both intersections (representing 

481 a geodesic chord), each a L{GDict} from method L{Position} 

482 extended to 14 items by C{lon0, lat0, azi0, a02, s02, at} 

483 with the circle center C{lat0}, C{lon0}, azimuth C{azi0} 

484 at, distance C{a02} in C{degrees} and C{s02} in C{meter} 

485 along the geodesic from the circle center to the intersection 

486 C{lat2}, C{lon2} and the angle C{at} between the geodesic 

487 and this line at the intersection. The geodesic azimuth 

488 at the intersection is C{(at + azi2)}. If this geodesic 

489 line is tangential to the circle, both points are the same 

490 L{GDict} instance. 

491 

492 @raise IntersectionError: The circle and this geodesic line do not 

493 intersect, no I{perpencular} geodetic 

494 intersection or no convergence. 

495 

496 @raise UnitError: Invalid B{C{radius}}. 

497 ''' 

498 try: 

499 return _MODS.geodesicw._Intersecant2(self, lat0, lon0, radius, tol=tol) 

500 except (TypeError, ValueError) as x: 

501 raise _xError(x, lat0, lon0, radius, tol=_TOL) 

502 

503 @Property_RO 

504 def _H0e2_f1(self): 

505 '''(INTERNAL) Cached/memoized. 

506 ''' 

507 return self._eF.cH * _2__PI * self.geodesic._e2_f1 

508 

509 @Property_RO 

510 def _H1(self): 

511 '''(INTERNAL) Cached/memoized. 

512 ''' 

513 return self._eF.deltaH(self._ssig1, self._csig1, self._dn1) 

514 

515 @Property_RO 

516 def lat1(self): 

517 '''Get the latitude of the first point (C{degrees}). 

518 ''' 

519 return self._lat1 

520 

521 @Property_RO 

522 def lon1(self): 

523 '''Get the longitude of the first point (C{degrees}). 

524 ''' 

525 return self._lon1 

526 

527 @Property_RO 

528 def _lon1_norm180(self): 

529 '''(INTERNAL) Cached/memoized. 

530 ''' 

531 return _norm180(self._lon1) 

532 

533 def PlumbTo(self, lat0, lon0, est=None, tol=_TOL): 

534 '''Compute the I{perpendicular} intersection of this geodesic line 

535 and a geodesic from the given point. 

536 

537 @arg lat0: Latitude of the point (C{degrees}). 

538 @arg lon0: Longitude of the point (C{degrees}). 

539 @kwarg est: Optional, initial estimate for the distance C{s12} of 

540 the intersection I{along} this geodesic line (C{meter}). 

541 @kwarg tol: Convergence tolerance (C(meter)). 

542 

543 @return: The intersection point on this geodesic line, a L{GDict} 

544 from method L{Position} extended to 14 items C{lat1, lon1, 

545 azi1, lat2, lon2, azi2, a12, s12, lat0, lon0, azi0, a02, 

546 s02, at} with distance C{a02} in C{degrees} and C{s02} in 

547 C{meter} between the given C{lat0, lon0} point and the 

548 intersection C{lat2, lon2}, azimuth C{azi0} at the given 

549 point and C{at} the (perpendicular) angle between the 

550 geodesic and this line at the intersection. The geodesic 

551 azimuth at the intersection is C{(at + azi2)}. See method 

552 L{Position} for further details. 

553 

554 @see: Methods C{Intersecant2}, C{Intersection} and C{Position}. 

555 ''' 

556 return _MODS.geodesicw._PlumbTo(self, lat0, lon0, est=est, tol=tol) 

557 

558 def Position(self, s12, outmask=Caps.STANDARD): 

559 '''Find the position on the line given B{C{s12}}. 

560 

561 @arg s12: Distance from this this line's first point (C{meter}). 

562 @kwarg outmask: Bit-or'ed combination of L{Caps} values specifying 

563 the quantities to be returned. 

564 

565 @return: A L{GDict} with up to 12 items C{lat1, lon1, azi1, lat2, 

566 lon2, azi2, m12, a12, s12, M12, M21, S12} with C{lat1}, 

567 C{lon1}, C{azi1} and arc length C{a12} always included, 

568 except when C{a12=NAN}. 

569 

570 @note: By default, C{B{outmask}=STANDARD}, meaning thc C{lat1}, 

571 C{lon1}, C{azi1}, C{lat2}, C{lon2}, C{azi2}, C{s12} and 

572 C{a12} entries are returned, except when C{a12=NAN}. 

573 

574 @note: This L{GeodesicLineExact} instance must have been 

575 constructed with capability C{Caps.DISTANCE_IN} set. 

576 ''' 

577 return self._GDictPosition(False, s12, outmask) 

578 

579 @Property_RO 

580 def s13(self): 

581 '''Get the distance to reference point 3 (C{meter} or C{NAN}). 

582 

583 @see: Methods L{Distance} and L{SetDistance}. 

584 ''' 

585 return self._s13 

586 

587 def SetArc(self, a13): 

588 '''Set reference point 3 in terms relative to the first point. 

589 

590 @arg a13: Spherical arc length from the first to the reference 

591 point (C{degrees}). 

592 

593 @return: The distance C{s13} (C{meter}) between the first and 

594 the reference point or C{NAN}. 

595 ''' 

596 if self._a13 != a13: 

597 self._a13 = a13 

598 self._s13 = self._GDictPosition(True, a13, Caps.DISTANCE).s12 # if a13 else _0_0 

599 _update_all(self) 

600 return self._s13 

601 

602 def SetDistance(self, s13): 

603 '''Set reference point 3 in terms relative to the first point. 

604 

605 @arg s13: Distance from the first to the reference point (C{meter}). 

606 

607 @return: The arc length C{a13} (C{degrees}) between the first 

608 and the reference point or C{NAN}. 

609 ''' 

610 if self._s13 != s13: 

611 self._s13 = s13 

612 self._a13 = self._GDictPosition(False, s13, 0).a12 if s13 else _0_0 

613 _update_all(self) 

614 return self._a13 # NAN for GeodesicLineExact without Cap.DISTANCE_IN 

615 

616 @Property_RO 

617 def _stau1_ctau1(self): 

618 '''(INTERNAL) Cached/memoized. 

619 ''' 

620 s, c = _sincos2(self._E1) 

621 # tau1 = sig1 + B11 

622 return _sincos12(-s, c, self._ssig1, self._csig1) 

623 # unnecessary because Einv inverts E 

624 # return -self._eF.deltaEinv(stau1, ctau1) 

625 

626 def toStr(self, prec=6, sep=_COMMASPACE_, **unused): # PYCHOK signature 

627 '''Return this C{GeodesicLineExact} as string. 

628 

629 @kwarg prec: The C{float} precision, number of decimal digits (0..9). 

630 Trailing zero decimals are stripped for B{C{prec}} values 

631 of 1 and above, but kept for negative B{C{prec}} values. 

632 @kwarg sep: Separator to join (C{str}). 

633 

634 @return: C{GeodesicLineExact} (C{str}). 

635 ''' 

636 d = dict(geodesic=self.geodesic, 

637 lat1=self.lat1, lon1=self.lon1, azi1=self.azi1, 

638 a13=self.a13, s13=self.s13) 

639 return sep.join(_MODS.streprs.pairs(d, prec=prec)) 

640 

641 

642__all__ += _ALL_DOCS(_GeodesicLineExact) 

643 

644# **) MIT License 

645# 

646# Copyright (C) 2016-2024 -- mrJean1 at Gmail -- All Rights Reserved. 

647# 

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

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

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

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

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

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

654# 

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

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

657# 

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

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

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

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

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

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

664# OTHER DEALINGS IN THE SOFTWARE.