本文整理汇总了Python中math.atan2方法的典型用法代码示例。如果您正苦于以下问题:Python math.atan2方法的具体用法?Python math.atan2怎么用?Python math.atan2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类math
的用法示例。
在下文中一共展示了math.atan2方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: heading_between_points
# 需要导入模块: import math [as 别名]
# 或者: from math import atan2 [as 别名]
def heading_between_points(x1, y1, x2, y2):
"""Returns the angle between 2 points in degrees.
:param x1: x coordinate of point 1
:param y1: y coordinate of point 1
:param x2: x coordinate of point 2
:param y2: y coordinate of point 2
:return: angle in degrees
"""
def angle_trunc(a):
while a < 0.0:
a += math.pi * 2
return a
deltax = x2 - x1
deltay = y2 - y1
return math.degrees(angle_trunc(math.atan2(deltay, deltax)))
示例2: distance
# 需要导入模块: import math [as 别名]
# 或者: from math import atan2 [as 别名]
def distance(origin, destination):
"""Determine distance between 2 sets of [lat,lon] in km"""
lat1, lon1 = origin
lat2, lon2 = destination
radius = 6371 # km
dlat = math.radians(lat2 - lat1)
dlon = math.radians(lon2 - lon1)
a = (math.sin(dlat / 2) * math.sin(dlat / 2) +
math.cos(math.radians(lat1)) *
math.cos(math.radians(lat2)) * math.sin(dlon / 2) *
math.sin(dlon / 2))
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
d = radius * c
return d
示例3: _get_observation
# 需要导入模块: import math [as 别名]
# 或者: from math import atan2 [as 别名]
def _get_observation(self):
world_translation_minitaur, world_rotation_minitaur = (
self._pybullet_client.getBasePositionAndOrientation(
self.minitaur.quadruped))
world_translation_ball, world_rotation_ball = (
self._pybullet_client.getBasePositionAndOrientation(self._ball_id))
minitaur_translation_world, minitaur_rotation_world = (
self._pybullet_client.invertTransform(world_translation_minitaur,
world_rotation_minitaur))
minitaur_translation_ball, _ = (
self._pybullet_client.multiplyTransforms(minitaur_translation_world,
minitaur_rotation_world,
world_translation_ball,
world_rotation_ball))
distance = math.sqrt(minitaur_translation_ball[0]**2 +
minitaur_translation_ball[1]**2)
angle = math.atan2(minitaur_translation_ball[0],
minitaur_translation_ball[1])
self._observation = [angle - math.pi / 2, distance]
return self._observation
示例4: draw_marker
# 需要导入模块: import math [as 别名]
# 或者: from math import atan2 [as 别名]
def draw_marker(self, name, mp, tp, weight, c):
if name in self.markers:
m_shape, ref, orient, units = self.markers[name]
c.save()
c.translate(*mp)
if orient == 'auto':
angle = math.atan2(tp[1]-mp[1], tp[0]-mp[0])
c.rotate(angle)
elif isinstance(orient, int):
angle = math.radians(orient)
c.rotate(angle)
if units == 'stroke':
c.scale(weight, weight)
c.translate(-ref[0], -ref[1])
self.draw_shape(m_shape)
c.restore()
示例5: rotm2eul
# 需要导入模块: import math [as 别名]
# 或者: from math import atan2 [as 别名]
def rotm2eul(m):
""" m (3x3, rotation matrix) --> rotation m = Rz*Ry*Rx
"""
c = math.sqrt(R[0,0] * R[0,0] + R[1,0] * R[1,0])
singular = c < 1e-6
if not singular :
x = math.atan2(R[2,1] , R[2,2])
y = math.atan2(-R[2,0], c)
z = math.atan2(R[1,0], R[0,0])
else :
x = math.atan2(-R[1,2], R[1,1])
y = math.atan2(-R[2,0], c)
z = 0
return numpy.array([x, y, z])
#EOF
示例6: _ecg_simulate_derivsecgsyn
# 需要导入模块: import math [as 别名]
# 或者: from math import atan2 [as 别名]
def _ecg_simulate_derivsecgsyn(t, x, rr, ti, sfint, ai, bi):
ta = math.atan2(x[1], x[0])
r0 = 1
a0 = 1.0 - np.sqrt(x[0] ** 2 + x[1] ** 2) / r0
ip = np.floor(t * sfint).astype(int)
w0 = 2 * np.pi / rr[min(ip, len(rr) - 1)]
# w0 = 2*np.pi/rr[ip[ip <= np.max(rr)]]
fresp = 0.25
zbase = 0.005 * np.sin(2 * np.pi * fresp * t)
dx1dt = a0 * x[0] - w0 * x[1]
dx2dt = a0 * x[1] + w0 * x[0]
# matlab rem and numpy rem are different
# dti = np.remainder(ta - ti, 2*np.pi)
dti = (ta - ti) - np.round((ta - ti) / 2 / np.pi) * 2 * np.pi
dx3dt = -np.sum(ai * dti * np.exp(-0.5 * (dti / bi) ** 2)) - 1 * (x[2] - zbase)
dxdt = np.array([dx1dt, dx2dt, dx3dt])
return dxdt
示例7: map
# 需要导入模块: import math [as 别名]
# 或者: from math import atan2 [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)
示例8: get_euler
# 需要导入模块: import math [as 别名]
# 或者: from math import atan2 [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
示例9: addArrow
# 需要导入模块: import math [as 别名]
# 或者: from math import atan2 [as 别名]
def addArrow(self, painterPath, startX, startY, endX, endY):
"""Add arrows to the edges
http://kapo-cpp.blogspot.com/2008/10/drawing-arrows-with-cairo.html
"""
arrowLength = 12.0
arrowDegrees = 0.15 # Radian
angle = math.atan2(endY - startY, endX - startX) + math.pi
arrowX1 = endX + arrowLength * math.cos(angle - arrowDegrees)
arrowY1 = endY + arrowLength * math.sin(angle - arrowDegrees)
arrowX2 = endX + arrowLength * math.cos(angle + arrowDegrees)
arrowY2 = endY + arrowLength * math.sin(angle + arrowDegrees)
painterPath.moveTo(endX, endY)
painterPath.lineTo(arrowX1, arrowY1)
painterPath.moveTo(endX, endY)
painterPath.lineTo(arrowX2, arrowY2)
示例10: apply
# 需要导入模块: import math [as 别名]
# 或者: from math import atan2 [as 别名]
def apply(self, fish, state):
if state['closecount'] == 0:
return
center = state['center']
distance_to_center = dist(
center[0], center[1],
fish.position[0], fish.position[1]
)
if distance_to_center > self.parameters['threshold']:
angle_to_center = math.atan2(
fish.position[1] - center[1],
fish.position[0] - center[0]
)
fish.turnrate += (angle_to_center - fish.direction) / self.parameters['weight']
fish.speed += distance_to_center / self.parameters['speedfactor']
示例11: cairo_draw_arrow
# 需要导入模块: import math [as 别名]
# 或者: from math import atan2 [as 别名]
def cairo_draw_arrow(head, tail, fill, c):
width = c.get_line_width()
c.save()
dy = head[1] - tail[1]
dx = head[0] - tail[0]
angle = math.atan2(dy,dx)
c.translate(head[0],head[1])
c.rotate(angle)
c.scale(width, width)
# Now positioned to draw arrow at 0,0 with point facing right
apath = [(-4,0), (-4.5,2), (0,0)]
mirror = [(x,-y) for x, y in reversed(apath[1:-1])] # Mirror central points
apath.extend(mirror)
c.move_to(*apath[0])
for p in apath[1:]:
c.line_to(*p)
c.close_path()
c.set_source_rgba(*fill)
c.fill()
c.restore()
示例12: haversine_distance
# 需要导入模块: import math [as 别名]
# 或者: from math import atan2 [as 别名]
def haversine_distance(self, lat1, lon1, lat2, lon2):
R = 6371.0088
lat1 = math.radians(lat1)
lon1 = math.radians(lon1)
lat2 = math.radians(lat2)
lon2 = math.radians(lon2)
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.atan2(math.sqrt(a), math.sqrt(1 - a))
distance = R * c
return distance * 1000
示例13: angle
# 需要导入模块: import math [as 别名]
# 或者: from math import atan2 [as 别名]
def angle(a, b=None):
"""Angle between two items: 0 if b is above a, tau/4 if b is to the right of a...
If b is not supplied, this becomes the angle between (0, 0) and a."""
try:
ax, ay = a
except TypeError:
ax, ay = a.x(), a.y()
if b is None:
return _math.atan2(ax, -ay)
try:
bx, by = b
except TypeError:
bx, by = b.x(), b.y()
return _math.atan2(bx-ax, ay-by)
示例14: latlngup_to_relxyz
# 需要导入模块: import math [as 别名]
# 或者: from math import atan2 [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 atan2 [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)