当前位置: 首页>>代码示例>>Python>>正文


Python Math.cbrt方法代码示例

本文整理汇总了Python中geographiclib.geomath.Math.cbrt方法的典型用法代码示例。如果您正苦于以下问题:Python Math.cbrt方法的具体用法?Python Math.cbrt怎么用?Python Math.cbrt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在geographiclib.geomath.Math的用法示例。


在下文中一共展示了Math.cbrt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Astroid

# 需要导入模块: from geographiclib.geomath import Math [as 别名]
# 或者: from geographiclib.geomath.Math import cbrt [as 别名]
 def Astroid(x, y):
   """Private: solve astroid equation."""
   # Solve k^4+2*k^3-(x^2+y^2-1)*k^2-2*y^2*k-y^2 = 0 for positive root k.
   # This solution is adapted from Geocentric::Reverse.
   p = Math.sq(x)
   q = Math.sq(y)
   r = (p + q - 1) / 6
   if not(q == 0 and r <= 0):
     # Avoid possible division by zero when r = 0 by multiplying equations
     # for s and t by r^3 and r, resp.
     S = p * q / 4            # S = r^3 * s
     r2 = Math.sq(r)
     r3 = r * r2
     # The discrimant of the quadratic equation for T3.  This is zero on
     # the evolute curve p^(1/3)+q^(1/3) = 1
     disc = S * (S + 2 * r3)
     u = r
     if (disc >= 0):
       T3 = S + r3
       # Pick the sign on the sqrt to maximize abs(T3).  This minimizes loss
       # of precision due to cancellation.  The result is unchanged because
       # of the way the T is used in definition of u.
       T3 += -math.sqrt(disc) if T3 < 0 else math.sqrt(disc) # T3 = (r * t)^3
       # N.B. cbrt always returns the real root.  cbrt(-8) = -2.
       T = Math.cbrt(T3)       # T = r * t
       # T can be zero; but then r2 / T -> 0.
       u += T + (r2 / T if T != 0 else 0)
     else:
       # T is complex, but the way u is defined the result is real.
       ang = math.atan2(math.sqrt(-disc), -(S + r3))
       # There are three possible cube roots.  We choose the root which
       # avoids cancellation.  Note that disc < 0 implies that r < 0.
       u += 2 * r * math.cos(ang / 3)
     v = math.sqrt(Math.sq(u) + q) # guaranteed positive
     # Avoid loss of accuracy when u < 0.
     uv = q / (v - u) if u < 0 else u + v # u+v, guaranteed positive
     w = (uv - q) / (2 * v)               # positive?
     # Rearrange expression for k to avoid loss of accuracy due to
     # subtraction.  Division by 0 not possible because uv > 0, w >= 0.
     k = uv / (math.sqrt(uv + Math.sq(w)) + w) # guaranteed positive
   else:                                       # q == 0 && r <= 0
     # y = 0 with |x| <= 1.  Handle this case directly.
     # for y small, positive root is k = abs(y)/sqrt(1-x^2)
     k = 0
   return k
开发者ID:Namorus,项目名称:Antenna_Estimator,代码行数:47,代码来源:geodesic.py


注:本文中的geographiclib.geomath.Math.cbrt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。