# Python math.asin() Examples

The following are 30 code examples for showing how to use math.asin(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module , or try the search function .

Example 1
 Project: SpaceXtract   Author: shahar603   File: analyse_raw_telemetry.py    License: MIT License 7 votes  ```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 ```
Example 2
 Project: AboveTustin   Author: kevinabrandon   File: geomath.py    License: MIT License 6 votes  ```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, pointA, pointB, pointB])

# 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 ```
Example 3
 Project: Localization   Author: kamalshadi   File: geometry.py    License: MIT License 6 votes  ```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 ```
Example 4
 Project: honeybee   Author: ladybug-tools   File: euclid.py    License: GNU General Public License v3.0 6 votes  ```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 ```
Example 5
 Project: renpy-shader   Author: bitsawer   File: euclid.py    License: MIT License 6 votes  ```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 ```
Example 6
 Project: pyth   Author: isaacg1   File: macros.py    License: MIT License 6 votes  ```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) ```
Example 7
 Project: orbit-predictor   Author: satellogic   File: locations.py    License: MIT License 6 votes  ```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 - observer_pos_ecef
ry = object_coords_ecef - observer_pos_ecef
rz = object_coords_ecef - observer_pos_ecef

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) ```
Example 8
 Project: apls   Author: CosmiQ   File: apls_utils.py    License: Apache License 2.0 6 votes  ```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

############################################################################### ```
Example 9
 Project: Finance-Python   Author: alpha-miner   File: testAccumulatorsArithmetic.py    License: MIT License 6 votes  ```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)) ```
Example 10
 Project: DragonFF   Author: Parik27   File: dff_importer.py    License: GNU General Public License v3.0 6 votes  ```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

####################################################### ```
Example 11
 Project: vrProjector   Author: bhautikj   File: SideBySideFisheyeProjection.py    License: Apache License 2.0 6 votes  ```def angular_position(texcoord):
up = texcoord
v = texcoord
# 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) ```
Example 12
 Project: differentiable-point-clouds   Author: eldar   File: euler.py    License: MIT License 6 votes  ```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 ```
Example 13
 Project: apartment-finder   Author: VikParuchuri   File: util.py    License: MIT License 6 votes  ```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 ```
Example 14
 Project: indras_net   Author: gcallah   File: fashion.py    License: GNU General Public License v3.0 5 votes  ```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 ```
Example 15
 Project: dump1090-tools   Author: mutability   File: adsb-polar.py    License: ISC License 5 votes  ```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 ```
Example 16
 Project: dump1090-tools   Author: mutability   File: adsb-polar.py    License: ISC License 5 votes  ```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) ```
Example 17
 Project: dump1090-tools   Author: mutability   File: adsb-polar-2.py    License: ISC License 5 votes  ```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)

# great circle distance from C to L, assuming spherical geometry (~0.3% error)
# from http://www.movable-type.co.uk/scripts/latlong.html ("haversine formula") ```
Example 18
 Project: dump1090-tools   Author: mutability   File: adsb-polar-2.py    License: ISC License 5 votes  ```def range_bearing_elevation_from(c):
# build a function that calculates ranges, bearing, elevation from C
clat,clng,calt = c

# rotate by -clng to put C on the XZ plane
# find angle between XY plane and C
cx,cy,cz = latlngup_to_ecef((clat,0,calt))
a = math.atan2(cz,cx)

# rotate by -a around Y to put C on the X axis
asin = math.sin(-a)
acos = math.cos(-a)

crx = cx * acos - cz * asin
cry = cy                         # should be zero
crz = cx * asin + cz * acos      # should be zero

def rbe(l):
# rotate L into our new reference frame
llat,llng,lalt = l
# rotate by -clng, convert to ECEF
lx,ly,lz = latlngup_to_ecef((llat,llng - clng,lalt))

# rotate by -a around Y
lrx = lx * acos - lz * asin
lry = ly
lrz = lx * asin + lz * acos

# Now we have cartesian coordinates with C on
# the +X axis, ground plane YZ, north along +Z.

dx, dy, dz = lrx-crx, lry-cry, lrz-crz
slant = math.sqrt(dx*dx + dy*dy + dz*dz)             # true line-of-sight range
bearing = (360 + 90 - rtod(math.atan2(dz,dy))) % 360 # bearing around X axis
elev = rtod(math.asin(dx / slant))                   # elevation from horizon (YZ plane)
horiz_range = math.sqrt(dy*dy + dz*dz)               # distance projected onto YZ (ground/horizon plane); something like ground distance if the Earth was flat
return (slant, horiz_range, bearing, elev, (lrx,lry,lrz))

return rbe

# calculate true range, bearing, elevation from C to L ```
Example 19
 Project: dump1090-tools   Author: mutability   File: adsb-polar-2.py    License: ISC License 5 votes  ```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, ground plane YZ, north along +Z.

dx, dy, dz = lrx-crx, lry-cry, lrz-crz
slant = math.sqrt(dx*dx + dy*dy + dz*dz)             # true line-of-sight range
bearing = (360 + 90 - rtod(math.atan2(dz,dy))) % 360 # bearing around X axis
elev = rtod(math.asin(dx / slant))                   # elevation from horizon (YZ plane)
horiz_range = math.sqrt(dy*dy + dz*dz)               # distance projected onto YZ (ground/horizon plane); something like ground distance if the Earth was flat
return (slant, horiz_range, bearing, elev, (lrx,lry,lrz)) ```
Example 20
 Project: quadcopter-simulation   Author: hbd730   File: utils.py    License: BSD 3-Clause "New" or "Revised" License 5 votes  ```def RotToRPY(R):
phi = asin(R[1,2])
theta = atan2(-R[0,2]/cos(phi),R[2,2]/cos(phi))
psi = atan2(-R[1,0]/cos(phi),R[1,1]/cos(phi))
return phi, theta, psi ```
Example 21
 Project: suncalcPy   Author: Broham   File: suncalc.py    License: MIT License 5 votes  ```def declination(l, b):
return asin(sin(b) * cos(e) + cos(b) * sin(e) * sin(l)) ```
Example 22
 Project: suncalcPy   Author: Broham   File: suncalc.py    License: MIT License 5 votes  ```def altitude(H, phi, dec):
return asin(sin(phi) * sin(dec) + cos(phi) * cos(dec) * cos(H)) ```
Example 23
 Project: chainer-gqn   Author: musyoku   File: functions.py    License: MIT License 5 votes  ```def compute_yaw_and_pitch(vec):
x, y, z = vec
norm = np.linalg.norm(vec)
if z < 0:
yaw = math.pi + math.atan(x / z)
elif x < 0:
yaw = math.pi * 2 + math.atan(x / z)
else:
yaw = math.atan(x / z)
pitch = -math.asin(y / norm)
return yaw, pitch ```
Example 24
 Project: chainer-gqn   Author: musyoku   File: functions.py    License: MIT License 5 votes  ```def compute_yaw_and_pitch(vec):
x, y, z = vec
norm = np.linalg.norm(vec)
if z < 0:
yaw = math.pi + math.atan(x / z)
elif x < 0:
yaw = math.pi * 2 + math.atan(x / z)
else:
yaw = math.atan(x / z)
pitch = -math.asin(y / norm)
return yaw, pitch ```
Example 25
 Project: chainer-gqn   Author: musyoku   File: functions.py    License: MIT License 5 votes  ```def compute_yaw_and_pitch(vec):
x, y, z = vec
norm = np.linalg.norm(vec)
if z < 0:
yaw = math.pi + math.atan(x / z)
elif x < 0:
yaw = math.pi * 2 + math.atan(x / z)
else:
yaw = math.atan(x / z)
pitch = -math.asin(y / norm)
return yaw, pitch ```
Example 26
 Project: me-ica   Author: ME-ICA   File: test_euler.py    License: GNU Lesser General Public License v2.1 5 votes  ```def crude_mat2euler(M):
''' The simplest possible - ignoring atan2 instability '''
r11, r12, r13, r21, r22, r23, r31, r32, r33 = M.flat
return math.atan2(-r12, r11), math.asin(r13), math.atan2(-r23, r33) ```
Example 27
 Project: hadrian   Author: modelop   File: pfamath.py    License: Apache License 2.0 5 votes  ```def __call__(self, state, scope, pos, paramTypes, x):
try:
return math.asin(x)
except ValueError:
return float("nan") ```
Example 28
 Project: simnibs   Author: simnibs   File: sphere.py    License: GNU General Public License v3.0 5 votes  ```def fibonacci_sphere(nr_points, R=1):
""" Creates N points around evenly spread through a unit sphere

Parameters
------------------------------
nr_points: int
number of points to be spread, must be odd
R: float
radius of sphere

Returns
------------------------------
Nx3 ndarray
Array with the points
"""
assert nr_points % 2 == 1, "The number of points must be odd"
points = []
# The golden ratio
phi = (1 + math.sqrt(5)) / 2.
N = int((nr_points - 1)/2)
for i in range(-N, N+1):
lat = math.asin(2 * i / nr_points)
lon = 2 * math.pi * i / phi
x = R * math.cos(lat) * math.cos(lon)
y = R * math.cos(lat) * math.sin(lon)
z = R * math.sin(lat)
points.append((x, y, z))
return np.array(points, dtype = float) ```
Example 29
 Project: simnibs   Author: simnibs   File: sphere.py    License: GNU General Public License v3.0 5 votes  ```def fibonacci_sphere(nr_points, R=1):
""" Creates N points around evenly spread through a unit sphere

Parameters
------------------------------
nr_points: int
number of points to be spread, must be odd
R: float
radius of sphere

Returns
------------------------------
Nx3 ndarray
Array with the points
"""
assert nr_points % 2 == 1, "The number of points must be odd"
points = []
# The golden ratio
phi = (1 + math.sqrt(5)) / 2.
N = int((nr_points - 1)/2)
for i in range(-N, N+1):
lat = math.asin(2 * i / nr_points)
lon = 2 * math.pi * i / phi
x = R * math.cos(lat) * math.cos(lon)
y = R * math.cos(lat) * math.sin(lon)
z = R * math.sin(lat)
points.append((x, y, z))
return np.array(points, dtype = float) ```
Example 30
 Project: sphere   Author: qedus   File: sphere.py    License: MIT License 5 votes  ```def angle(self):
if self.is_empty():
return Angle.from_radians(-1)
return Angle.from_radians(2 * math.asin(math.sqrt(0.5 * self.height()))) ```