chakravala / Grassmann.jl

⟨Grassmann-Clifford-Hodge⟩ multilinear differential geometric algebra

Home Page:https://grassmann.crucialflow.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

generate rotation quaternions using exp

karlwessel opened this issue · comments

I wanted to do a test your package by implementing Quaternions and tried to create a quaternion q for a rotation around a vector v = (a, b, c) by an angle alpha using exponentials:
q = exp(alpha/2*(ai + bj + ck))

However the exponential function doesn't seem to be fully implemented yet for multivectors? At least i get an error in the following MWE:

julia> using Grassmann

julia> i, j, k = hyperplanes(ℝ^3)
3-element Array{SValue{⟨+++⟩,2,B,Int64} where B,1}:
 -1v₂₃
 1v₁₃ 
 -1v₁₂

julia> alpha = 0.5π
1.5707963267948966

julia> exp(alpha/2*(i))
0.7071067811865476 - 0.7071067811865475v₂₃

julia> a, b, c = 1/sqrt(2) * [1, 1, 0]
3-element Array{Float64,1}:
 0.7071067811865475
 0.7071067811865475
 0.0               

julia> exp(alpha/2*(a*i + b*j + c*k))
ERROR: MethodError: no method matching abs(::StaticArrays.MArray{Tuple{8},Float64,1,8})
Closest candidates are:
  abs(::Bool) at bool.jl:91
  abs(::Float16) at float.jl:520
  abs(::Float32) at float.jl:521
  ...
Stacktrace:
 [1] abs(::MultiVector{Float64,⟨+++⟩,8}) at .julia/packages/AbstractTensors/fUnNY/src/AbstractTensors.jl:55
 [2] _broadcast_getindex_evalf at ./broadcast.jl:578 [inlined]
 [3] _broadcast_getindex at ./broadcast.jl:551 [inlined]
 [4] getindex at ./broadcast.jl:511 [inlined]
 [5] copyto_nonleaf!(::Array{Float64,1}, ::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1},Tuple{Base.OneTo{Int64}},typeof(abs),Tuple{Base.Broadcast.Extruded{Array{TensorAlgebra{⟨+++⟩},1},Tuple{Bool},Tuple{Int64}}}}, ::Base.OneTo{Int64}, ::Int64, ::Int64) at ./broadcast.jl:928
 [6] copy at ./broadcast.jl:791 [inlined]
 [7] materialize at ./broadcast.jl:753 [inlined]
 [8] exp(::SBlade{Float64,⟨+++⟩,2,3}) at .julia/packages/Grassmann/wWv7E/src/algebra.jl:961
 [9] top-level scope at none:0

Thanks for opening the issue. The algorithm for the exp method is a rough draft at the moment and I have received some feedback about how to improve it, but have not followed through on it yet.

Thank you for the quick response! Then i'll just fall back to sine and cosine to create the quaternion for now.

That exp call should work now

julia> exp(alpha/2*(a*i + b*j + c*k))
0.7071067811865476 + 0.5v₁₃ - 0.5v₂₃

julia> ans == (sqrt(2)+j+i)/2
true