本文整理汇总了Python中math.acos方法的典型用法代码示例。如果您正苦于以下问题:Python math.acos方法的具体用法?Python math.acos怎么用?Python math.acos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类math
的用法示例。
在下文中一共展示了math.acos方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_angle_diff
# 需要导入模块: import math [as 别名]
# 或者: from math import acos [as 别名]
def get_angle_diff(self, target, result):
size = target.size()
sequence_length = size[1]
all_averages = np.zeros((sequence_length)).astype(np.float)
for seq_id in range(sequence_length):
average = AverageMeter()
for batch_id in range(size[0]):
for imu_id in range(size[2]):
goal = Quaternion(target[batch_id, seq_id, imu_id])
out = Quaternion(result[batch_id, seq_id, imu_id])
acos = (2 * (np.dot(out.normalised.q, goal.normalised.q)**2)
- 1)
acos = round(acos, 6)
if acos > 1 or acos < -1:
pdb.set_trace()
radian = math.acos(acos)
average.update(radian)
all_averages[seq_id] = (average.avg)
return all_averages
示例2: c2s
# 需要导入模块: import math [as 别名]
# 或者: from math import acos [as 别名]
def c2s(self):
R = self.dist(point(0, 0, 0))
lg = math.atan(self.y / self.x)
lat = acos(self.z / R)
return (lg, lat, R)
# ~ def transform(self,p1,p2):
# ~ if isinstance(p2,point):
# ~ v=vec(p1,p2)
# ~ rot=v.angle()
# ~ return self.transform(p1,rot)
# ~ else:
# ~ temp=self-p1
# ~ rot=p2
# ~ px=math.cos(rot)*temp.x+math.sin(rot)*temp.y
# ~ py=-math.sin(rot)*temp.x+math.cos(rot)*temp.y
# ~ return point(px,py)
示例3: map
# 需要导入模块: import math [as 别名]
# 或者: from math import acos [as 别名]
def map(self, p, inv=False):
# cartesian to lat/lon
# if inv is true lat/lon to cartesian
R = self.R
if not inv:
ed = R * (vec(p - self.c).norm())
ed = point(ed.dx, ed.dy, ed.dz)
lon = math.atan2(ed.y, ed.x)
lat1 = math.acos(abs(ed.z) / R)
if ed.z > 0:
lat = math.pi / 2 - lat1
else:
lat = -(math.pi / 2 - lat1)
return point(lon, lat) * 180 / math.pi
if inv:
p = p * math.pi / 180
z = R * math.sin(p.y)
y = R * math.cos(p.y) * math.sin(p.x)
x = R * math.cos(p.y) * math.cos(p.x)
return point(x, y, z)
示例4: theta_phi_to_dzeta_gamma
# 需要导入模块: import math [as 别名]
# 或者: from math import acos [as 别名]
def theta_phi_to_dzeta_gamma(theta, phi, z):
"""Calculation of the angles dzeta and gamma."""
dzeta = theta
if ((math.cos(z) * math.cos(theta) + math.sin(z) * math.sin(theta) *
math.cos(phi)) > 1 and (math.cos(z) * math.cos(theta) + math.sin(z) *
math.sin(theta) * math.cos(phi) < 1.1)):
gamma = 0
elif math.cos(z) * math.cos(theta) + math.sin(z) * math.sin(theta) * \
math.cos(phi) > 1.1:
raise ValueError("error in calculation of gamma (angle between point and sun)")
else:
gamma = math.acos(math.cos(z) * math.cos(theta) + math.sin(z) *
math.sin(theta) * math.cos(phi))
return dzeta, gamma
示例5: vector_angle_between
# 需要导入模块: import math [as 别名]
# 或者: from math import acos [as 别名]
def vector_angle_between(vector1, vector2, **kwargs):
""" Computes the angle between the two input vectors.
If the keyword argument ``degrees`` is set to *True*, then the angle will be in degrees. Otherwise, it will be
in radians. By default, ``degrees`` is set to *True*.
:param vector1: vector
:type vector1: list, tuple
:param vector2: vector
:type vector2: list, tuple
:return: angle between the vectors
:rtype: float
"""
degrees = kwargs.get('degrees', True)
magn1 = vector_magnitude(vector1)
magn2 = vector_magnitude(vector2)
acos_val = vector_dot(vector1, vector2) / (magn1 * magn2)
angle_radians = math.acos(acos_val)
if degrees:
return math.degrees(angle_radians)
else:
return angle_radians
示例6: sunset_hour_angle
# 需要导入模块: import math [as 别名]
# 或者: from math import acos [as 别名]
def sunset_hour_angle(latitude, sol_dec):
"""
Calculate sunset hour angle (*Ws*) from latitude and solar
declination.
Based on FAO equation 25 in Allen et al (1998).
:param latitude: Latitude [radians]. Note: *latitude* should be negative
if it in the southern hemisphere, positive if in the northern
hemisphere.
:param sol_dec: Solar declination [radians]. Can be calculated using
``sol_dec()``.
:return: Sunset hour angle [radians].
:rtype: float
"""
_check_latitude_rad(latitude)
_check_sol_dec_rad(sol_dec)
cos_sha = -math.tan(latitude) * math.tan(sol_dec)
# If tmp is >= 1 there is no sunset, i.e. 24 hours of daylight
# If tmp is <= 1 there is no sunrise, i.e. 24 hours of darkness
# See http://www.itacanet.org/the-sun-as-a-source-of-energy/
# part-3-calculating-solar-angles/
# Domain of acos is -1 <= x <= 1 radians (this is not mentioned in FAO-56!)
return math.acos(min(max(cos_sha, -1.0), 1.0))
示例7: re
# 需要导入模块: import math [as 别名]
# 或者: from math import acos [as 别名]
def re(R_est, R_gt):
"""Rotational Error.
:param R_est: 3x3 ndarray with the estimated rotation matrix.
:param R_gt: 3x3 ndarray with the ground-truth rotation matrix.
:return: The calculated error.
"""
assert (R_est.shape == R_gt.shape == (3, 3))
error_cos = float(0.5 * (np.trace(R_est.dot(np.linalg.inv(R_gt))) - 1.0))
# Avoid invalid values due to numerical errors.
error_cos = min(1.0, max(-1.0, error_cos))
error = math.acos(error_cos)
error = 180.0 * error / np.pi # Convert [rad] to [deg].
return error
示例8: trig
# 需要导入模块: import math [as 别名]
# 或者: from math import acos [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)
示例9: spherical_cartesian_to_polar
# 需要导入模块: import math [as 别名]
# 或者: from math import acos [as 别名]
def spherical_cartesian_to_polar(vec):
'''
Return a parameterization of a vector of 3 coordinates:
x = r sin u cos v
y = r sin u sin v
z = r cos u
0 <= u <= pi
-pi <= v <= pi
Where u is the polar angle and v is the azimuth angle.
@param vec: A vector of 3 cartesian coordinates.
@return: (r, u, v)
'''
r = magnitude(vec)
u = m.acos(vec[2] / r)
v = m.atan2(vec[1], vec[0])
nt.assert_allclose(vec[0], r * m.sin(u) * m.cos(v), rtol=1e-7, atol=1e-7)
return (r, u, v)
示例10: ccw
# 需要导入模块: import math [as 别名]
# 或者: from math import acos [as 别名]
def ccw(self,p0,p1,c):
# Return 1 if p1 is counterclockwise from p0 with c as center; otherwise, return 0
cx = c[0]
cy = c[1]
v0 = (p0.x-cx,p0.y-cy)
v1 = (p1.x-cx,p1.y-cy)
d0 = enorm(v0[0],v0[1])
d1 = enorm(v1[0],v1[1])
dp = (v0[0]*v1[0]) + (v0[1]*v1[1])
if d0*d1 == 0:
return 0
q = clamp(dp/exclus(d0*d1),-1,1)
ang = math.acos(q)
if ang >= 0:
return 1
else:
return 0
示例11: check_order
# 需要导入模块: import math [as 别名]
# 或者: from math import acos [as 别名]
def check_order(self, x1, y1, x2, y2, x3, y3, x4, y4):
"""
makes sure that quadrilateral has order 1-2-4-3
calculates angles around
"""
def angle(v1, v2):
v1_l = np.sqrt(v1[0] ** 2 + v1[1] ** 2)
v2_l = np.sqrt(v2[0] ** 2 + v2[1] ** 2)
return math.acos(np.dot(v1, v2) / (v1_l * v2_l))
v21 = np.array([x2 - x1, y2 - y1])
v42 = np.array([x4 - x2, y4 - y2])
v34 = np.array([x3 - x4, y3 - y4])
v13 = np.array([x1 - x3, y1 - y3])
angle_1 = angle(v21, -v42)
angle_2 = angle(v42, -v34)
angle_3 = angle(v34, -v13)
angle_4 = angle(v13, -v21)
#print (angle_1 + angle_2 + angle_3 + angle_4)
if abs((angle_1 + angle_2 + angle_3 + angle_4) - 2 * math.pi) < 1e-9:
return x1, y1, x2, y2, x3, y3, x4, y4
else:
return x1, y1, x2, y2, x4, y4, x3, y3
示例12: testAcosFunction
# 需要导入模块: import math [as 别名]
# 或者: from math import acos [as 别名]
def testAcosFunction(self):
ma5 = MovingAverage(5, 'close')
holder = Acos(ma5)
sampleClose = np.cos(self.sampleClose)
for i, close in enumerate(sampleClose):
data = {'close': close}
ma5.push(data)
holder.push(data)
expected = math.acos(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))
示例13: slerp
# 需要导入模块: import math [as 别名]
# 或者: from math import acos [as 别名]
def slerp(quaternion1, quaternion2, amount):
num = amount
num2 = 0.0
num3 = 0.0
num4 = np.dot(quaternion1, quaternion2)
flag = False
if num4 < 0.0:
flag = True
num4 = -num4
if num4 > 0.999999:
num3 = 1.0 - num
num2 = -num if flag else num
else:
num5 = math.acos(num4)
num6 = 1.0 / math.sin(num5)
num3 = math.sin((1.0 - num) * num5) * num6
num2 = (-math.sin(num * num5) * num6) if flag else (math.sin(num * num5) * num6)
return (num3 * quaternion1) + (num2 * quaternion2)
示例14: quat_slerp
# 需要导入模块: import math [as 别名]
# 或者: from math import acos [as 别名]
def quat_slerp(quat0, quat1, fraction, spin=0, shortestpath=True):
"""Return spherical linear interpolation between two quaternions.
>>> q0 = random_quat()
>>> q1 = random_quat()
>>> q = quat_slerp(q0, q1, 0.0)
>>> np.allclose(q, q0)
True
>>> q = quat_slerp(q0, q1, 1.0, 1)
>>> np.allclose(q, q1)
True
>>> q = quat_slerp(q0, q1, 0.5)
>>> angle = math.acos(np.dot(q0, q))
>>> np.allclose(2.0, math.acos(np.dot(q0, q1)) / angle) or \
np.allclose(2.0, math.acos(-np.dot(q0, q1)) / angle)
True
"""
q0 = unit_vector(quat0[:4])
q1 = unit_vector(quat1[:4])
if fraction == 0.0:
return q0
elif fraction == 1.0:
return q1
d = np.dot(q0, q1)
if abs(abs(d) - 1.0) < _EPS:
return q0
if shortestpath and d < 0.0:
# invert rotation
d = -d
q1 *= -1.0
angle = math.acos(d) + spin * math.pi
if abs(angle) < _EPS:
return q0
isin = 1.0 / math.sin(angle)
q0 *= math.sin((1.0 - fraction) * angle) * isin
q1 *= math.sin(fraction * angle) * isin
q0 += q1
return q0
示例15: getAngle
# 需要导入模块: import math [as 别名]
# 或者: from math import acos [as 别名]
def getAngle(Ps, Pt, DD):
Q = np.hstack((Ps, scipy.linalg.null_space(Ps.T)))
dim = Pt.shape[1]
QPt = Q.T @ Pt
A, B = QPt[:dim, :], QPt[dim:, :]
U,V,X,C,S = gsvd(A, B)
alpha = np.zeros([1, DD])
for i in range(DD):
alpha[0][i] = math.sin(np.real(math.acos(C[i][i]*math.pi/180)))
return alpha