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."
评论列表
文章目录