计算四元数逆 [英] Calculate Quaternion Inverse

查看:108
本文介绍了计算四元数逆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚如何计算四元数的倒数.代码示例会很棒.

Hi i'm trying to figure out how to calculate the inverse of a quaternion. A code example would be awesome.

干杯

推荐答案

参见 维基百科文章整个四元数数学.

See Wikipedia article for the entire Quaternion math.

不知道您想使用哪种语言,但我会尝试在 Haskell 中提供一些提示.

Don't know what language you want to use but I'll try to give some hints in Haskell.

data Quaternion = Q Double Double Double Double deriving (Show, Eq)

首先需要实现四元数的乘法和加法.

First, you need to implement multiplication and addition of quaternions.

instance Num Quaternion where
 (+) = q_plus
 (*) = q_mult
 --....

q_plus (Q a b c d) (Q a' b' c' d') = Q (a + a') (b + b') (c + c') (d + d')
q_mult (Q a b c d) (Q a' b' c' d') = Q a'' b'' c'' d''
  where
    a'' = a * a' - b * b' - c * c' - d * d'
    b'' = a * b' + b * a' + c * d' - d * c'
    c'' = a * c' - b * d' + c * a' + d * b'
    d'' = a * d' + b * c' - c * b' + d * a'

标量乘法应通过转换完成:

Multiplication with scalar should be done via a conversion:

scalar_to_q a = Q a 0 0 0

定义

i = Q 0 1 0 0
j = Q 0 0 1 0
k = Q 0 0 0 1

然后实现共轭和模:

q_conjugate q = (scalar_to_q (negate .5)) * (q + i * q * i + j * q * j + k * q * k)
q_modulus q = sqrt $ q * (q_conjugate q)

现在,反过来:

q_inverse q = (q_conjugate q) * (scalar_to_q (m * m))
  where
    m = q_modulus q

希望有用.

PS:如果成功完成,上面的实例定义将简化一些事情.我让你填补空白.

PS: the instance definition above will simplify things a little if completed successfully. I let you fill in the gaps.

这篇关于计算四元数逆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆