def compute_pose_error(pose_A, pose_B):
"""
Compute the error norm of position and orientation.
"""
error_position = np.linalg.norm(pose_A[0:3] - pose_B[0:3], ord=2)
# Construct quaternions to compare.
quaternion_A = Quaternion(q=pose_A[3:7])
quaternion_A.normalize()
if quaternion_A.w < 0:
quaternion_A.q = -quaternion_A.q
quaternion_B = Quaternion(q=pose_B[3:7])
quaternion_B.normalize()
if quaternion_B.w < 0:
quaternion_B.q = -quaternion_B.q
# Sum up the square of the orientation angle error.
error_angle_rad = angle_between_quaternions(
quaternion_A, quaternion_B)
error_angle_degrees = math.degrees(error_angle_rad)
if error_angle_degrees > 180.0:
error_angle_degrees = math.fabs(360.0 - error_angle_degrees)
return (error_position, error_angle_degrees)
python类degrees()的实例源码
dual_quaternion_hand_eye_calibration.py 文件源码
项目:hand_eye_calibration
作者: ethz-asl
项目源码
文件源码
阅读 22
收藏 0
点赞 0
评论 0
def to_degrees(self):
"""
Set angle measurement units to degrees.
Convert the angles in this TorsionAngles instance to degrees.
"""
if self._units != AngleUnits.Degrees:
phi = TorsionAngles.deg(self._phi)
psi = TorsionAngles.deg(self._psi)
omega = TorsionAngles.deg(self._omega)
# if no ValueError is raised by TorsionAngles.check_angle in TorsionAngles.deg:
# (we assign directly to the instance variables to avoid check_angle being invoked again in setters)
self._phi, self._psi, self._omega = phi, psi, omega
self._units = AngleUnits.Degrees
def deg(angle):
"""
Convert a torsion angle value, expressed in radians, to degrees.
Negative angles are not accepted, it is assumed that negative torsion angles have been
converted to their ang+2pi counterparts beforehand.
Return the calculated value in the range of [-180, +180] degrees.
"""
TorsionAngles.check_angle(angle, AngleUnits.Radians)
if angle is not None:
if angle > math.pi:
angle = -((2. * math.pi) - angle)
angle = math.degrees(angle)
return angle
def draw_text(self, image, display_text, fnt, pos=(0,0),
colour=(0,0,255,255), rotate=False):
#draw text - (WARNING old versions of PIL have huge memory leak here!)
if display_text is None: return
self.log.info("MAP: writing text: pos: %s, text: %s"
% (pos, display_text))
if rotate:
txt = Image.new('RGBA', (fnt.getsize(display_text)),
self.transparent)
text = ImageDraw.Draw(txt)
# draw text rotated 180 degrees...
text.text((0,0), display_text, font=fnt, fill=colour)
image.paste(txt.rotate(180-self.angle, expand=True), pos)
else:
text = ImageDraw.Draw(image)
text.text(pos, display_text, font=fnt, fill=colour)
def radang(x, y):
'''return (radius, angle) of a vector(x, y)'''
if x == 0:
if y == 0:
return 0, 0
return abs(y), 90+180*(y<0)
if y == 0:
return abs(x), 180*(x<0)
r = math.sqrt(x*x+y*y)
a = math.degrees(math.atan(y/x))
if x < 0:
a += 180
elif y < 0:
a += 360
return r, a
def calcAzimuth(SatLon, SiteLat, SiteLon, Height_over_ocean = 0):
def rev(number):
return number - math.floor(number / 360.0) * 360
sinRadSiteLat = math.sin(math.radians(SiteLat))
cosRadSiteLat = math.cos(math.radians(SiteLat))
Rstation = r_eq / (math.sqrt(1 - f * (2 - f) * sinRadSiteLat **2))
Ra = (Rstation + Height_over_ocean) * cosRadSiteLat
Rz = Rstation * (1 - f) ** 2 * sinRadSiteLat
alfa_rx = r_sat * math.cos(math.radians(SatLon - SiteLon)) - Ra
alfa_ry = r_sat * math.sin(math.radians(SatLon - SiteLon))
alfa_rz = -Rz
alfa_r_north = -alfa_rx * sinRadSiteLat + alfa_rz * cosRadSiteLat
if alfa_r_north < 0:
Azimuth = 180 + math.degrees(math.atan(alfa_ry / alfa_r_north))
elif alfa_r_north > 0:
Azimuth = rev(360 + math.degrees(math.atan(alfa_ry / alfa_r_north)))
else:
Azimuth = 0
return Azimuth
def calcSatHourangle(SatLon, SiteLat, SiteLon):
Azimuth = calcAzimuth(SatLon, SiteLat, SiteLon )
Elevation = calcElevation(SatLon, SiteLat, SiteLon)
a = - math.cos(math.radians(Elevation)) * math.sin(math.radians(Azimuth))
b = math.sin(math.radians(Elevation)) * math.cos(math.radians(SiteLat)) - \
math.cos(math.radians(Elevation)) * math.sin(math.radians(SiteLat)) * \
math.cos(math.radians(Azimuth))
# Works for all azimuths (northern & southern hemisphere)
returnvalue = 180 + math.degrees(math.atan(a / b))
if Azimuth > 270:
returnvalue += 180
if returnvalue > 360:
returnvalue = 720 - returnvalue
if Azimuth < 90:
returnvalue = 180 - returnvalue
return returnvalue
def vector_direction_re_north(s, d):
"""
Make the source as the reference of the plan. Then compute atan2 of the resulting destination point
:param s: source point
:param d: destination point
:return: angle!
"""
# find the new coordinates of the destination point in a plan originated at source.
new_d_lon = d.lon - s.lon
new_d_lat = d.lat - s.lat
angle = -math.degrees(math.atan2(new_d_lat, new_d_lon)) + 90
# the following is required to move the degrees from -180, 180 to 0, 360
if angle < 0:
angle = angle + 360
return angle
def coords_down_bearing(lat, lon, bearing, distance, body):
'''
Takes a latitude, longitude and bearing in degrees, and a
distance in meters over a given body. Returns a tuple
(latitude, longitude) of the point you've calculated.
'''
bearing = math.radians(bearing)
R = body.equatorial_radius
lat = math.radians(lat)
lon = math.radians(lon)
lat2 = math.asin( math.sin(lat)*math.cos(distance/R) +
math.cos(lat)*math.sin(distance/R)*math.cos(bearing))
lon2 = lon + math.atan2(math.sin(bearing)*math.sin(distance/R
)*math.cos(lat),math.cos(distance/R)-math.sin(lat
)*math.sin(lat2))
lat2 = math.degrees(lat2)
lon2 = math.degrees(lon2)
return (lat2, lon2)
def heading_for_latlon(target, location):
lat1 = math.radians(location.lat)
lat2 = math.radians(target.lat)
diffLong = math.radians(target.lon - location.lon)
x = math.sin(diffLong) * math.cos(lat2)
y = math.cos(lat1) * math.sin(lat2) - (math.sin(lat1)
* math.cos(lat2) * math.cos(diffLong))
initial_bearing = math.atan2(x, y)
initial_bearing = math.degrees(initial_bearing)
compass_bearing = (initial_bearing + 360) % 360
return compass_bearing
def _set_equatorial(self, equatorial):
"""Set the value of the 3 element equatorial coordinate list [RA,Dec,Roll]
expects values in degrees
bounds are not checked
:param equatorial: list or array [ RA, Dec, Roll] in degrees
"""
att = np.array(equatorial)
ra, dec, roll = att#@UnusedVariable
self._ra0 = ra
if (ra > 180):
self._ra0 = ra - 360
self._roll0 = roll
if (roll > 180):
self._roll0 = roll - 360
self._equatorial = att
def angle(v1, v2, look): # FIXME pylint: disable=unused-argument
'''
Compute the unsigned angle between two vectors.
Returns a number between 0 and 180.
'''
import math
# TODO https://bodylabs.atlassian.net/projects/GEN/issues/GEN-1
# As pylint points out, we are not using `look` here. This method is
# supposed to be giving the angle between two vectors when viewed along a
# particular look vector, squashed into a plane. The code here is
# returning the angle in 3-space, which might be a reasonable function to
# have, but is not workable for computing the angle between planes as
# we're doing in bodylabs.measurement.anatomy.Angle.
dot = normalize(v1).dot(normalize(v2))
# Dot product sometimes slips past 1 or -1 due to rounding.
# Can't acos(-1.00001).
dot = max(min(dot, 1), -1)
return math.degrees(math.acos(dot))
def update(self, t, crazyflies):
if len(self.cfs) == 0:
verts, faces, normals, nothin = io.read_mesh(os.path.join(os.path.dirname(__file__), "crazyflie2.obj.gz"))
for i in range(0, len(crazyflies)):
mesh = scene.visuals.Mesh(vertices=verts, shading='smooth', faces=faces, parent=self.view.scene)
mesh.transform = transforms.MatrixTransform()
self.cfs.append(mesh)
for i in range(0, len(self.cfs)):
x, y, z = crazyflies[i].position()
roll, pitch, yaw = crazyflies[i].rpy()
self.cfs[i].transform.reset()
self.cfs[i].transform.rotate(90, (1, 0, 0))
self.cfs[i].transform.rotate(math.degrees(roll), (1, 0, 0))
self.cfs[i].transform.rotate(math.degrees(pitch), (0, 1, 0))
self.cfs[i].transform.rotate(math.degrees(yaw), (0, 0, 1))
self.cfs[i].transform.scale((0.001, 0.001, 0.001))
self.cfs[i].transform.translate((x, y, z))
self.canvas.app.process_events()
def get_sprite_rotation(self,sprite_name):
obj = bpy.data.objects[sprite_name]
euler_rot = obj.matrix_basis.to_euler()
degrees = math.degrees(euler_rot[1])
return -math.radians(degrees)
### convert windows slashes to linux slashes
def get_bone_angle(armature,bone,relative=True):
loc, rot, scale = get_bone_matrix(armature,bone,relative).decompose()
compat_euler = Euler((0.0,0.0,math.pi),"XYZ")
angle = -rot.to_euler().z # negate angle to fit dragonbones angle
return round(math.degrees(angle),2)
def declination(self):
"""Calculate declination of vector in degrees"""
return math.degrees(math.atan2(math.sqrt(self.x ** 2 + self.y ** 2), self.z))
def get_angle(origin, endpoint):
""" Returns the angle created by the line from origin to endpoint """
dx = endpoint.x - origin.x
dy = endpoint.y - origin.y
return math.degrees(math.atan2(dy, dx))
def angle(self):
"""The angle in degrees this line makes to the horizontal."""
(x1, y1), (x2, y2) = self
return math.degrees(math.atan2(y2 - y1, x2 - x1))
def getPitch():
x = accelerometer.get_x() / 1024
y = accelerometer.get_y() / 1024
z = accelerometer.get_z() / 1024
return math.degrees(math.atan(y/((math.sqrt(x**2 + z**2) if math.sqrt(x**2 + z**2) != 0 else 0.1))))
def __init__(self, config):
# general world configuration
self.config = config
# To derive the formula for calculating jump speed, first solve
# v_t = v_0 + a * t
# for the time at which you achieve maximum height, where a is the acceleration
# due to gravity and v_t = 0. This gives:
# t = - v_0 / a
# Use t and the desired MAX_JUMP_HEIGHT to solve for v_0 (jump speed) in
# s = s_0 + v_0 * t + (a * t^2) / 2
self.jump_speed = math.sqrt(2 * self.config['gravity'] * self.config['max_jump_height'])
# When flying gravity has no effect and speed is increased.
self.flying = False
# Strafing is moving lateral to the direction you are facing,
# e.g. moving to the left or right while continuing to face forward.
#
# First element is -1 when moving forward, 1 when moving back, and 0
# otherwise. The second element is -1 when moving left, 1 when moving
# right, and 0 otherwise.
self.strafe = [0, 0]
# This is strafing in the absolute up/down position, not
# relative to where the player is facing. 1 when moving up, -1 when moving down
self.strafe_z = 0
# Current (x, y, z) position in the world, specified with floats. Note
# that, perhaps unlike in math class, the y-axis is the vertical axis.
self.position = (0, 5, 0)
# First element is rotation of the player in the x-z plane (ground
# plane) measured from the z-axis down. The second is the rotation
# angle from the ground plane up. Rotation is in degrees.
#
# The vertical plane rotation ranges from -90 (looking straight down) to
# 90 (looking straight up). The horizontal rotation range is unbounded.
self.rotation = (0, 0)
# Velocity in the y (upward) direction.
self.dy = 0