python 四元素,如何通过python或numpy乘以两个四元数

I have two quaternions: Q1= w0, x0, y0, z0 and Q2 = w1, x1, y1, z1. I would like to multiply them by using NumPy or Python function which can return 2-d array. I found some pseudocodes on the internet which is written by Christoph Gohlke to do this kind of multiplication. I tried a lot but failed to apply it. Can anyone help me please to do this kind of multiplication? The pseudocodes are here: `

def quaternion_multiply(quaternion1, quaternion0):

w0, x0, y0, z0 = quaternion0

w1, x1, y1, z1 = quaternion1

return array([-x1*x0 - y1*y0 - z1*z0 + w1*w0,

x1*w0 + y1*z0 - z1*y0 + w1*x0,

-x1*z0 + y1*w0 + z1*x0 + w1*y0,

x1*y0 - y1*x0 + z1*w0 + w1*z0], dtype=float64)`

解决方案

Here's a little example using your function:

import numpy as np

import random

def quaternion_multiply(quaternion1, quaternion0):

w0, x0, y0, z0 = quaternion0

w1, x1, y1, z1 = quaternion1

return np.array([-x1 * x0 - y1 * y0 - z1 * z0 + w1 * w0,

x1 * w0 + y1 * z0 - z1 * y0 + w1 * x0,

-x1 * z0 + y1 * w0 + z1 * x0 + w1 * y0,

x1 * y0 - y1 * x0 + z1 * w0 + w1 * z0], dtype=np.float64)

N = 4

for i in range(N):

q1 = np.random.rand(4)

q2 = np.random.rand(4)

q = quaternion_multiply(q1, q2)

print("{0} x {1} = {2}".format(q1, q2, q))

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值