1

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

3

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

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

6

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

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

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

10

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

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

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

14'''

15# make sure int/int division yields float quotient

16 from __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 # _MODS

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

41 _180_0, _2__PI, _copysign_1_0, isfinite

42 from pygeodesy.errors import _xError, _xkwds_pop2

43 from pygeodesy.fsums import fsumf_, fsum1f_

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

45 _sincos12, _sin1cos2, \

46 _sinf1cos2d, _TINY

47# from pygeodesy.geodesicw import _Intersecant2 # _MODS

48 from pygeodesy.lazily import _ALL_DOCS, _ALL_MODS as _MODS

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

50 _K_2_0, _llz2gl, _norm2, _norm180, \

51 _sincos2, _sincos2d

52 from pygeodesy.props import Property_RO, property_ROver, _update_all

53 from pygeodesy.utily import atan2, atan2d as _atan2d_reverse, sincos2

54

55 from math import cos, degrees, fabs, floor, radians, sin

56

57__all__ = ()

58__version__ = '25.04.12'

59

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

61

62

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

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

65 any L{GeodesicLineExact} instances tied to the given

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

67 '''

68 _xGeodesicExact(gX=gX)

69 for glX in _glXs: # PYCHOK use weakref?

70 if glX._gX is gX:

71 _update_all(glX)

72

73

74 def _xGeodesicExact(**gX):

75 '''(INTERNAL) Check a L{GeodesicExact} instance.

76 '''

77 _MODS.basics._xinstanceof(_MODS.geodesicx.GeodesicExact, **gX)

78

79

80 class _GeodesicLineExact(_GeodesicBase):

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

82 '''

83 _a13 = _s13 = NAN

84# _azi1 = _0_0

85# _cchi1 = NAN

86# _dn1 = NAN

87 _gX = None # Exact only

88# _k2 = NAN

89# _lat1 = _lon1 = _0_0

90# _salp0 = _calp0 = NAN

91# _salp1 = _calp1 = NAN

92# _somg1 = _comg1 = NAN

93# _ssig1 = _csig1 = NAN

94

95 def __init__(self, gX, lat1, lon1, azi1, caps, **name_):

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

97 '''

98# _xGeodesicExact(gX=gX)

99 if azi1 is None: # see GeodesicExact.InverseLine

100 (salp1, calp1), name_ = _xkwds_pop2(name_, _s_calp1=(_0_0, _1_0))

101 azi1 = _atan2d(salp1, calp1)

102 else: # guard against salp0 underflow, convert -0 to +0

103 azi1 = _norm180(azi1)

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

105 if name_:

106 self.name = name_

107

108 self._gX = gX # GeodesicExact only

109 self._lat1 = lat1 = _fix90(lat1)

110 self._lon1 = lon1

111 self._azi1 = azi1

112 self._salp1 = salp1

113 self._calp1 = calp1

114 # allow lat, azimuth and unrolling of lon

115 self._caps = caps | Caps._AZIMUTH_LATITUDE_LONG_UNROLL

116

117 sbet1, cbet1 = _sinf1cos2d(_around(lat1), gX.f1)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

133 self._somg1 = sbet1 * self._salp0

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

135 # Without normalization we have schi1 = somg1.

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

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

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

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

140 if not (caps & Caps.LINE_OFF):

141 _glXs.append(self)

142 # no need to pre-compute other attrs for (caps & Caps.X). All are

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

144 # arc, distance, C4order is changed or Elliptic function is reset.

145

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

147 if _glXs: # may be empty or None

148 try: # PYCHOK no cover

149 _glXs.remove(self)

150 except (TypeError, ValueError):

151 pass

152 self._gX = None

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

154

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

156 if updated:

157 _update_all(self, *attrs)

158

159 @Property_RO

160 def a1(self):

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

162 the northward equatorial crossing and the first point.

163 '''

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

165

166 equatorarc = a1

167

168 @Property_RO

169 def a13(self):

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

171

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

173 '''

174 return self._a13

175

176 def Arc(self):

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

178

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

180 '''

181 return self.a13

182

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

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

185

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

187 second point (C{degrees}).

188 @kwarg outmask: Bit-or'ed combination of L{Caps<pygeodesy.karney.Caps>}

189 values specifying the quantities to be returned.

190

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

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

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

194 except when C{a12=NAN}.

195

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

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

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

199 '''

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

201

202 @Property_RO

203 def azi0(self):

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

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

206 '''

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

208

209 equatorazimuth = azi0

210

211 @Property_RO

212 def azi0_sincos2(self):

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

214 '''

215 return self._salp0, self._calp0

216

217 @Property_RO

218 def azi1(self):

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

220 '''

221 return self._azi1

222

223 @Property_RO

224 def azi1_sincos2(self):

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

226 '''

227 return self._salp1, self._calp1

228

229 @Property_RO

230 def _B41(self):

231 '''(INTERNAL) Cached/memoized.

232 '''

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

234

235 @Property_RO

236 def _C4a(self):

237 '''(INTERNAL) Cached/memoized.

238 '''

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

240

241 @Property_RO

242 def _caps_DISTANCE_IN(self):

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

244 '''

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

246

247 @Property_RO

248 def _D0k2(self):

249 '''(INTERNAL) Cached/memoized.

250 '''

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

252

253 @Property_RO

254 def _D1(self):

255 '''(INTERNAL) Cached/memoized.

256 '''

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

258

259 def Distance(self):

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

261

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

263 '''

264 return self.s13

265

266 @Property_RO

267 def _E0b(self):

268 '''(INTERNAL) Cached/memoized.

269 '''

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

271

272 @Property_RO

273 def _E1(self):

274 '''(INTERNAL) Cached/memoized.

275 '''

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

277

278 @Property_RO

279 def _eF(self):

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

281 '''

282 # see .gx.GeodesicExact._ef_reset_k2

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

284

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

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

287

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

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

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

291 except when C{a12=NAN}.

292 '''

293 Cs = Caps

294 if outmask:

295 outmask &= self._caps & Cs._OUT_MASK

296 eF = self._eF

297 gX = self.geodesic # ._gX

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

299

300 if not isfinite(s12_a12):

301 # E2 = sig12 = ssig12 = csig12 = NAN

302 return r._toNAN(outmask)

303 elif arcmode: # s12_a12 is (spherical) arc length

304 r.set_(a12=s12_a12)

305 sig12 = radians(s12_a12)

306 if _K_2_0:

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

308 else: # PYCHOK no cover

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

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

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

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

313 E2 = _0_0

314 elif self._caps_DISTANCE_IN: # s12_a12 is distance

315 t = s12_a12 / self._E0b

316 s, c = _sincos2(t) # tau12

317 # tau2 = tau1 + tau12

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

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

320 ssig12, csig12 = _sincos2(sig12)

321 r.set_(a12=degrees(sig12))

322 else: # uninitialized or impossible distance requested

323 return r

324

325 # sig2 = sig1 + sig12

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

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

328 dn2 = eF.fDelta(*t)

329

330 if (outmask & Cs.DISTANCE):

331 outmask ^= Cs.DISTANCE

332 if arcmode: # or f_0_01

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

334 # AB1 = _E0 * (E2 - _E1)

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

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

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

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

339 else:

340 s12 = s12_a12

341 r.set_(s12=s12)

342

343 if not outmask: # all done, see ._GenSet

344 return r

345

346 if self._debug: # PYCHOK no cover

347 outmask |= self._debug & Cs._DEBUG_DIRECT_LINE

348

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

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

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

352

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

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

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

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

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

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

359 cbet2 = csig2 = _TINY

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

361 salp2 = salp0

362 calp2 = calp0 * csig2 # no need to normalize

363

364 if (outmask & Cs.AZIMUTH):

365 r.set_(azi2=_atan2d_reverse(salp2, calp2,

366 reverse=outmask & Cs.REVERSE2))

367

368 if (outmask & Cs.LATITUDE):

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

370

371 if (outmask & Cs.LONGITUDE):

372 schi1 = self._somg1

373 cchi1 = self._cchi1

374 schi2 = ssig2 * salp0

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

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

377 -self._H1, sig12)

378 if (outmask & Cs.LONG_UNROLL):

379 t = _copysign_1_0(salp0) # east-going?

380 tchi1 = t * schi1

381 tchi2 = t * schi2

382 chi12 = t * fsum1f_(atan2(ssig1, csig1), -atan2(ssig2, csig2),

383 atan2(tchi2, cchi2), -atan2(tchi1, cchi1), sig12)

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

385 else:

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

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

388 r.set_(lon2=lon2)

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

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

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

392

393 if (outmask & Cs._REDUCEDLENGTH_GEODESICSCALE):

394 dn1 = self._dn1

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

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

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

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

399 if (outmask & Cs.REDUCEDLENGTH):

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

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

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

403 -dn1 * (ssig1 * csig2),

404 -J12 * (csig1 * csig2)))

405 if (outmask & Cs.GEODESICSCALE):

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

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

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

409

410 if (outmask & Cs.AREA):

411 A4 = salp0 * calp0

412 if A4:

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

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

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

416 # If csig12 > 0, write

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

418 # else

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

420 # No need to normalize

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

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

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

424 A4 *= gX._e2a2

425 B41 = self._B41

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

427 S12 = (B42 - B41) * A4

428 else:

429 S12 = A4 = B41 = B42 = _0_0

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

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

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

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

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

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

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

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

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

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

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

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

442 r.set_(S12=S12)

443

444 r.set_(azi1=_norm180(self.azi1),

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

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

447 return r

448

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

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

451

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

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

454 '''

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

456 return r.toDirect9Tuple()

457

458 def _GenSet(self, debug, s12=None, a12=None, **llz2):

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

460 '''

461 Cs = Caps

462 if debug: # PYCHOK no cover

463 self._debug |= debug & Cs._DEBUG_ALL

464 # _CapsBase.debug._update(self)

465 if s12 is None:

466 if a12 is None: # see GeodesicExact.Line

467 return self

468 s12 = self._GDictPosition(True, a12, outmask=Cs.DISTANCE).s12 if a12 else _0_0

469 elif a12 is None:

470 a12 = self._GDictPosition(False, s12, 0).a12 if s12 else _0_0

471 self._s13 = s12

472 self._a13 = a12

473 self._caps |= Cs.DISTANCE | Cs.DISTANCE_IN

474 # _update_all(self) # new, from GeodesicExact.*Line

475 return _llz2gl(self, **llz2)

476

477 @Property_RO

478 def geodesic(self):

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

480 '''

481 _xGeodesicExact(geodesic=self._gX)

482 return self._gX

483

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

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

486

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

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

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

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

491

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

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

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

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

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

497 along the geodesic from the circle center to the intersection

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

499 and this line at the intersection. The geodesic azimuth

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

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

502 L{GDict} instance.

503

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

505 intersect, no I{perpencular} geodetic

506 intersection or no convergence.

507

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

509 '''

510 try:

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

512 except (TypeError, ValueError) as x:

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

514

515 @Property_RO

516 def _H0e2_f1(self):

517 '''(INTERNAL) Cached/memoized.

518 '''

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

520

521 @Property_RO

522 def _H1(self):

523 '''(INTERNAL) Cached/memoized.

524 '''

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

526

527 @Property_RO

528 def lat1(self):

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

530 '''

531 return self._lat1

532

533 @Property_RO

534 def lon1(self):

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

536 '''

537 return self._lon1

538

539 @Property_RO

540 def _lon1_norm180(self):

541 '''(INTERNAL) Cached/memoized.

542 '''

543 return _norm180(self._lon1)

544

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

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

547 and a geodesic from the given point.

548

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

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

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

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

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

554

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

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

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

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

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

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

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

562 geodesic and this line at the intersection. The geodesic

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

564 L{Position} for further details.

565

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

567 '''

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

569

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

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

572

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

574 @kwarg outmask: Bit-or'ed combination of L{Caps<pygeodesy.karney.Caps>}

575 values specifying the quantities to be returned.

576

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

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

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

580 except when C{a12=NAN}.

581

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

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

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

585

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

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

588 '''

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

590

591 @Property_RO

592 def s13(self):

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

594

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

596 '''

597 return self._s13

598

599 def SetArc(self, a13):

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

601

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

603 point (C{degrees}).

604

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

606 the reference point or C{NAN}.

607 '''

608 if self._a13 != a13:

609 self._GenSet(0, a12=a13)

610 _update_all(self)

611 return self._s13

612

613 def SetDistance(self, s13):

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

615

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

617

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

619 and the reference point or C{NAN}.

620 '''

621 if self._s13 != s13:

622 self._GenSet(0, s12=s13)

623 _update_all(self)

624 return self._a13

625

626 @Property_RO

627 def _stau1_ctau1(self):

628 '''(INTERNAL) Cached/memoized.

629 '''

630 s, c = _sincos2(self._E1)

631 # tau1 = sig1 + B11

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

633 # unnecessary because Einv inverts E

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

635

636 @property_ROver

637 def _toProps7(self):

638 '''(INTERNAL) 7-Tuple of C{toStr} properties.

639 '''

640 C = _GeodesicLineExact

641 return C.lat1, C.lon1, C.azi1, C.a13, C.s13, C.caps, C.geodesic

642

643 def toStr(self, **prec_sep_name): # PYCHOK signature

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

645

646 @see: L{Ellipsoid.toStr<pygeodesy.ellipsoids.Ellipsoid.toStr>}

647 for further details.

648

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

650 '''

651 return self._instr(props=self._toProps7, **prec_sep_name)

652

653

654__all__ += _ALL_DOCS(_GeodesicLineExact)

655

656# **) MIT License

657#

658# Copyright (C) 2016-2025 -- mrJean1 at Gmail -- All Rights Reserved.

659#

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

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

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

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

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

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

666#

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

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

669#

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

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

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

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

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

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

676# OTHER DEALINGS IN THE SOFTWARE.