quaternion.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:hand_eye_calibration 作者: ethz-asl 项目源码 文件源码
def __mul__(self, other):
    """ Scalar and Hamilton quaternion product.

    The multiplication with a scalar returns the quaternion with all elements
    multiplied by the scalar.

    The multiplication with a quaternion returns the Hamilton product.
    """
    if isinstance(other, Quaternion):
      x = (self.w * other.x + self.x * other.w +
           self.y * other.z - self.z * other.y)
      y = (self.w * other.y - self.x * other.z +
           self.y * other.w + self.z * other.x)
      z = (self.w * other.z + self.x * other.y -
           self.y * other.x + self.z * other.w)
      w = (self.w * other.w - self.x * other.x -
           self.y * other.y - self.z * other.z)
      return Quaternion(x, y, z, w)
    elif isinstance(other, Number):
      q = self.q.copy()
      q_out = q * np.float64(other)
      return Quaternion(q=q_out)
    else:
      assert False, "Multiplication is only defined for scalars or quaternions."
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号