JuliaSpace / ReferenceFrameRotations.jl

A toolbox to represent 3D rotations of coordinate frames for Julia language.
MIT License
59 stars 13 forks source link

Product between a quaternion and a pure quaternion #16

Closed empet closed 3 years ago

empet commented 3 years ago

The product of a unit quaternion and a vector has non-zero real part. By product definition it must be zero.

using ReferenceFrameRotations
q = Quaternion(cos(π/6), 0,  0, sin(π/6))
v =  [3, -1.5,  -0.354];
q * v
Quaternion{Float64}:
  + 0.177 + 3.34808⋅i + 0.200962⋅j - 0.306573⋅k

Julia 1.6.1, ReferenceFrameRotations.jl, v 1.0.1

ronisbr commented 3 years ago

Hi @empet !

No, the product q * v is defined here as the product of q * Quaternion(0, v). The latter is a quaternion with real part 0 and vector part equal to v. The real part will be 0 if you use quaternions to rotate a vector like inv(q) * v * q or q \ v * q.

julia> using ReferenceFrameRotations

julia> q = Quaternion(cos(π/6), 0,  0, sin(π/6))
Quaternion{Float64}:
  + 0.866025 + 0.0⋅i + 0.0⋅j + 0.5⋅k

julia> v =  [3, -1.5,  -0.354];

julia> q \ v * q
Quaternion{Float64}:
  + 0.0 + 0.200962⋅i - 3.34808⋅j - 0.354⋅k

Notice that the way I defined the multiplication between vectors and quaternions is not the same as in other packages. It is more close to the mathematical definition. Does it make sense?

empet commented 3 years ago

I was confused by multiplication in Rotations.jl. There q=UnitQuaternion(cos(π/6), 0, 0, sin(π/6) is in fact the rotation matrix with pi/3 about zaxis, and the product q*v is the result of rotation. Thank you!