本文整理匯總了Python中math.asin方法的典型用法代碼示例。如果您正苦於以下問題:Python math.asin方法的具體用法?Python math.asin怎麽用?Python math.asin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類math
的用法示例。
在下文中一共展示了math.asin方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: distance
# 需要導入模塊: import math [as 別名]
# 或者: from math import asin [as 別名]
def distance(pointA, pointB):
"""
Calculate the great circle distance between two points
on the earth (specified in decimal degrees)
http://stackoverflow.com/questions/15736995/how-can-i-quickly-estimate-the-distance-between-two-latitude-longitude-points
"""
# convert decimal degrees to radians
lon1, lat1, lon2, lat2 = map(math.radians, [pointA[1], pointA[0], pointB[1], pointB[0]])
# haversine formula
dlon = lon2 - lon1
dlat = lat2 - lat1
a = math.sin(dlat/2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon/2)**2
c = 2 * math.asin(math.sqrt(a))
r = 3956 # Radius of earth in miles. Use 6371 for kilometers
return c * r
示例2: gcd
# 需要導入模塊: import math [as 別名]
# 或者: from math import asin [as 別名]
def gcd(self, lon1, lat1, lon2, lat2):
"""
Calculate the great circle distance between two points
on the earth (specified in decimal degrees)
"""
# convert decimal degrees to radians
lon1, lat1, lon2, lat2 = map(math.radians, [lon1, lat1, lon2, lat2])
# haversine formula
dlon = lon2 - lon1
dlat = lat2 - lat1
a = math.sin(dlat / 2) ** 2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon / 2) ** 2
c = 2 * math.asin(math.sqrt(a))
dis = E.R * c
return dis
示例3: get_euler
# 需要導入模塊: import math [as 別名]
# 或者: from math import asin [as 別名]
def get_euler(self):
t = self.x * self.y + self.z * self.w
if t > 0.4999:
heading = 2 * math.atan2(self.x, self.w)
attitude = math.pi / 2
bank = 0
elif t < -0.4999:
heading = -2 * math.atan2(self.x, self.w)
attitude = -math.pi / 2
bank = 0
else:
sqx = self.x ** 2
sqy = self.y ** 2
sqz = self.z ** 2
heading = math.atan2(2 * self.y * self.w - 2 * self.x * self.z,
1 - 2 * sqy - 2 * sqz)
attitude = math.asin(2 * t)
bank = math.atan2(2 * self.x * self.w - 2 * self.y * self.z,
1 - 2 * sqx - 2 * sqz)
return heading, attitude, bank
示例4: trig
# 需要導入模塊: import math [as 別名]
# 或者: from math import asin [as 別名]
def trig(a, b=' '):
if is_num(a) and isinstance(b, int):
funcs = [math.sin, math.cos, math.tan,
math.asin, math.acos, math.atan,
math.degrees, math.radians,
math.sinh, math.cosh, math.tanh,
math.asinh, math.acosh, math.atanh]
return funcs[b](a)
if is_lst(a):
width = max(len(row) for row in a)
padded_matrix = [list(row) + (width - len(row)) * [b] for row in a]
transpose = list(zip(*padded_matrix))
if all(isinstance(row, str) for row in a) and isinstance(b, str):
normalizer = ''.join
else:
normalizer = list
norm_trans = [normalizer(padded_row) for padded_row in transpose]
return norm_trans
return unknown_types(trig, ".t", a, b)
示例5: elevation_for
# 需要導入模塊: import math [as 別名]
# 或者: from math import asin [as 別名]
def elevation_for(self, position):
"""Returns elevation to given position in radians
calculation is made inline to have better performance
"""
observer_pos_ecef = self.position_ecef
object_coords_ecef = position
rx = object_coords_ecef[0] - observer_pos_ecef[0]
ry = object_coords_ecef[1] - observer_pos_ecef[1]
rz = object_coords_ecef[2] - observer_pos_ecef[2]
a, b, c = self._cached_elevation_calculation_data
top_z = (a * rx) + (b * ry) + (c * rz)
range_sat = sqrt((rx * rx) + (ry * ry) + (rz * rz))
return asin(top_z / range_sat)
示例6: _haversine
# 需要導入模塊: import math [as 別名]
# 或者: from math import asin [as 別名]
def _haversine(lon1, lat1, lon2, lat2):
"""
Calculate the great circle distance between two points in m
on the earth (specified in decimal degrees)
http://stackoverflow.com/questions/15736995/how-can-i-
quickly-estimate-the-distance-between-two-latitude-longitude-points
"""
# convert decimal degrees to radians
lon1, lat1, lon2, lat2 = list(map(radians, [lon1, lat1, lon2, lat2]))
# haversine formula
dlon = lon2 - lon1
dlat = lat2 - lat1
a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
c = 2 * asin(sqrt(a))
km = 6367 * c
m = 1000. * km
return m
###############################################################################
示例7: testAsinFunction
# 需要導入模塊: import math [as 別名]
# 或者: from math import asin [as 別名]
def testAsinFunction(self):
ma5 = MovingAverage(5, 'close')
holder = Asin(ma5)
sampleClose = np.sin(self.sampleClose)
for i, close in enumerate(sampleClose):
data = {'close': close}
ma5.push(data)
holder.push(data)
expected = math.asin(ma5.result())
calculated = holder.result()
self.assertAlmostEqual(calculated, expected, 12, "at index {0:d}\n"
"expected: {1:f}\n"
"calculated: {2:f}".format(i, expected, calculated))
示例8: align_roll
# 需要導入模塊: import math [as 別名]
# 或者: from math import asin [as 別名]
def align_roll( vec, vecz, tarz ):
sine_roll = vec.normalized().dot(vecz.normalized().cross(tarz.normalized()))
if 1 < abs(sine_roll):
sine_roll /= abs(sine_roll)
if 0 < vecz.dot( tarz ):
return math.asin( sine_roll )
elif 0 < sine_roll:
return -math.asin( sine_roll ) + math.pi
else:
return -math.asin( sine_roll ) - math.pi
#######################################################
示例9: angular_position
# 需要導入模塊: import math [as 別名]
# 或者: from math import asin [as 別名]
def angular_position(texcoord):
up = texcoord[0]
v = texcoord[1]
# correct for hemisphere
if up>=0.5:
u = 2.0*(up-0.5)
else:
u = 2.0*up
# ignore points outside of circles
if ((u-0.5)*(u-0.5) + (v-0.5)*(v-0.5))>0.25:
return None, None
# v: 0..1-> vp: -1..1
phi = math.asin(2.0*(v-0.5))
# u = math.cos(phi)*math.cos(theta)
# u: 0..1 -> upp: -1..1
u = 1.0-u
theta = math.acos( 2.0*(u-0.5) / math.cos(phi) )
if up<0.5:
theta = theta-math.pi
return (theta,phi)
示例10: find_angle_graph
# 需要導入模塊: import math [as 別名]
# 或者: from math import asin [as 別名]
def find_angle_graph(velocity, vertical_velocity, interp=False):
angle = []
for i in range(len(velocity)):
if velocity[i] == 0:
angle.append(angle[-1])
else:
ratio = max(-1, min(vertical_velocity[i] / velocity[i], 1))
angle.append(asin(ratio))
angle = savgol_filter(angle, 5, 1)
if interp:
angle = savgol_filter(angle, 11, 1)
return ss.medfilt(angle, kernel_size=7)
return angle
示例11: ypr_from_campos
# 需要導入模塊: import math [as 別名]
# 或者: from math import asin [as 別名]
def ypr_from_campos(cx, cy, cz):
camDist = math.sqrt(cx * cx + cy * cy + cz * cz)
cx = cx / camDist
cy = cy / camDist
cz = cz / camDist
t = math.sqrt(cx * cx + cy * cy)
tx = cx / t
ty = cy / t
yaw = math.acos(tx)
if ty > 0:
yaw = 2 * math.pi - yaw
roll = 0
pitch = math.asin(cz)
return yaw, pitch, roll
示例12: coord_distance
# 需要導入模塊: import math [as 別名]
# 或者: from math import asin [as 別名]
def coord_distance(lat1, lon1, lat2, lon2):
"""
Finds the distance between two pairs of latitude and longitude.
:param lat1: Point 1 latitude.
:param lon1: Point 1 longitude.
:param lat2: Point two latitude.
:param lon2: Point two longitude.
:return: Kilometer distance.
"""
lon1, lat1, lon2, lat2 = map(math.radians, [lon1, lat1, lon2, lat2])
dlon = lon2 - lon1
dlat = lat2 - lat1
a = math.sin(dlat/2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon/2)**2
c = 2 * math.asin(math.sqrt(a))
km = 6367 * c
return km
示例13: new_color_pref
# 需要導入模塊: import math [as 別名]
# 或者: from math import asin [as 別名]
def new_color_pref(old_pref, env_color):
"""
Calculate new color pref with the formula below:
new_color = sin(avg(asin(old_pref) + asin(env_color)))
"""
me = math.asin(old_pref)
env = math.asin(env_color)
avg = np.average([me, env], weights=weightings)
new_color = math.sin(avg)
return new_color
示例14: latlngup_to_relxyz
# 需要導入模塊: import math [as 別名]
# 或者: from math import asin [as 別名]
def latlngup_to_relxyz(c,l):
# this converts WGS84 (lat,lng,alt) to a rotated ECEF frame
# where the earth center is still at the origin
# but (clat,clng,calt) has been rotated to lie on the positive X axis
clat,clng,calt = c
llat,llng,lalt = l
# rotate by -clng around Z to put C on the X/Z plane
# (this is easy to do while still in WGS84 coordinates)
llng = llng - clng
# find angle between XY plane and C
cx,cy,cz = latlngup_to_ecef((clat,0,calt))
a = math.atan2(cz,cx)
# convert L to (rotated around Z) ECEF
lx,ly,lz = latlngup_to_ecef((llat,llng,lalt))
# rotate by -a around Y to put C on the X axis
asin = math.sin(-a)
acos = math.cos(-a)
rx = lx * acos - lz * asin
rz = lx * asin + lz * acos
return (rx, ly, rz)
# calculate range, bearing, elevation from C to L
示例15: range_bearing_elevation
# 需要導入模塊: import math [as 別名]
# 或者: from math import asin [as 別名]
def range_bearing_elevation(c,l):
# rotate C onto X axis
crx, cry, crz = latlngup_to_relxyz(c,c)
# rotate L in the same way
lrx, lry, lrz = latlngup_to_relxyz(c,l)
# Now we have cartesian coordinates with C on
# the X axis with ground plane YZ and north along +Z.
dx, dy, dz = lrx-crx, lry-cry, lrz-crz
rng = math.sqrt(dx*dx + dy*dy + dz*dz)
bearing = (360 + 90 - rtod(math.atan2(dz,dy))) % 360
elev = rtod(math.asin(dx / rng))
return (rng, bearing, elev)