本文整理汇总了Python中geographiclib.geomath.Math.norm方法的典型用法代码示例。如果您正苦于以下问题:Python Math.norm方法的具体用法?Python Math.norm怎么用?Python Math.norm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geographiclib.geomath.Math
的用法示例。
在下文中一共展示了Math.norm方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from geographiclib.geomath import Math [as 别名]
# 或者: from geographiclib.geomath.Math import norm [as 别名]
def __init__(self, geod, lat1, lon1, azi1,
caps = GeodesicCapability.STANDARD |
GeodesicCapability.DISTANCE_IN,
salp1 = Math.nan, calp1 = Math.nan):
"""Construct a GeodesicLine object
:param geod: a :class:`~geographiclib.geodesic.Geodesic` object
:param lat1: latitude of the first point in degrees
:param lon1: longitude of the first point in degrees
:param azi1: azimuth at the first point in degrees
:param caps: the :ref:`capabilities <outmask>`
This creates an object allowing points along a geodesic starting at
(*lat1*, *lon1*), with azimuth *azi1* to be found. The default
value of *caps* is STANDARD | DISTANCE_IN. The optional parameters
*salp1* and *calp1* should not be supplied; they are part of the
private interface.
"""
from geographiclib.geodesic import Geodesic
self.a = geod.a
"""The equatorial radius in meters (readonly)"""
self.f = geod.f
"""The flattening (readonly)"""
self._b = geod._b
self._c2 = geod._c2
self._f1 = geod._f1
self.caps = (caps | Geodesic.LATITUDE | Geodesic.AZIMUTH |
Geodesic.LONG_UNROLL)
"""the capabilities (readonly)"""
# Guard against underflow in salp0
self.lat1 = Math.LatFix(lat1)
"""the latitude of the first point in degrees (readonly)"""
self.lon1 = lon1
"""the longitude of the first point in degrees (readonly)"""
if Math.isnan(salp1) or Math.isnan(calp1):
self.azi1 = Math.AngNormalize(azi1)
self.salp1, self.calp1 = Math.sincosd(Math.AngRound(azi1))
else:
self.azi1 = azi1
"""the azimuth at the first point in degrees (readonly)"""
self.salp1 = salp1
"""the sine of the azimuth at the first point (readonly)"""
self.calp1 = calp1
"""the cosine of the azimuth at the first point (readonly)"""
# real cbet1, sbet1
sbet1, cbet1 = Math.sincosd(Math.AngRound(lat1)); sbet1 *= self._f1
# Ensure cbet1 = +epsilon at poles
sbet1, cbet1 = Math.norm(sbet1, cbet1); cbet1 = max(Geodesic.tiny_, cbet1)
self._dn1 = math.sqrt(1 + geod._ep2 * Math.sq(sbet1))
# Evaluate alp0 from sin(alp1) * cos(bet1) = sin(alp0),
self._salp0 = self.salp1 * cbet1 # alp0 in [0, pi/2 - |bet1|]
# Alt: calp0 = hypot(sbet1, calp1 * cbet1). The following
# is slightly better (consider the case salp1 = 0).
self._calp0 = math.hypot(self.calp1, self.salp1 * sbet1)
# Evaluate sig with tan(bet1) = tan(sig1) * cos(alp1).
# sig = 0 is nearest northward crossing of equator.
# With bet1 = 0, alp1 = pi/2, we have sig1 = 0 (equatorial line).
# With bet1 = pi/2, alp1 = -pi, sig1 = pi/2
# With bet1 = -pi/2, alp1 = 0 , sig1 = -pi/2
# Evaluate omg1 with tan(omg1) = sin(alp0) * tan(sig1).
# With alp0 in (0, pi/2], quadrants for sig and omg coincide.
# No atan2(0,0) ambiguity at poles since cbet1 = +epsilon.
# With alp0 = 0, omg1 = 0 for alp1 = 0, omg1 = pi for alp1 = pi.
self._ssig1 = sbet1; self._somg1 = self._salp0 * sbet1
self._csig1 = self._comg1 = (cbet1 * self.calp1
if sbet1 != 0 or self.calp1 != 0 else 1)
# sig1 in (-pi, pi]
self._ssig1, self._csig1 = Math.norm(self._ssig1, self._csig1)
# No need to normalize
# self._somg1, self._comg1 = Math.norm(self._somg1, self._comg1)
self._k2 = Math.sq(self._calp0) * geod._ep2
eps = self._k2 / (2 * (1 + math.sqrt(1 + self._k2)) + self._k2)
if self.caps & Geodesic.CAP_C1:
self._A1m1 = Geodesic._A1m1f(eps)
self._C1a = list(range(Geodesic.nC1_ + 1))
Geodesic._C1f(eps, self._C1a)
self._B11 = Geodesic._SinCosSeries(
True, self._ssig1, self._csig1, self._C1a)
s = math.sin(self._B11); c = math.cos(self._B11)
# tau1 = sig1 + B11
self._stau1 = self._ssig1 * c + self._csig1 * s
self._ctau1 = self._csig1 * c - self._ssig1 * s
# Not necessary because C1pa reverts C1a
# _B11 = -_SinCosSeries(true, _stau1, _ctau1, _C1pa)
if self.caps & Geodesic.CAP_C1p:
self._C1pa = list(range(Geodesic.nC1p_ + 1))
Geodesic._C1pf(eps, self._C1pa)
if self.caps & Geodesic.CAP_C2:
self._A2m1 = Geodesic._A2m1f(eps)
self._C2a = list(range(Geodesic.nC2_ + 1))
Geodesic._C2f(eps, self._C2a)
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from geographiclib.geomath import Math [as 别名]
# 或者: from geographiclib.geomath.Math import norm [as 别名]
def __init__(self, geod, lat1, lon1, azi1, caps = GeodesicCapability.ALL):
from geographiclib.geodesic import Geodesic
self._a = geod._a
self._f = geod._f
self._b = geod._b
self._c2 = geod._c2
self._f1 = geod._f1
self._caps = (caps | Geodesic.LATITUDE | Geodesic.AZIMUTH |
Geodesic.LONG_UNROLL)
# Guard against underflow in salp0
azi1 = Math.AngRound(Math.AngNormalize(azi1))
self._lat1 = lat1
self._lon1 = lon1
self._azi1 = azi1
# alp1 is in [0, pi]
alp1 = azi1 * Math.degree
# Enforce sin(pi) == 0 and cos(pi/2) == 0. Better to face the ensuing
# problems directly than to skirt them.
self._salp1 = 0 if azi1 == -180 else math.sin(alp1)
self._calp1 = 0 if abs(azi1) == 90 else math.cos(alp1)
# real cbet1, sbet1, phi
phi = lat1 * Math.degree
# Ensure cbet1 = +epsilon at poles
sbet1 = self._f1 * math.sin(phi)
cbet1 = Geodesic.tiny_ if abs(lat1) == 90 else math.cos(phi)
sbet1, cbet1 = Math.norm(sbet1, cbet1)
self._dn1 = math.sqrt(1 + geod._ep2 * Math.sq(sbet1))
# Evaluate alp0 from sin(alp1) * cos(bet1) = sin(alp0),
self._salp0 = self._salp1 * cbet1 # alp0 in [0, pi/2 - |bet1|]
# Alt: calp0 = hypot(sbet1, calp1 * cbet1). The following
# is slightly better (consider the case salp1 = 0).
self._calp0 = math.hypot(self._calp1, self._salp1 * sbet1)
# Evaluate sig with tan(bet1) = tan(sig1) * cos(alp1).
# sig = 0 is nearest northward crossing of equator.
# With bet1 = 0, alp1 = pi/2, we have sig1 = 0 (equatorial line).
# With bet1 = pi/2, alp1 = -pi, sig1 = pi/2
# With bet1 = -pi/2, alp1 = 0 , sig1 = -pi/2
# Evaluate omg1 with tan(omg1) = sin(alp0) * tan(sig1).
# With alp0 in (0, pi/2], quadrants for sig and omg coincide.
# No atan2(0,0) ambiguity at poles since cbet1 = +epsilon.
# With alp0 = 0, omg1 = 0 for alp1 = 0, omg1 = pi for alp1 = pi.
self._ssig1 = sbet1; self._somg1 = self._salp0 * sbet1
self._csig1 = self._comg1 = (cbet1 * self._calp1
if sbet1 != 0 or self._calp1 != 0 else 1)
# sig1 in (-pi, pi]
self._ssig1, self._csig1 = Math.norm(self._ssig1, self._csig1)
# No need to normalize
# self._somg1, self._comg1 = Math.norm(self._somg1, self._comg1)
self._k2 = Math.sq(self._calp0) * geod._ep2
eps = self._k2 / (2 * (1 + math.sqrt(1 + self._k2)) + self._k2)
if self._caps & Geodesic.CAP_C1:
self._A1m1 = Geodesic.A1m1f(eps)
self._C1a = list(range(Geodesic.nC1_ + 1))
Geodesic.C1f(eps, self._C1a)
self._B11 = Geodesic.SinCosSeries(
True, self._ssig1, self._csig1, self._C1a)
s = math.sin(self._B11); c = math.cos(self._B11)
# tau1 = sig1 + B11
self._stau1 = self._ssig1 * c + self._csig1 * s
self._ctau1 = self._csig1 * c - self._ssig1 * s
# Not necessary because C1pa reverts C1a
# _B11 = -SinCosSeries(true, _stau1, _ctau1, _C1pa)
if self._caps & Geodesic.CAP_C1p:
self._C1pa = list(range(Geodesic.nC1p_ + 1))
Geodesic.C1pf(eps, self._C1pa)
if self._caps & Geodesic.CAP_C2:
self._A2m1 = Geodesic.A2m1f(eps)
self._C2a = list(range(Geodesic.nC2_ + 1))
Geodesic.C2f(eps, self._C2a)
self._B21 = Geodesic.SinCosSeries(
True, self._ssig1, self._csig1, self._C2a)
if self._caps & Geodesic.CAP_C3:
self._C3a = list(range(Geodesic.nC3_))
geod.C3f(eps, self._C3a)
self._A3c = -self._f * self._salp0 * geod.A3f(eps)
self._B31 = Geodesic.SinCosSeries(
True, self._ssig1, self._csig1, self._C3a)
if self._caps & Geodesic.CAP_C4:
self._C4a = list(range(Geodesic.nC4_))
geod.C4f(eps, self._C4a)
# Multiplier = a^2 * e^2 * cos(alpha0) * sin(alpha0)
self._A4 = Math.sq(self._a) * self._calp0 * self._salp0 * geod._e2
self._B41 = Geodesic.SinCosSeries(
False, self._ssig1, self._csig1, self._C4a)
示例3: GenInverse
# 需要导入模块: from geographiclib.geomath import Math [as 别名]
# 或者: from geographiclib.geomath.Math import norm [as 别名]
def GenInverse(self, lat1, lon1, lat2, lon2, outmask):
"""Private: General version of the inverse problem"""
a12 = s12 = azi1 = azi2 = m12 = M12 = M21 = S12 = Math.nan # return vals
outmask &= Geodesic.OUT_MASK
# Compute longitude difference (AngDiff does this carefully). Result is
# in [-180, 180] but -180 is only for west-going geodesics. 180 is for
# east-going and meridional geodesics.
lon12 = Math.AngDiff(Math.AngNormalize(lon1), Math.AngNormalize(lon2))
# If very close to being on the same half-meridian, then make it so.
lon12 = Math.AngRound(lon12)
# Make longitude difference positive.
lonsign = 1 if lon12 >= 0 else -1
lon12 *= lonsign
# If really close to the equator, treat as on equator.
lat1 = Math.AngRound(lat1)
lat2 = Math.AngRound(lat2)
# Swap points so that point with higher (abs) latitude is point 1
swapp = 1 if abs(lat1) >= abs(lat2) else -1
if swapp < 0:
lonsign *= -1
lat2, lat1 = lat1, lat2
# Make lat1 <= 0
latsign = 1 if lat1 < 0 else -1
lat1 *= latsign
lat2 *= latsign
# Now we have
#
# 0 <= lon12 <= 180
# -90 <= lat1 <= 0
# lat1 <= lat2 <= -lat1
#
# longsign, swapp, latsign register the transformation to bring the
# coordinates to this canonical form. In all cases, 1 means no change was
# made. We make these transformations so that there are few cases to
# check, e.g., on verifying quadrants in atan2. In addition, this
# enforces some symmetries in the results returned.
# real phi, sbet1, cbet1, sbet2, cbet2, s12x, m12x
phi = lat1 * Math.degree
# Ensure cbet1 = +epsilon at poles
sbet1 = self._f1 * math.sin(phi)
cbet1 = Geodesic.tiny_ if lat1 == -90 else math.cos(phi)
sbet1, cbet1 = Math.norm(sbet1, cbet1)
phi = lat2 * Math.degree
# Ensure cbet2 = +epsilon at poles
sbet2 = self._f1 * math.sin(phi)
cbet2 = Geodesic.tiny_ if abs(lat2) == 90 else math.cos(phi)
sbet2, cbet2 = Math.norm(sbet2, cbet2)
# If cbet1 < -sbet1, then cbet2 - cbet1 is a sensitive measure of the
# |bet1| - |bet2|. Alternatively (cbet1 >= -sbet1), abs(sbet2) + sbet1 is
# a better measure. This logic is used in assigning calp2 in Lambda12.
# Sometimes these quantities vanish and in that case we force bet2 = +/-
# bet1 exactly. An example where is is necessary is the inverse problem
# 48.522876735459 0 -48.52287673545898293 179.599720456223079643
# which failed with Visual Studio 10 (Release and Debug)
if cbet1 < -sbet1:
if cbet2 == cbet1:
sbet2 = sbet1 if sbet2 < 0 else -sbet1
else:
if abs(sbet2) == -sbet1:
cbet2 = cbet1
dn1 = math.sqrt(1 + self._ep2 * Math.sq(sbet1))
dn2 = math.sqrt(1 + self._ep2 * Math.sq(sbet2))
lam12 = lon12 * Math.degree
slam12 = 0 if lon12 == 180 else math.sin(lam12)
clam12 = math.cos(lam12) # lon12 == 90 isn't interesting
# real a12, sig12, calp1, salp1, calp2, salp2
# index zero elements of these arrays are unused
C1a = list(range(Geodesic.nC1_ + 1))
C2a = list(range(Geodesic.nC2_ + 1))
C3a = list(range(Geodesic.nC3_))
meridian = lat1 == -90 or slam12 == 0
if meridian:
# Endpoints are on a single full meridian, so the geodesic might lie on
# a meridian.
calp1 = clam12; salp1 = slam12 # Head to the target longitude
calp2 = 1; salp2 = 0 # At the target we're heading north
# tan(bet) = tan(sig) * cos(alp)
ssig1 = sbet1; csig1 = calp1 * cbet1
ssig2 = sbet2; csig2 = calp2 * cbet2
# sig12 = sig2 - sig1
sig12 = math.atan2(max(csig1 * ssig2 - ssig1 * csig2, 0.0),
csig1 * csig2 + ssig1 * ssig2)
s12x, m12x, dummy, M12, M21 = self.Lengths(
self._n, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2, cbet1, cbet2,
#.........这里部分代码省略.........
示例4: Lambda12
# 需要导入模块: from geographiclib.geomath import Math [as 别名]
# 或者: from geographiclib.geomath.Math import norm [as 别名]
def Lambda12(self, sbet1, cbet1, dn1, sbet2, cbet2, dn2, salp1, calp1, diffp,
# Scratch areas of the right size
C1a, C2a, C3a):
"""Private: Solve hybrid problem"""
if sbet1 == 0 and calp1 == 0:
# Break degeneracy of equatorial line. This case has already been
# handled.
calp1 = -Geodesic.tiny_
# sin(alp1) * cos(bet1) = sin(alp0)
salp0 = salp1 * cbet1
calp0 = math.hypot(calp1, salp1 * sbet1) # calp0 > 0
# real somg1, comg1, somg2, comg2, omg12, lam12
# tan(bet1) = tan(sig1) * cos(alp1)
# tan(omg1) = sin(alp0) * tan(sig1) = tan(omg1)=tan(alp1)*sin(bet1)
ssig1 = sbet1; somg1 = salp0 * sbet1
csig1 = comg1 = calp1 * cbet1
ssig1, csig1 = Math.norm(ssig1, csig1)
# Math.norm(somg1, comg1); -- don't need to normalize!
# Enforce symmetries in the case abs(bet2) = -bet1. Need to be careful
# about this case, since this can yield singularities in the Newton
# iteration.
# sin(alp2) * cos(bet2) = sin(alp0)
salp2 = salp0 / cbet2 if cbet2 != cbet1 else salp1
# calp2 = sqrt(1 - sq(salp2))
# = sqrt(sq(calp0) - sq(sbet2)) / cbet2
# and subst for calp0 and rearrange to give (choose positive sqrt
# to give alp2 in [0, pi/2]).
calp2 = (math.sqrt(Math.sq(calp1 * cbet1) +
((cbet2 - cbet1) * (cbet1 + cbet2) if cbet1 < -sbet1
else (sbet1 - sbet2) * (sbet1 + sbet2))) / cbet2
if cbet2 != cbet1 or abs(sbet2) != -sbet1 else abs(calp1))
# tan(bet2) = tan(sig2) * cos(alp2)
# tan(omg2) = sin(alp0) * tan(sig2).
ssig2 = sbet2; somg2 = salp0 * sbet2
csig2 = comg2 = calp2 * cbet2
ssig2, csig2 = Math.norm(ssig2, csig2)
# Math.norm(somg2, comg2); -- don't need to normalize!
# sig12 = sig2 - sig1, limit to [0, pi]
sig12 = math.atan2(max(csig1 * ssig2 - ssig1 * csig2, 0.0),
csig1 * csig2 + ssig1 * ssig2)
# omg12 = omg2 - omg1, limit to [0, pi]
omg12 = math.atan2(max(comg1 * somg2 - somg1 * comg2, 0.0),
comg1 * comg2 + somg1 * somg2)
# real B312, h0
k2 = Math.sq(calp0) * self._ep2
eps = k2 / (2 * (1 + math.sqrt(1 + k2)) + k2)
self.C3f(eps, C3a)
B312 = (Geodesic.SinCosSeries(True, ssig2, csig2, C3a) -
Geodesic.SinCosSeries(True, ssig1, csig1, C3a))
h0 = -self._f * self.A3f(eps)
domg12 = salp0 * h0 * (sig12 + B312)
lam12 = omg12 + domg12
if diffp:
if calp2 == 0:
dlam12 = - 2 * self._f1 * dn1 / sbet1
else:
dummy, dlam12, dummy, dummy, dummy = self.Lengths(
eps, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2, cbet1, cbet2,
False, C1a, C2a)
dlam12 *= self._f1 / (calp2 * cbet2)
else:
dlam12 = Math.nan
return (lam12, salp2, calp2, sig12, ssig1, csig1, ssig2, csig2, eps,
domg12, dlam12)
示例5: InverseStart
# 需要导入模块: from geographiclib.geomath import Math [as 别名]
# 或者: from geographiclib.geomath.Math import norm [as 别名]
def InverseStart(self, sbet1, cbet1, dn1, sbet2, cbet2, dn2, lam12,
# Scratch areas of the right size
C1a, C2a):
"""Private: Find a starting value for Newton's method."""
# Return a starting point for Newton's method in salp1 and calp1 (function
# value is -1). If Newton's method doesn't need to be used, return also
# salp2 and calp2 and function value is sig12.
sig12 = -1; salp2 = calp2 = dnm = Math.nan # Return values
# bet12 = bet2 - bet1 in [0, pi); bet12a = bet2 + bet1 in (-pi, 0]
sbet12 = sbet2 * cbet1 - cbet2 * sbet1
cbet12 = cbet2 * cbet1 + sbet2 * sbet1
# Volatile declaration needed to fix inverse cases
# 88.202499451857 0 -88.202499451857 179.981022032992859592
# 89.262080389218 0 -89.262080389218 179.992207982775375662
# 89.333123580033 0 -89.333123580032997687 179.99295812360148422
# which otherwise fail with g++ 4.4.4 x86 -O3
sbet12a = sbet2 * cbet1
sbet12a += cbet2 * sbet1
shortline = cbet12 >= 0 and sbet12 < 0.5 and cbet2 * lam12 < 0.5
omg12 = lam12
if shortline:
sbetm2 = Math.sq(sbet1 + sbet2)
# sin((bet1+bet2)/2)^2
# = (sbet1 + sbet2)^2 / ((sbet1 + sbet2)^2 + (cbet1 + cbet2)^2)
sbetm2 /= sbetm2 + Math.sq(cbet1 + cbet2)
dnm = math.sqrt(1 + self._ep2 * sbetm2)
omg12 /= self._f1 * dnm
somg12 = math.sin(omg12); comg12 = math.cos(omg12)
salp1 = cbet2 * somg12
calp1 = (
sbet12 + cbet2 * sbet1 * Math.sq(somg12) / (1 + comg12) if comg12 >= 0
else sbet12a - cbet2 * sbet1 * Math.sq(somg12) / (1 - comg12))
ssig12 = math.hypot(salp1, calp1)
csig12 = sbet1 * sbet2 + cbet1 * cbet2 * comg12
if shortline and ssig12 < self._etol2:
# really short lines
salp2 = cbet1 * somg12
calp2 = sbet12 - cbet1 * sbet2 * (Math.sq(somg12) / (1 + comg12)
if comg12 >= 0 else 1 - comg12)
salp2, calp2 = Math.norm(salp2, calp2)
# Set return value
sig12 = math.atan2(ssig12, csig12)
elif (abs(self._n) >= 0.1 or # Skip astroid calc if too eccentric
csig12 >= 0 or
ssig12 >= 6 * abs(self._n) * math.pi * Math.sq(cbet1)):
# Nothing to do, zeroth order spherical approximation is OK
pass
else:
# Scale lam12 and bet2 to x, y coordinate system where antipodal point
# is at origin and singular point is at y = 0, x = -1.
# real y, lamscale, betscale
# Volatile declaration needed to fix inverse case
# 56.320923501171 0 -56.320923501171 179.664747671772880215
# which otherwise fails with g++ 4.4.4 x86 -O3
# volatile real x
if self._f >= 0: # In fact f == 0 does not get here
# x = dlong, y = dlat
k2 = Math.sq(sbet1) * self._ep2
eps = k2 / (2 * (1 + math.sqrt(1 + k2)) + k2)
lamscale = self._f * cbet1 * self.A3f(eps) * math.pi
betscale = lamscale * cbet1
x = (lam12 - math.pi) / lamscale
y = sbet12a / betscale
else: # _f < 0
# x = dlat, y = dlong
cbet12a = cbet2 * cbet1 - sbet2 * sbet1
bet12a = math.atan2(sbet12a, cbet12a)
# real m12b, m0, dummy
# In the case of lon12 = 180, this repeats a calculation made in
# Inverse.
dummy, m12b, m0, dummy, dummy = self.Lengths(
self._n, math.pi + bet12a, sbet1, -cbet1, dn1, sbet2, cbet2, dn2,
cbet1, cbet2, False, C1a, C2a)
x = -1 + m12b / (cbet1 * cbet2 * m0 * math.pi)
betscale = (sbet12a / x if x < -0.01
else -self._f * Math.sq(cbet1) * math.pi)
lamscale = betscale / cbet1
y = (lam12 - math.pi) / lamscale
if y > -Geodesic.tol1_ and x > -1 - Geodesic.xthresh_:
# strip near cut
if self._f >= 0:
salp1 = min(1.0, -x); calp1 = - math.sqrt(1 - Math.sq(salp1))
else:
calp1 = max((0.0 if x > -Geodesic.tol1_ else -1.0), x)
salp1 = math.sqrt(1 - Math.sq(calp1))
else:
# Estimate alp1, by solving the astroid problem.
#
# Could estimate alpha1 = theta + pi/2, directly, i.e.,
# calp1 = y/k; salp1 = -x/(1+k); for _f >= 0
# calp1 = x/(1+k); salp1 = -y/k; for _f < 0 (need to check)
#
# However, it's better to estimate omg12 from astroid and use
# spherical formula to compute alp1. This reduces the mean number of
# Newton iterations for astroid cases from 2.24 (min 0, max 6) to 2.12
#.........这里部分代码省略.........
示例6: __init__
# 需要导入模块: from geographiclib.geomath import Math [as 别名]
# 或者: from geographiclib.geomath.Math import norm [as 别名]
def __init__(self, geod, lat1, lon1, azi1, caps = GeodesicCapability.ALL):
"""Construct a GeodesicLine object describing a geodesic line
starting at (lat1, lon1) with azimuth azi1. geod is a Geodesic
object (which embodies the ellipsoid parameters). caps is caps is
an or'ed combination of bit the following values indicating the
capabilities of the returned object
Geodesic.LATITUDE
Geodesic.LONGITUDE
Geodesic.AZIMUTH
Geodesic.DISTANCE
Geodesic.REDUCEDLENGTH
Geodesic.GEODESICSCALE
Geodesic.AREA
Geodesic.DISTANCE_IN
Geodesic.ALL (all of the above)
The default value of caps is ALL.
"""
from geographiclib.geodesic import Geodesic
self._a = geod._a
self._f = geod._f
self._b = geod._b
self._c2 = geod._c2
self._f1 = geod._f1
self._caps = (caps | Geodesic.LATITUDE | Geodesic.AZIMUTH |
Geodesic.LONG_UNROLL)
# Guard against underflow in salp0
self._lat1 = Math.LatFix(lat1)
self._lon1 = lon1
self._azi1 = Math.AngNormalize(azi1)
self._salp1, self._calp1 = Math.sincosd(Math.AngRound(azi1))
# real cbet1, sbet1
sbet1, cbet1 = Math.sincosd(Math.AngRound(lat1)); sbet1 *= self._f1
# Ensure cbet1 = +epsilon at poles
sbet1, cbet1 = Math.norm(sbet1, cbet1); cbet1 = max(Geodesic.tiny_, cbet1)
self._dn1 = math.sqrt(1 + geod._ep2 * Math.sq(sbet1))
# Evaluate alp0 from sin(alp1) * cos(bet1) = sin(alp0),
self._salp0 = self._salp1 * cbet1 # alp0 in [0, pi/2 - |bet1|]
# Alt: calp0 = hypot(sbet1, calp1 * cbet1). The following
# is slightly better (consider the case salp1 = 0).
self._calp0 = math.hypot(self._calp1, self._salp1 * sbet1)
# Evaluate sig with tan(bet1) = tan(sig1) * cos(alp1).
# sig = 0 is nearest northward crossing of equator.
# With bet1 = 0, alp1 = pi/2, we have sig1 = 0 (equatorial line).
# With bet1 = pi/2, alp1 = -pi, sig1 = pi/2
# With bet1 = -pi/2, alp1 = 0 , sig1 = -pi/2
# Evaluate omg1 with tan(omg1) = sin(alp0) * tan(sig1).
# With alp0 in (0, pi/2], quadrants for sig and omg coincide.
# No atan2(0,0) ambiguity at poles since cbet1 = +epsilon.
# With alp0 = 0, omg1 = 0 for alp1 = 0, omg1 = pi for alp1 = pi.
self._ssig1 = sbet1; self._somg1 = self._salp0 * sbet1
self._csig1 = self._comg1 = (cbet1 * self._calp1
if sbet1 != 0 or self._calp1 != 0 else 1)
# sig1 in (-pi, pi]
self._ssig1, self._csig1 = Math.norm(self._ssig1, self._csig1)
# No need to normalize
# self._somg1, self._comg1 = Math.norm(self._somg1, self._comg1)
self._k2 = Math.sq(self._calp0) * geod._ep2
eps = self._k2 / (2 * (1 + math.sqrt(1 + self._k2)) + self._k2)
if self._caps & Geodesic.CAP_C1:
self._A1m1 = Geodesic.A1m1f(eps)
self._C1a = list(range(Geodesic.nC1_ + 1))
Geodesic.C1f(eps, self._C1a)
self._B11 = Geodesic.SinCosSeries(
True, self._ssig1, self._csig1, self._C1a)
s = math.sin(self._B11); c = math.cos(self._B11)
# tau1 = sig1 + B11
self._stau1 = self._ssig1 * c + self._csig1 * s
self._ctau1 = self._csig1 * c - self._ssig1 * s
# Not necessary because C1pa reverts C1a
# _B11 = -SinCosSeries(true, _stau1, _ctau1, _C1pa)
if self._caps & Geodesic.CAP_C1p:
self._C1pa = list(range(Geodesic.nC1p_ + 1))
Geodesic.C1pf(eps, self._C1pa)
if self._caps & Geodesic.CAP_C2:
self._A2m1 = Geodesic.A2m1f(eps)
self._C2a = list(range(Geodesic.nC2_ + 1))
Geodesic.C2f(eps, self._C2a)
self._B21 = Geodesic.SinCosSeries(
True, self._ssig1, self._csig1, self._C2a)
if self._caps & Geodesic.CAP_C3:
self._C3a = list(range(Geodesic.nC3_))
geod.C3f(eps, self._C3a)
self._A3c = -self._f * self._salp0 * geod.A3f(eps)
self._B31 = Geodesic.SinCosSeries(
True, self._ssig1, self._csig1, self._C3a)
if self._caps & Geodesic.CAP_C4:
self._C4a = list(range(Geodesic.nC4_))
#.........这里部分代码省略.........