pygeodesy 25.10.10__py2.py3-none-any.whl → 25.12.12__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. pygeodesy/__init__.py +25 -12
  2. pygeodesy/__main__.py +1 -1
  3. pygeodesy/albers.py +1 -1
  4. pygeodesy/angles.py +960 -0
  5. pygeodesy/auxilats/_CX_4.py +1 -1
  6. pygeodesy/auxilats/_CX_6.py +1 -1
  7. pygeodesy/auxilats/_CX_8.py +1 -1
  8. pygeodesy/auxilats/_CX_Rs.py +1 -1
  9. pygeodesy/auxilats/__init__.py +2 -2
  10. pygeodesy/auxilats/__main__.py +1 -1
  11. pygeodesy/auxilats/auxAngle.py +7 -8
  12. pygeodesy/auxilats/auxDLat.py +1 -1
  13. pygeodesy/auxilats/auxDST.py +1 -1
  14. pygeodesy/auxilats/auxLat.py +1 -1
  15. pygeodesy/auxilats/auxily.py +1 -1
  16. pygeodesy/azimuthal.py +6 -5
  17. pygeodesy/basics.py +14 -10
  18. pygeodesy/booleans.py +8 -33
  19. pygeodesy/cartesianBase.py +7 -7
  20. pygeodesy/clipy.py +17 -23
  21. pygeodesy/constants.py +86 -63
  22. pygeodesy/css.py +1 -1
  23. pygeodesy/datums.py +1 -1
  24. pygeodesy/deprecated/__init__.py +2 -2
  25. pygeodesy/deprecated/bases.py +1 -1
  26. pygeodesy/deprecated/classes.py +32 -2
  27. pygeodesy/deprecated/consterns.py +1 -1
  28. pygeodesy/deprecated/datum.py +1 -1
  29. pygeodesy/deprecated/functions.py +1 -1
  30. pygeodesy/deprecated/nvector.py +1 -1
  31. pygeodesy/deprecated/rhumbBase.py +1 -1
  32. pygeodesy/deprecated/rhumbaux.py +1 -1
  33. pygeodesy/deprecated/rhumbsolve.py +1 -1
  34. pygeodesy/deprecated/rhumbx.py +1 -1
  35. pygeodesy/dms.py +1 -1
  36. pygeodesy/ecef.py +1 -1
  37. pygeodesy/ecefLocals.py +1 -1
  38. pygeodesy/elevations.py +1 -1
  39. pygeodesy/ellipsoidalBase.py +1 -1
  40. pygeodesy/ellipsoidalBaseDI.py +1 -1
  41. pygeodesy/ellipsoidalExact.py +1 -1
  42. pygeodesy/ellipsoidalGeodSolve.py +1 -1
  43. pygeodesy/ellipsoidalKarney.py +1 -1
  44. pygeodesy/ellipsoidalNvector.py +1 -1
  45. pygeodesy/ellipsoidalVincenty.py +1 -1
  46. pygeodesy/ellipsoids.py +7 -6
  47. pygeodesy/elliptic.py +1 -1
  48. pygeodesy/epsg.py +1 -1
  49. pygeodesy/errors.py +8 -4
  50. pygeodesy/etm.py +1 -1
  51. pygeodesy/fmath.py +15 -8
  52. pygeodesy/formy.py +107 -5
  53. pygeodesy/frechet.py +1 -1
  54. pygeodesy/fstats.py +1 -1
  55. pygeodesy/fsums.py +1 -1
  56. pygeodesy/gars.py +1 -1
  57. pygeodesy/geod3solve.py +488 -0
  58. pygeodesy/geodesici.py +4 -4
  59. pygeodesy/geodesicw.py +1 -1
  60. pygeodesy/geodesicx/_C4_24.py +1 -1
  61. pygeodesy/geodesicx/_C4_27.py +1 -1
  62. pygeodesy/geodesicx/_C4_30.py +1 -1
  63. pygeodesy/geodesicx/__init__.py +1 -1
  64. pygeodesy/geodesicx/__main__.py +1 -1
  65. pygeodesy/geodesicx/gx.py +1 -1
  66. pygeodesy/geodesicx/gxarea.py +1 -1
  67. pygeodesy/geodesicx/gxbases.py +1 -1
  68. pygeodesy/geodesicx/gxline.py +1 -1
  69. pygeodesy/geodsolve.py +70 -102
  70. pygeodesy/geohash.py +1 -1
  71. pygeodesy/geoids.py +1 -1
  72. pygeodesy/hausdorff.py +1 -1
  73. pygeodesy/heights.py +1 -1
  74. pygeodesy/internals.py +3 -3
  75. pygeodesy/interns.py +3 -3
  76. pygeodesy/iters.py +1 -1
  77. pygeodesy/karney.py +132 -116
  78. pygeodesy/ktm.py +1 -1
  79. pygeodesy/latlonBase.py +1 -1
  80. pygeodesy/lazily.py +25 -13
  81. pygeodesy/lcc.py +1 -1
  82. pygeodesy/ltp.py +1 -1
  83. pygeodesy/ltpTuples.py +1 -1
  84. pygeodesy/mgrs.py +3 -3
  85. pygeodesy/named.py +14 -9
  86. pygeodesy/namedTuples.py +1 -1
  87. pygeodesy/nvectorBase.py +1 -1
  88. pygeodesy/osgr.py +1 -1
  89. pygeodesy/points.py +1 -1
  90. pygeodesy/props.py +1 -1
  91. pygeodesy/resections.py +1 -1
  92. pygeodesy/rhumb/__init__.py +8 -6
  93. pygeodesy/rhumb/aux_.py +1 -1
  94. pygeodesy/rhumb/bases.py +1 -1
  95. pygeodesy/rhumb/ekx.py +1 -1
  96. pygeodesy/rhumb/solve.py +91 -84
  97. pygeodesy/simplify.py +1 -1
  98. pygeodesy/solveBase.py +72 -49
  99. pygeodesy/sphericalBase.py +1 -1
  100. pygeodesy/sphericalNvector.py +1 -1
  101. pygeodesy/sphericalTrigonometry.py +1 -1
  102. pygeodesy/streprs.py +6 -4
  103. pygeodesy/trf.py +1 -1
  104. pygeodesy/triaxials/__init__.py +70 -0
  105. pygeodesy/triaxials/bases.py +935 -0
  106. pygeodesy/triaxials/conformal3.py +617 -0
  107. pygeodesy/triaxials/triaxial3.py +969 -0
  108. pygeodesy/triaxials/triaxial5.py +1220 -0
  109. pygeodesy/units.py +6 -1
  110. pygeodesy/unitsBase.py +1 -1
  111. pygeodesy/ups.py +2 -3
  112. pygeodesy/utily.py +19 -15
  113. pygeodesy/utm.py +1 -1
  114. pygeodesy/utmups.py +1 -1
  115. pygeodesy/utmupsBase.py +1 -1
  116. pygeodesy/vector2d.py +2 -2
  117. pygeodesy/vector3d.py +1 -1
  118. pygeodesy/vector3dBase.py +195 -51
  119. pygeodesy/webmercator.py +1 -1
  120. pygeodesy/wgrs.py +1 -1
  121. {pygeodesy-25.10.10.dist-info → pygeodesy-25.12.12.dist-info}/METADATA +13 -13
  122. pygeodesy-25.12.12.dist-info/RECORD +125 -0
  123. pygeodesy/triaxials.py +0 -1566
  124. pygeodesy-25.10.10.dist-info/RECORD +0 -119
  125. {pygeodesy-25.10.10.dist-info → pygeodesy-25.12.12.dist-info}/WHEEL +0 -0
  126. {pygeodesy-25.10.10.dist-info → pygeodesy-25.12.12.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,617 @@
1
+
2
+ # -*- coding: utf-8 -*-
3
+
4
+ u'''I{Jacobi Conformal projection} classes L{Conformal3}, L{Conformal3B} and L{Conformal3Sphere} on
5
+ triaxial ellipsoids and spheres using L{Ang}, L{Deg}, L{Rad} lat-, longitude, heading and meridian
6
+ (convergence) angles.
7
+
8
+ Transcoded to pure Python from I{Karney}'s GeographicLib 2.7 C++ class U{Conformal3<https://
9
+ GeographicLib.SourceForge.io/C++/doc/classGeographicLib_1_1Triaxial_1_1Conformal3.html>}.
10
+
11
+ Copyright (C) U{Charles Karney<malto:Karney@Alum.MIT.edu>} (2024-2025) and licensed under the MIT/X11
12
+ License. For more information, see the U{GeographicLib 2.7<https://GeographicLib.SourceForge.io/>}
13
+ documentation.
14
+ '''
15
+ # make sure int/int division yields float quotient, see .basics
16
+ from __future__ import division as _; del _ # noqa: E702 ;
17
+
18
+ from pygeodesy.angles import Ang, _Ang3Tuple, isAng, Property_RO
19
+ from pygeodesy.basics import _copysign, signBit
20
+ from pygeodesy.constants import EPS, INF, NAN, PI_2, \
21
+ _copysign_1_0, _over, _1_over, remainder, \
22
+ _0_0, _0_01, _0_5, _0_75, _1_0, _2_0, _4_0
23
+ from pygeodesy.constants import _16_0 # PYCHOK used!
24
+ from pygeodesy.fmath import hypot1, _ALL_LAZY, Fmt
25
+ from pygeodesy.interns import _DMAIN_, _scale_
26
+ # from pygeodesy.lazily import _ALL_LAZY # from .fmath
27
+ # from pygeodesy.named import _NamedTuple, _Pass # from .namedTuples
28
+ from pygeodesy.namedTuples import Vector2Tuple, _Pass
29
+ # from pygeodesy.props import Property_RO # from .triaxials.angles
30
+ # from pygeodesy.streprs import Fmt # from .fmath
31
+ from pygeodesy.triaxials.bases import _bet_, Conformal5Tuple, LLK, _llk_, \
32
+ _MAXIT, _omg_, TriaxialError, \
33
+ _Triaxial3Base, Vector3d
34
+ from pygeodesy.triaxials.triaxial3 import Triaxial3B
35
+ from pygeodesy.units import Easting, Northing, Radians, Radius_, Scalar
36
+ from pygeodesy.utily import sincos2
37
+ # from pygeodesy.vector3d import Vector3d # from .triaxials.bases
38
+
39
+ from math import atan, atanh, exp, fabs, log, sinh, sqrt
40
+
41
+ __all__ = _ALL_LAZY.triaxials_conformal3
42
+ __version__ = '25.11.29'
43
+
44
+ _gam_ = 'gam'
45
+ _LOG2MIN = log(EPS) * _2_0
46
+ # _N = (log(_4_0) - log(PI)) / (PI_2 - log(_4_0))
47
+ _NLOG2 = -log(_2_0)
48
+ # _B = exp(_N * PI_2) - pow(_4_0, _N)
49
+
50
+
51
+ class BetOmgGam5Tuple(_Ang3Tuple):
52
+ '''5-Tuple C{(bet, omg, gam, scale, llk)} with I{ellipsoidal} lat-
53
+ C{bet}, longitude C{omg} and meridian convergence C{gam} all
54
+ L{Ang}les, C{scale} I{and kind} C{llk} I{set to} C{LLK.CONFORMAL}.
55
+ '''
56
+ _Names_ = (_bet_, _omg_, _gam_, _scale_, _llk_)
57
+ _Units_ = ( Ang, Ang, _Pass, Scalar, _Pass)
58
+
59
+ def __new__(cls, bet, omg, gam, scale=NAN, llk=None, unit=None, **kwds): # **iteration_name
60
+ args = bet, omg, gam, scale, (llk or LLK.CONFORMAL)
61
+ self = _Ang3Tuple.__new__(cls, args, **kwds)
62
+ return self.toUnit(unit) if unit else self
63
+
64
+
65
+ class Conformal3(_Triaxial3Base):
66
+ '''I{Jacobi Conformal} projection of triaxial ellipsoid using class L{Ang}
67
+ lat- and longitudes.
68
+
69
+ @see: L{Triaxial<triaxials.triaxial5.Triaxial>} for details.
70
+ '''
71
+ @Property_RO
72
+ def _a_b(self):
73
+ return self.a / self.b
74
+
75
+ @Property_RO
76
+ def _a2_b(self):
77
+ return self.a * self._a_b # == self.b * self._a2_b2
78
+
79
+ @Property_RO
80
+ def _b_a(self):
81
+ return self.b / self.a # = sqrt(self._b2_a2)
82
+
83
+ @Property_RO
84
+ def _b_c(self):
85
+ return self.b / self.c
86
+
87
+ @Property_RO
88
+ def _c_b(self):
89
+ return self.c / self.b # = sqrt(self._c2_b2)
90
+
91
+ @Property_RO
92
+ def _c2_b(self):
93
+ return self.c * self._c_b # == self.b * self._c2_b2
94
+
95
+ @Property_RO
96
+ def _C3S(self):
97
+ '''(INTERNAL) Cache the I{equivalent Conformal Sphere}.
98
+ '''
99
+ return self.equi3Sphere(*self.xyQ2, name=self.name)
100
+
101
+ def equi3Sphere(self, x, y, **name):
102
+ '''Get this projection's I{equivalent Conformal Sphere}.
103
+
104
+ @arg x: Quadrant x length, easting (C{meter}).
105
+ @arg y: Quadrant y length, northing (C{meter}).
106
+
107
+ @return: The C{Comformal3Sphere} of this projection.
108
+
109
+ @see: Classes L{Conformal3Sphere<triaxials.spheres.Conformal3Sphere>} and
110
+ L{ConformalSphere<triaxials.triaxial5.ConformalSphere>} and I{Karney}'s
111
+ GeographicLib 2.7 C++ U{Triaxial::Conformal3<https://GeographicLib.
112
+ SourceForge.io/C++/doc/classGeographicLib_1_1Triaxial_1_1Conformal3.html>}
113
+ for more information.
114
+ '''
115
+ x, y = self.xyQ2
116
+ # Find C{b, k2, kp2} s.t. C{b * K(kp2) = x},
117
+ # C{b * K(k2) = y} and C{x * K(k2) - y * K(kp2) = 0}.
118
+ _EF = self._Elliptic
119
+ _xy = x < y
120
+ if _xy:
121
+ x, y = y, x
122
+ # Now x >= y, k2 <= 1/2
123
+ if x != y:
124
+ s = x + y
125
+ ny = _over(y, s)
126
+ if ny:
127
+ nx = _over(x, s)
128
+ # assert nx != ny
129
+ # Find initial guess assume K(k2) = pi/2, so K(kp2) = nx/ny * pi/2.
130
+ # Invert using approximate k(K) given in https://arxiv.org/abs/2505.17159v4
131
+ KK = _over(nx, ny) * PI_2
132
+ # k2 = _16_0 / pow(exp(_N * KK) - _B, _2_0 / _N)
133
+ # Alternatively using KK = 1/2*log(16/kp) A+S 17.3.26
134
+ k2 = min(_0_5, exp(-KK * _2_0) * _16_0) # Make sure guess is sane
135
+ logk2 = log(k2)
136
+ if logk2 > _LOG2MIN:
137
+ # Solve for log(k2) to preserve relative accuracy for tiny k2.
138
+ def _k2s2(logk2):
139
+ k2 = exp(logk2)
140
+ kp2 = _1_0 - k2
141
+ xS = _EF(kp2, 0, k2)
142
+ yS = _EF(k2, 0, kp2)
143
+ f = nx * yS.cK - ny * xS.cK
144
+ fp = (nx * (yS.cE - kp2 * yS.cK) +
145
+ ny * (xS.cE - k2 * xS.cK)) / (kp2 * _2_0)
146
+ return f, fp
147
+
148
+ logk2, _, _, _ = _root4(_k2s2, 0, logk2, _LOG2MIN, _NLOG2)
149
+ k2 = exp(logk2)
150
+ # otherwise accept the asymptotic result
151
+ kp2 = _1_0 - k2
152
+ else:
153
+ k2, kp2 = _0_0, _1_0
154
+ else:
155
+ k2 = kp2 = _0_5
156
+ # b * K(kp2) = x
157
+ # b * K(k2) = y
158
+
159
+ K = _EF(k2, 0, kp2).cK
160
+ b = _over(y, K)
161
+ if _xy:
162
+ k2, kp2 = kp2, k2
163
+ return Conformal3Sphere(b, k2, kp2, **name)
164
+
165
+ def forwardBetOmg(self, bet, omg, M=False, **unit_name):
166
+ '''Compute the projection to this conformal triaxial.
167
+
168
+ @arg bet: Ellipsoidal latitude (C{Ang} or B{C{unit}}).
169
+ @arg omg: Ellipsoidal longitude (C{Ang} or B{C{unit}})..
170
+ @kwarg M: If C{True}, compute and include the scale (C{bool}).
171
+ @kwarg unit_name: Optional C{B{unit}=}L{Radians} and C{B{name}=NN} (C{str}).
172
+
173
+ @return: A L{Conformal5Tuple}C{(x, y, z, scale, llk)} with C{z = INT0}
174
+ I{always} and C{scale} if C{B{M}=True}, otherwise C{scale = NAN}.
175
+ '''
176
+ bet, omg, name = _bet_omg_name(bet, omg, **unit_name)
177
+ m = _1_over(self._invScale(bet, omg)) if M else NAN
178
+ return Conformal5Tuple(self._x(omg), self._y(bet), scale=m, **name)
179
+
180
+ def forwardOther(self, other, bet, omg, M=False, **unit_name):
181
+ '''Compute the projection to an other conformal triaxial.
182
+
183
+ @arg other: A conformal triaxial (C{Conformal3}).
184
+ @arg bet: Ellipsoidal latitude (C{Ang} or B{C{unit}}).
185
+ @arg omg: Ellipsoidal longitude (C{Ang} or B{C{unit}}).
186
+ @kwarg M: If C{True}, compute and include the scale (C{bool}).
187
+ @kwarg unit_name: Optional C{B{unit}=}L{Radians} and C{B{name}=NN} (C{str}).
188
+
189
+ @return: A L{BetOmgGam5Tuple}C{(bet, omg, gam, scale, llk)} with C{scale}
190
+ if C{B{M}=True}, otherwise C{scale = NAN}.
191
+ '''
192
+ if not isinstance(other, Conformal3):
193
+ raise TriaxialError(other=other)
194
+ bet, omg, name = _bet_omg_name(bet, omg, **unit_name)
195
+ m = other._C3S.b / self._C3S.b
196
+ ct, v, ma = self.forwardSphere3(bet, omg, M=M)
197
+ ct = Vector3d(ct).times(m)
198
+ bet, omg, gam, mb, _ = other.reverseSphere(ct, dir3d=v, M=M)
199
+ if M:
200
+ m *= _over(ma, mb)
201
+ else:
202
+ m = NAN
203
+ return BetOmgGam5Tuple(bet, omg, gam, m, **name)
204
+
205
+ def forwardSphere3(self, bet, omg, M=False, **unit_name):
206
+ '''Compute the projection to and direction on the equivalent I{Conformal
207
+ Sphere}.
208
+
209
+ @arg bet: Ellipsoidal latitude (C{Ang} or B{C{unit}}).
210
+ @arg omg: Ellipsoidal longitude (C{Ang} or B{C{unit}}).
211
+ @kwarg M: If C{True}, compute and include the scale (C{bool}).
212
+ @kwarg unit_name: Optional C{B{unit}=}L{Radians} and C{B{name}=NN} (C{str}).
213
+
214
+ @return: 3-Tuple C{(cartesian, direction, scale)} with a C{cartesian}
215
+ L{Cartesian5Tuple}C{(x, y, z, h, llk)} on and C{direction} a
216
+ C{Vector3d} due North and tangent to the I{Conformal Sphere}
217
+ and C{scale} if C{B{M}=True}, otherwise C{scale = NAN}.
218
+ '''
219
+ if M:
220
+ bet, omg, _ = _bet_omg_name(bet, omg, **unit_name)
221
+ x, y, _, _, _ = self.forwardBetOmg(bet, omg, M=False, **unit_name)
222
+ S = self._C3S
223
+ bets = _invF(S._yE, y / S.b)
224
+ omgs = _invF(S._xE, x / S.b).shift(-1)
225
+ ct, dir3d = S.forwardBetOmgAlp2(bets, omgs, Ang.N(), **unit_name)
226
+ if M:
227
+ ma = self._invScale(bet, omg)
228
+ mb = _invScale(S, bets, omgs)
229
+ m = self._sphScale(ma, mb)
230
+ else:
231
+ m = NAN
232
+ return ct, dir3d, m
233
+
234
+ def _invScale(self, bet, omg):
235
+ # scale helper
236
+ return _invScale(self, bet, omg.shift(+1))
237
+
238
+ def reverseBetOmg(self, x_cf, y=None, M=False, **unit_name):
239
+ '''Reverse a projection from this conformal triaxial.
240
+
241
+ @arg x_cf: Easting (C{scalar}) or a conformal projection (C{Conformal5Tuple}).
242
+ @kwarg y: Northing (C{scalar}), required if B{C{x_cf}} is C{scalar},
243
+ ignored otherwise.
244
+ @kwarg M: If C{True}, compute and include the scale (C{bool}).
245
+ @kwarg unit_name: Optional C{B{unit}=}L{Radians} and C{B{name}=NN} (C{str}).
246
+
247
+ @return: A L{BetOmgGam5Tuple}C{(bet, omg, gam, scale, llk)} with
248
+ C{gam} set to C{None} and C{scale} only if C{B{M}=True},
249
+ otherwise C{scale is NAN}.
250
+ '''
251
+ x, y = _cf2en(x_cf, y)
252
+ bet = _invPi(self._yE, y / self._c2_b).mod(self._c_b)
253
+ omg = _invPi(self._xE, x / self._a2_b).mod(self._a_b).shift(-1)
254
+ m = _1_over(self._invScale(bet, omg)) if M else NAN
255
+ return BetOmgGam5Tuple(bet, omg, None, m, **unit_name)
256
+
257
+ def reverseOther(self, other, beto, omgo, M=False, **unit_name):
258
+ '''Reverse a projection from an other conformal triaxial.
259
+
260
+ @arg other: A conformal triaxial (C{Conformal3}).
261
+ @arg beto: Ellipsoidal latitude on the B{C{other}} triaxial
262
+ (C{Ang} or B{C{unit}}).
263
+ @arg omgo: Ellipsoidal longitude on the B{C{other}} triaxial
264
+ (C{Ang} or B{C{unit}}).
265
+ @kwarg M: If C{True}, compute and include the scale (C{bool}).
266
+ @kwarg unit_name: Optional C{B{unit}=}L{Radians} and C{B{name}=NN} (C{str}).
267
+
268
+ @return: A L{BetOmgGam5Tuple}C{(bet, omg, gam, scale, llk)} with
269
+ C{scale} if C{B{M}=True}, otherwise C{scale = NAN}.
270
+ '''
271
+ if not isinstance(other, Conformal3):
272
+ raise TriaxialError(other=other)
273
+ bet, omg, gam, m, _ = other.forwardOther(self, beto, omgo, M=M)
274
+ m = _1_over(m) if M else NAN
275
+ return BetOmgGam5Tuple(bet, omg, _Neg(gam), m, **unit_name)
276
+
277
+ def reverseSphere(self, x_ct, y=None, z=None, dir3d=None, M=False, **unit_name):
278
+ '''Reverse a projection from this C{Conformal Sphere} to this triaxial.
279
+
280
+ @arg x_ct: X component (C{scalar}) of or a cartesian on the C{Conformal
281
+ Sphere} (C{Cartesian5Tuple}).
282
+ @kwarg y: Y component (C{scalar}), required if B{C{x_ct}} is C{scalar},
283
+ ignored otherwise.
284
+ @kwarg z: Z component (C{scalar}), like B{C{y}}.
285
+ @kwarg dir3d: The direction (C{Vector3d} or C{None}), reference.
286
+ @kwarg M: If C{True}, compute and include the scale (C{bool}).
287
+ @kwarg unit_name: Optional C{B{unit}=}L{Radians} and C{B{name}=NN} (C{str}).
288
+
289
+ @return: A L{BetOmgGam5Tuple}C{(bet, omg, gam, scale, llk)} with
290
+ C{scale} only if C{B{M}=True}, otherwise C{scale = NAN}.
291
+ '''
292
+ S = self._C3S
293
+ bets, omgs, alp, _, _ = S.reverseBetOmgAlp(x_ct, y, z, dir3d=dir3d)
294
+ _ = Ang._norm(bets, omgs, alp, alt=bool(S.k2 == 0))
295
+ x = S.b * _F(S._xE, omgs.shift(+1))
296
+ y = S.b * _F(S._yE, bets)
297
+ bet, omg, _, _, _ = self.reverseBetOmg(x, y, M=False)
298
+ if M:
299
+ mb = _invScale(S, bets, omgs)
300
+ ma = _invScale(S, bet, omg)
301
+ m = self._sphScale(ma, mb)
302
+ else:
303
+ m = NAN
304
+ return BetOmgGam5Tuple(bet, omg, _Neg(alp), m, **unit_name)
305
+
306
+ def _sphScale(self, ma, mb):
307
+ '''(INTERNAL) Compute the C{scale}.
308
+ '''
309
+ return _over(mb, ma) if ma and mb else self._sphScale_m
310
+
311
+ @Property_RO
312
+ def _sphScale_m(self):
313
+ '''(INTERNAL) Cache the constant C{scale}.
314
+ '''
315
+ e = sqrt(self.e2)
316
+
317
+ def _h1sg(atan_):
318
+ sg = sinh(e * atan_(e))
319
+ return hypot1(sg) + sg
320
+
321
+ k2, kp2 = self._k2_kp2
322
+ if not kp2: # oblate pole
323
+ m = self._c_b * _h1sg(atanh)
324
+ elif not k2: # prolate pole
325
+ m = _over(self._a_b, _h1sg(atan))
326
+ else: # trixial umbilical
327
+ S = self._C3S
328
+ s = _over(S.k2 * S.kp2, k2 * kp2)
329
+ m = (sqrt(s) * (self.b / S.b)) if s > 0 else _0_0
330
+ return m
331
+
332
+ def _x(self, omg): # degrees?
333
+ '''(INTERNAL) Compute an C{x} projection easting.
334
+ '''
335
+ omg = omg.shift(+1)
336
+ _, c, n = omg.scn3
337
+ if (n or signBit(c)) and not self.k2:
338
+ x = NAN
339
+ else:
340
+ x = _Pi(self._xE, omg.mod(self._b_a))
341
+ x *= self._a2_b
342
+ return x
343
+
344
+ @Property_RO
345
+ def xyQ2(self):
346
+ '''Get the quadrant length in x and y direction (Vector2Tuple{x, y}).
347
+ '''
348
+ return Vector2Tuple(self._a2_b * self._xE.cPi,
349
+ self._c2_b * self._yE.cPi,
350
+ name=Conformal3.xyQ2.name)
351
+
352
+ def _y(self, bet): # degrees?
353
+ '''(INTERNAL) Compute a C{y} projection northing.
354
+ '''
355
+ _, c, n = bet.scn3
356
+ if (n or signBit(c)) and not self.kp2:
357
+ y = NAN
358
+ else:
359
+ y = _Pi(self._yE, bet.mod(self._b_c))
360
+ y *= self._c2_b
361
+ return y
362
+
363
+
364
+ class Conformal3B(Conformal3):
365
+ '''I{Jacobi Conformal projection} on a triaxial ellipsoid
366
+ specified by its middle semi-axis and shape.
367
+
368
+ @see: L{Conformal3} for details and more information.
369
+ '''
370
+ def __init__(self, b, e2=_0_0, k2=_1_0, kp2=_0_0, **name):
371
+ '''New L{Conformal3B} triaxial.
372
+
373
+ @note: Use C{B{b}=radius} and C{B{e2}=0} for a conformal
374
+ I{spherical} projection.
375
+
376
+ @see: L{Conformal<triaxials.triaxial5.Conformal.__init__>}.
377
+ '''
378
+ self._init_abc3_e2_k2_kp2(Radius_(b=b), e2, k2, kp2, **name)
379
+
380
+
381
+ class Conformal3Sphere(Triaxial3B): # note C{Triaxial3}!
382
+ '''I{Jacobi Conformal projection} on a I{spherical} triaxial.
383
+
384
+ @see: Method L{equiv3Sphere<triaxials.conformal3.Conformal3.equi3Sphere>}.
385
+ '''
386
+ def __init__(self, radius, k2=_1_0, kp2=_0_0, **name):
387
+ '''New, L{Conformal3Sphere} instance.
388
+
389
+ @see: L{Triaxial3<triaxials.triaxial3.Triaxial3>} for more information.
390
+ '''
391
+ self._init_abc3_e2_k2_kp2(Radius_(radius), 0, k2, kp2, **name)
392
+ # self._xE = self._Elliptic(kp2, 0, k2, **name) # _Triaxial3Base._xE
393
+ # self._yE = self._Elliptic(k2, 0, kp2, **name) # _Triaxial3Base._yE
394
+
395
+
396
+ def _bet_omg_name(bet, omg, unit=Radians, **name):
397
+ '''(INTERNAL) Get C{(bet, omg, name)}.
398
+ '''
399
+ return (Ang.fromScalar(bet, unit=unit),
400
+ Ang.fromScalar(omg, unit=unit), name)
401
+
402
+
403
+ def _cf2en(x_cf, y):
404
+ '''(INTERNAL) Get easting C{x} and notrthing C{y}.
405
+ '''
406
+ return x_cf[:2] if isinstance(x_cf, Conformal5Tuple) else (
407
+ Easting(x_cf), Northing(y))
408
+
409
+
410
+ def _F(eF, phi): # -> float
411
+ '''(INTERNAL) Elliptic function C{F(phi)}.
412
+ '''
413
+ s, c, n = phi.scn3
414
+ if (n or signBit(c)) and not eF.kp2:
415
+ p = NAN
416
+ else:
417
+ p = eF.fF(s, c, eF.fDelta(s, c))
418
+ if n:
419
+ p += eF.cK * n * _4_0
420
+ return p
421
+
422
+
423
+ def _invF(eF, x): # -> Ang
424
+ '''(INTERNAL) Inverse elliptic function C{F(x)}.
425
+ '''
426
+ r, y = _invRy2(eF, eF.cK, x)
427
+ if y: # solve eF.fF(phi) = y for phi
428
+ def _fF2(phi): # -> pair<real, real>
429
+ s, c = sincos2(phi)
430
+ f = eF.fF(s, c, eF.fDelta(s, c))
431
+ fp = sqrt(eF.kp2 + c**2 * eF.k2)
432
+ return f, _1_over(fp)
433
+
434
+ z = fabs(y)
435
+ z, _, _, _ = _root4(_fF2, z, z * PI_2 / eF.cK)
436
+ r += Ang.fromRadians(_copysign(z, y))
437
+ return r
438
+
439
+
440
+ def _invPi(eF, x): # -> Ang
441
+ '''(INTERNAL) Inverse elliptic function C{Pi(x)}.
442
+ '''
443
+ r, y = _invRy2(eF, eF.cPi, x)
444
+ if y: # solve eF.fPi(phi) = y for phi
445
+ def _fPi2(phi): # -> pair<real, real>
446
+ s, c = sincos2(phi)
447
+ f = eF.fPi(s, c, eF.fDelta(s, c))
448
+ a2 = eF.alpha2
449
+ fp = (_1_0 - c**2 * a2) if a2 < 0 else \
450
+ (eF.alphap2 + s**2 * a2)
451
+ fp *= sqrt(eF.kp2 + c**2 * eF.k2)
452
+ return f, _1_over(fp)
453
+
454
+ z = fabs(y)
455
+ z, _, _, _ = _root4(_fPi2, z, z * PI_2 / eF.cPi)
456
+ r += Ang.fromRadians(_copysign(z, y))
457
+ return r
458
+
459
+
460
+ def _invRy2(eF, eF_c, x):
461
+ # helper for C{_invF} and C{_invPi}
462
+ if eF.kp2:
463
+ n = eF_c * _2_0
464
+ y = remainder(x, n)
465
+ n = round((x - y) / n) * _2_0
466
+ else: # eF_c == N-/INF
467
+ y, n = x, _0_0
468
+ if not y:
469
+ y, n = 0, (n if n else y) # signed 0
470
+ elif fabs(y) == eF_c:
471
+ y, n = 0, (_copysign_1_0(y) + n)
472
+ return Ang.cardinal(n), y
473
+
474
+
475
+ def _invScale(triax, bet, omg):
476
+ # helper for triaxial, sphere scale
477
+ k2, kp2 = triax._k2_kp2
478
+ return sqrt(k2 * bet.c**2 + kp2 * omg.c**2)
479
+
480
+
481
+ def _Neg(ang):
482
+ return (-ang) if isAng(ang) else (ang or None)
483
+
484
+
485
+ def _Pi(eF, phi): # -> float
486
+ '''(INTERNAL) Elliptic function C{Pi(phi)}.
487
+ '''
488
+ s, c, n = phi.scn3
489
+ if (n or signBit(c)) and not eF.kp2:
490
+ p = NAN
491
+ else:
492
+ p = eF.fPi(s, c, eF.fDelta(s, c))
493
+ if n:
494
+ p += eF.cPi * n * _4_0
495
+ return p
496
+
497
+
498
+ def _root4(_fp2, z, x, xa=_0_0, xb=PI_2, xscale=1, zscale=1, s=1, tol=EPS): # int s
499
+ '''(INTERNAL) Solve v = _fp2(x) - z = 0.
500
+ '''
501
+ k = b = C = 0
502
+ if xa < xb and xa <= x <= xb:
503
+ # p = PI_2 * 0 #???
504
+ # def _fp2z(x):
505
+ # f, fp = _fp2(x)
506
+ # f -= z
507
+ # # "DAT ", x, f, fp
508
+ # return f
509
+ # a, _, b = map1(_fp2z, xa, x, xb)
510
+ # if (a * b) > 0:
511
+ # raise TriaxalError('"DATBAD")
512
+ # tol = max(tol, EPS) # tol if tol > 0 else EPS
513
+ vtol = tol * zscale * _0_01
514
+ xtol = pow(tol, _0_75) * xscale
515
+ oldv = oldx = olddx = INF
516
+ for k in range(1, _MAXIT):
517
+ # TODO: 20 60 -90 180 127.4974 24.6254 2.4377
518
+ v, vp = _fp2(x)
519
+ v -= z
520
+ va = fabs(v)
521
+ dx = _over(-v, vp)
522
+ # "XX ", k, (xa - p), (x - p), (xb - p), dx, (x + dx - p), v, vp
523
+ if not (va > (0 if k < 2 else vtol)):
524
+ C = 1 # k, va
525
+ break
526
+ elif (v * s) > 0:
527
+ xb = min(xb, x)
528
+ else:
529
+ xa = max(xa, x)
530
+ x += dx
531
+ dxa = fabs(dx)
532
+ if x < xa or x > xb or va > oldv or \
533
+ (k > 2 and dxa > olddx):
534
+ b += 1 # k, xa, x, xb
535
+ x = (xa + xb) * _0_5
536
+ if x == oldx:
537
+ C = 3 # k, x, dx
538
+ break
539
+ elif not dxa > xtol:
540
+ C = 2 # k, dx, xtol
541
+ break
542
+ # "GAPS ", k, dx, (x - xa), (xb - x), oldx, x, (oldx - x)
543
+ oldx = x
544
+ oldv = va
545
+ olddx = dxa * _0_5
546
+ else:
547
+ t = Fmt.no_convergence(dx, xtol)
548
+ raise TriaxialError(x=x, xa=xa, xb=xb, txt=t)
549
+ else:
550
+ x = NAN
551
+ return x, k, b, C
552
+
553
+
554
+ if __name__ == _DMAIN_:
555
+
556
+ from pygeodesy import Degrees, printf
557
+ from pygeodesy.triaxials import Triaxials
558
+
559
+ # <https://GeographicLib.SourceForge.io/C++/doc/Cart3Convert.1.html>
560
+ T = Conformal3(Triaxials.WGS84_3)
561
+ printf(T)
562
+ # name='WGS84_3', a=6378171.36, b=6378101.609999999, c=6356751.84, ...
563
+ t = T.forwardBetOmg(Ang.fromDegrees(33.3), Ang.fromDegrees(44.4), M=True)
564
+ printf((t.x, t.y, t.scale))
565
+ # (-5077802.461853351, 3922572.0186951873, 1.197034384522207)
566
+ # -5077732.396 3922571.859 1.1970343759 C++
567
+ t = T.reverseBetOmg(*t[:2], M=True)
568
+ printf((t.bet.degrees0, t.omg.degrees0, t.scale))
569
+ # (33.47654394192169, 44.39937131735643, 1.1994622456567812)
570
+ # 33.30000000 44.40000000 1.1970343759 C++
571
+
572
+ T = Conformal3(Triaxials.WGS84_3r) # rounded
573
+ printf(T)
574
+ # name='WGS84_3r', a=6378172, b=6378102, c=6356752, ...
575
+ t = T.forwardBetOmg(Degrees(33.3), Degrees(44.4), M=True)
576
+ printf((t.x, t.y, t.scale))
577
+ # (-5077802.439189989, 3922571.859124643, 1.197034375926918)
578
+ # -5077732.396 3922571.859 1.1970343759 C++
579
+ t = T.reverseBetOmg(*t[:2], M=True)
580
+ printf((t.bet.degrees0, t.omg.degrees0, t.scale))
581
+ # (33.47654654826102, 44.39937131735643, 1.1994622731246583)
582
+ # 33.30000000 44.40000000 1.1970343759 C++
583
+
584
+ c = 6378137 * (1 - 1 / (298257223563 / 1000000000))
585
+ T = Conformal3(6378172, 6378102, c)
586
+ printf(T)
587
+ # name='', a=6378172, b=6378102, c=6356752.314245179, ...
588
+ t = T.forwardBetOmg(Degrees(33.3), Degrees(44.4), M=True)
589
+ printf((t.x, t.y, t.scale))
590
+ # (-5077802.461853351, 3922572.0186951873, 1.197034384522207)
591
+ # -5077732.396 3922571.859 1.1970343759 C++
592
+ t = T.reverseBetOmg(*t[:2], M=True)
593
+ printf((t.bet.degrees0, t.omg.degrees0, t.scale))
594
+ # (33.47654394192169, 44.39937131735643, 1.1994622456567812)
595
+ # 33.30000000 44.40000000 1.1970343759 C++
596
+
597
+ # **) MIT License
598
+ #
599
+ # Copyright (C) 2025-2026 -- mrJean1 at Gmail -- All Rights Reserved.
600
+ #
601
+ # Permission is hereby granted, free of charge, to any person obtaining a
602
+ # copy of this software and associated documentation files (the "Software"),
603
+ # to deal in the Software without restriction, including without limitation
604
+ # the rights to use, copy, modify, merge, publish, distribute, sublicense,
605
+ # and/or sell copies of the Software, and to permit persons to whom the
606
+ # Software is furnished to do so, subject to the following conditions:
607
+ #
608
+ # The above copyright notice and this permission notice shall be included
609
+ # in all copies or substantial portions of the Software.
610
+ #
611
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
612
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
613
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
614
+ # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
615
+ # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
616
+ # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
617
+ # OTHER DEALINGS IN THE SOFTWARE.