Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate rotation quaternions using exp #15

Closed
karlwessel opened this issue May 22, 2019 · 3 comments
Closed

generate rotation quaternions using exp #15

karlwessel opened this issue May 22, 2019 · 3 comments

Comments

@karlwessel
Copy link

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

@chakravala
Copy link
Owner

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.

@karlwessel
Copy link
Author

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

@chakravala
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants