Quaternion
Tensorial.Quaternion — TypeQuaternion represents $q_1 + q_2 \bm{i} + q_3 \bm{j} + q_4 \bm{k}$. The salar part and vector part can be accessed by q.scalar and q.vector, respectively.
Quaternion is experimental and could change or disappear in future versions of Tensorial.
Tensorial.quaternion — Methodquaternion(θ, x::Vec; [normalize = true, degree = false])
quaternion(T, θ, x::Vec; [normalize = true, degree = false])Construct Quaternion from angle θ and direction x. The constructed quaternion is normalized such as norm(q) ≈ 1 by default.
julia> q = quaternion(π/4, Vec(0,0,1))
0.9238795325112867 + 0.0𝙞 + 0.0𝙟 + 0.3826834323650898𝙠
julia> v = rand(Vec{3})
3-element Tensor{Tuple{3},Float64,1,3}:
0.5908446386657102
0.7667970365022592
0.5662374165061859
julia> (q * v / q).vector ≈ rotmatz(π/4) ⋅ v
trueTensorial.rotate — Methodrotate(x::Vec, q::Quaternion)Rotate x by quaternion q.
Examples
julia> v = Vec(1.0, 0.0, 0.0)
3-element Tensor{Tuple{3},Float64,1,3}:
1.0
0.0
0.0
julia> rotate(v, quaternion(π/4, Vec(0,0,1)))
3-element Tensor{Tuple{3},Float64,1,3}:
0.7071067811865475
0.7071067811865476
0.0