Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/Quaternion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,25 @@ function slerp(qa::Quaternion{T}, qb::Quaternion{T}, t::T) where {T}
qa.v3 * ratio_a + qm.v3 * ratio_b,
)
end

function _complex_representation(A::Matrix{Quaternion{T}}) where {T}
# convert a quatenion matrix to corresponding complex matrix
a = map(t->t.s, A)
b = map(t->t.v1, A)
c = map(t->t.v2, A)
d = map(t->t.v3, A)

return [a+im*b c+im*d;-c+im*d a-im*b]
end

function _quaternion_representation(A::Matrix{Complex{T}}) where {T}
n = round(Int, size(A, 1)/2)
a = real(A[1:n, 1:n])
b = imag(A[1:n, 1:n])
c = real(A[1:n, n+1:2n])
d = imag(A[1:n, n+1:2n])
return [Quaternion(a[i,j], b[i,j], c[i,j], d[i,j]) for i in 1:n, j in 1:n]
end

# A quick way of doing the quaternionic matrix exponential
exp(A::Matrix{Quaternion{T}}) where {T} = _quaternion_representation(exp(_complex_representation(A)))
5 changes: 3 additions & 2 deletions src/Quaternions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ module Quaternions

import Base: +, -, *, /, ^
import Base: abs, abs2, angle, conj, cos, exp, inv, isfinite, log, real, sin, sqrt
import Base: convert, promote_rule, float
import LinearAlgebra: norm, normalize
import Base: convert, promote_rule, float, imag
import LinearAlgebra: norm, normalize, exp

include("Quaternion.jl")
include("Octonion.jl")
Expand All @@ -32,4 +32,5 @@ module Quaternions
export qrotation
export rotationmatrix
export slerp
export exp
end