本文整理匯總了Python中math.radians方法的典型用法代碼示例。如果您正苦於以下問題:Python math.radians方法的具體用法?Python math.radians怎麽用?Python math.radians使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類math
的用法示例。
在下文中一共展示了math.radians方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: distance
# 需要導入模塊: import math [as 別名]
# 或者: from math import radians [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: _startImageCapturingAtGraphNode
# 需要導入模塊: import math [as 別名]
# 或者: from math import radians [as 別名]
def _startImageCapturingAtGraphNode(self):
amntY = 0.3
xdir = [-0.5, 0, 0.5]
cameraId = 0
for idx,amntX in enumerate(xdir):
self._moveHead(amntX, amntY)
time.sleep(0.1)
self._checkIfAsthamaInEnvironment(cameraId)
if self.pumpFound :
# Setting rotation angle of body towards head
theta = 0
if idx == 0: # LEFT
theta = math.radians(-45)
if idx == 2: # RIGHT
theta = math.radians(45)
self.pumpAngleRotation = theta
return "KILLING GRAPH SEARCH : PUMP FOUND"
self._moveHead(0, 0) # Bringing to initial view
return
示例3: distance
# 需要導入模塊: import math [as 別名]
# 或者: from math import radians [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
示例4: rotate_bbox
# 需要導入模塊: import math [as 別名]
# 或者: from math import radians [as 別名]
def rotate_bbox(box, a):
'''Rotate a bounding box 4-tuple by an angle in degrees'''
corners = ( (box[0], box[1]), (box[0], box[3]), (box[2], box[3]), (box[2], box[1]) )
a = -math.radians(a)
sa = math.sin(a)
ca = math.cos(a)
rot = []
for p in corners:
rx = p[0]*ca + p[1]*sa
ry = -p[0]*sa + p[1]*ca
rot.append((rx,ry))
# Find the extrema of the rotated points
rot = list(zip(*rot))
rx0 = min(rot[0])
rx1 = max(rot[0])
ry0 = min(rot[1])
ry1 = max(rot[1])
#print('## RBB:', box, rot)
return (rx0, ry0, rx1, ry1)
示例5: draw_marker
# 需要導入模塊: import math [as 別名]
# 或者: from math import radians [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()
示例6: update
# 需要導入模塊: import math [as 別名]
# 或者: from math import radians [as 別名]
def update(self):
radians = math.radians(self.direction)
self.x += self.speed * math.sin(radians)
self.y -= self.speed * math.cos(radians)
# Update ball position
self.rect.x = self.x
self.rect.y = self.y
if self.y <= self.top_edge:
self.direction = (180-self.direction) % 360
self.sound.edge_sound.play()
if self.y > self.bottom_edge - 1*self.height:
self.direction = (180-self.direction) % 360
self.sound.edge_sound.play()
示例7: gcd
# 需要導入模塊: import math [as 別名]
# 或者: from math import radians [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
示例8: to_quaternion
# 需要導入模塊: import math [as 別名]
# 或者: from math import radians [as 別名]
def to_quaternion(roll = 0.0, pitch = 0.0, yaw = 0.0):
"""
Convert degrees to quaternions
"""
t0 = math.cos(math.radians(yaw * 0.5))
t1 = math.sin(math.radians(yaw * 0.5))
t2 = math.cos(math.radians(roll * 0.5))
t3 = math.sin(math.radians(roll * 0.5))
t4 = math.cos(math.radians(pitch * 0.5))
t5 = math.sin(math.radians(pitch * 0.5))
w = t0 * t2 * t4 + t1 * t3 * t5
x = t0 * t3 * t4 - t1 * t2 * t5
y = t0 * t2 * t5 + t1 * t3 * t4
z = t1 * t2 * t4 - t0 * t3 * t5
return [w, x, y, z]
# Take off 2.5m in GUIDED_NOGPS mode.
示例9: contains
# 需要導入模塊: import math [as 別名]
# 或者: from math import radians [as 別名]
def contains(self, *args):
if isinstance(args[0], Point):
point = args[0]
return self.contains(LatLon.from_point(point))
elif isinstance(args[0], LatLon):
ll = args[0]
assert ll.is_valid()
return self.lat().contains(ll.lat().radians) \
and self.lon().contains(ll.lon().radians)
elif isinstance(args[0], self.__class__):
other = args[0]
return self.lat().contains(other.lat()) \
and self.lon().contains(other.lon())
elif isinstance(args[0], Cell):
cell = args[0]
return self.contains(cell.get_rect_bound())
else:
raise NotImplementedError()
示例10: _set_lighting
# 需要導入模塊: import math [as 別名]
# 或者: from math import radians [as 別名]
def _set_lighting(self):
# Create new lamp datablock
light_data = bpy.data.lamps.new(name="New Lamp", type='HEMI')
# Create new object with our lamp datablock
light_2 = bpy.data.objects.new(name="New Lamp", object_data=light_data)
bpy.context.scene.objects.link(light_2)
# put the light behind the camera. Reduce specular lighting
self.light.location = (0, -2, 2)
self.light.rotation_mode = 'ZXY'
self.light.rotation_euler = (radians(45), 0, radians(90))
self.light.data.energy = 0.7
light_2.location = (0, 2, 2)
light_2.rotation_mode = 'ZXY'
light_2.rotation_euler = (-radians(45), 0, radians(90))
light_2.data.energy = 0.7
示例11: __init__
# 需要導入模塊: import math [as 別名]
# 或者: from math import radians [as 別名]
def __init__(self, name=None, origin=(0, 0, 0), width=3.0, depth=6.0, height=3.2,
rotation_angle=0):
"""Init room."""
self._width = float(width) or 3.0
self._depth = float(depth) or 6.0
self._height = float(height) or 3.2
self._rotation_angle = float(rotation_angle) or 0.0
self._z_axis = Vector3(0, 0, 1)
self._x_axis = Vector3(1, 0, 0).rotate_around(
self._z_axis, math.radians(rotation_angle))
self._y_axis = Vector3(0, 1, 0).rotate_around(
self._z_axis, math.radians(rotation_angle))
name = name or 'room'
origin = Point3(*tuple(origin)) if origin else Point3(0, 0, 0)
# setting up origin will initiate recalculation of room
HBZone.__init__(self, name, origin)
示例12: _get_affine_matrix
# 需要導入模塊: import math [as 別名]
# 或者: from math import radians [as 別名]
def _get_affine_matrix(center, angle, translate, scale, shear):
# Helper method to compute matrix for affine transformation
# We need compute affine transformation matrix: M = T * C * RSS * C^-1
# where T is translation matrix: [1, 0, tx | 0, 1, ty | 0, 0, 1]
# C is translation matrix to keep center: [1, 0, cx | 0, 1, cy | 0, 0, 1]
# RSS is rotation with scale and shear matrix
# RSS(a, scale, shear) = [ cos(a)*scale -sin(a + shear)*scale 0]
# [ sin(a)*scale cos(a + shear)*scale 0]
# [ 0 0 1]
angle = math.radians(angle)
shear = math.radians(shear)
# scale = 1.0 / scale
T = np.array([[1, 0, translate[0]], [0, 1, translate[1]], [0,0,1]])
C = np.array([[1, 0, center[0]], [0, 1, center[1]], [0,0,1]])
RSS = np.array([[math.cos(angle)*scale, -math.sin(angle+shear)*scale, 0],
[math.sin(angle)*scale, math.cos(angle+shear)*scale, 0],
[0,0,1]])
matrix = T @ C @ RSS @ np.linalg.inv(C)
return matrix[:2,:]
示例13: pointOnCircle
# 需要導入模塊: import math [as 別名]
# 或者: from math import radians [as 別名]
def pointOnCircle(cx, cy, radius, angle):
"""
Calculates the coordinates of a point on a circle given the center point,
radius, and angle.
"""
angle = math.radians(angle) - (math.pi / 2)
x = cx + radius * math.cos(angle)
if x < cx:
x = math.ceil(x)
else:
x = math.floor(x)
y = cy + radius * math.sin(angle)
if y < cy:
y = math.ceil(y)
else:
y = math.floor(y)
return (int(x), int(y))
示例14: _get_affine_matrix
# 需要導入模塊: import math [as 別名]
# 或者: from math import radians [as 別名]
def _get_affine_matrix(center, angle, translate, scale, shear):
# Helper method to compute matrix for affine transformation
# We need compute affine transformation matrix: M = T * C * RSS * C^-1
# where T is translation matrix: [1, 0, tx | 0, 1, ty | 0, 0, 1]
# C is translation matrix to keep center: [1, 0, cx | 0, 1, cy | 0, 0, 1]
# RSS is rotation with scale and shear matrix
# RSS(a, scale, shear) = [ cos(a)*scale -sin(a + shear)*scale 0]
# [ sin(a)*scale cos(a + shear)*scale 0]
# [ 0 0 1]
angle = math.radians(angle)
shear = math.radians(shear)
# scale = 1.0 / scale
T = np.array([[1, 0, translate[0]], [0, 1, translate[1]], [0,0,1]])
C = np.array([[1, 0, center[0]], [0, 1, center[1]], [0,0,1]])
RSS = np.array([[math.cos(angle)*scale, -math.sin(angle+shear)*scale, 0],
[math.sin(angle)*scale, math.cos(angle+shear)*scale, 0],
[0,0,1]])
matrix = T @ C @ RSS @ np.linalg.inv(C)
return matrix[:2,:]
示例15: set_sailboat_heading
# 需要導入模塊: import math [as 別名]
# 或者: from math import radians [as 別名]
def set_sailboat_heading(pub_state):
global current_state
global current_sail
state_aux = ModelState()
quaternion = (current_state.pose.pose.orientation.x, current_state.pose.pose.orientation.y, current_state.pose.pose.orientation.z, current_state.pose.pose.orientation.w)
euler = tf.transformations.euler_from_quaternion(quaternion)
quaternion = tf.transformations.quaternion_from_euler(euler[0], euler[1], math.radians(current_heading))
state_aux.pose.orientation.x = quaternion[0]
state_aux.pose.orientation.y = quaternion[1]
state_aux.pose.orientation.z = quaternion[2]
state_aux.pose.orientation.w = quaternion[3]
state_aux.model_name = 'sailboat'
#state_aux.pose.position.x = current_state.pose.pose.position.x
#state_aux.pose.position.y = current_state.pose.pose.position.y
#state_aux.pose.position.z = current_state.pose.pose.position.z
#print(current_state)
state_aux.pose.position.x = 240
state_aux.pose.position.y = 95
state_aux.pose.position.z = 1
pub_state.publish(state_aux)