本文整理汇总了Python中quaternion.Quaternion.interpolate方法的典型用法代码示例。如果您正苦于以下问题:Python Quaternion.interpolate方法的具体用法?Python Quaternion.interpolate怎么用?Python Quaternion.interpolate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类quaternion.Quaternion
的用法示例。
在下文中一共展示了Quaternion.interpolate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RigidTransform
# 需要导入模块: from quaternion import Quaternion [as 别名]
# 或者: from quaternion.Quaternion import interpolate [as 别名]
class RigidTransform(object):
def __init__(self, rotation_quat, translation_vec):
self.quat = Quaternion(rotation_quat)
self.tvec = numpy.array(translation_vec)
def inverse(self):
""" returns a new RigidTransform that corresponds to the inverse of this one """
qinv = self.quat.inverse()
return RigidTransform(qinv, qinv.rotate(- self.tvec))
def interpolate(self, other_transform, this_weight):
assert this_weight >= 0 and this_weight <= 1
t = self.tvec * this_weight + other_transform.tvec * (1 - this_weight)
r = self.quat.interpolate(other_transform.quat, this_weight)
return RigidTransform(r, t)
def __mul__(self, other):
if isinstance(other, RigidTransform):
t = self.quat.rotate(other.tvec) + self.tvec
r = self.quat * other.quat
return RigidTransform(r, t)
else:
olen = len(other)
if olen == 3:
r = numpy.array(self.quat.rotate(other))
return r + self.tvec
elif olen == 4:
return np.dot(self.to_homogeneous_matrix(), other)
else:
raise ValueError()
def to_homogeneous_matrix(self):
result = self.quat.to_matrix_homogeneous()
result.A[:3, 3] = self.tvec
return result
def to_roll_pitch_yaw_x_y_z(self):
r, p, y = self.quat.to_roll_pitch_yaw()
return numpy.array((r, p, y, self.tvec[0], self.tvec[1], self.tvec[2]))
@staticmethod
def from_roll_pitch_yaw_x_y_z(r, p, yaw, x, y, z):
q = Quaternion.from_roll_pitch_yaw(r, p, yaw)
return RigidTransform(q, (x, y, z))
def quaternion(self):
return self.quat
def translation(self):
return self.tvec
@staticmethod
def identity():
return RigidTransform((1, 0, 0, 0), (0, 0, 0))