Skip to content

Commit

Permalink
Merge acb8c24 into 1217540
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasnoack committed Jul 14, 2018
2 parents 1217540 + acb8c24 commit 09aff3e
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ os:
- osx
julia:
- 0.6
- 0.7
- nightly

matrix:
Expand Down
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
julia 0.6
Compat 0.48
DualNumbers
2 changes: 1 addition & 1 deletion src/Octonion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function log(o::Octonion)
o, a = normalizea(o)
s = o.s
M = abs(Octonion(imag(o)))
th = atan2(M, s)
th = atan(M, s)
if M > 0
M = th / M
return Octonion(log(a),
Expand Down
11 changes: 7 additions & 4 deletions src/Quaternion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ struct Quaternion{T<:Real} <: Number
norm::Bool
end

(::Type{Quaternion{T}})(x::Real) where {T} = Quaternion{T}(x, 0, 0, 0, false)
(::Type{Quaternion{T}})(q::Quaternion{T}) where {T<:Real} = q
(::Type{Quaternion{T}})(q::Quaternion) where {T<:Real} = Quaternion{T}(q.s, q.v1, q.v2, q.v3, q.norm)
Quaternion(s::Real, v1::Real, v2::Real, v3::Real, n::Bool = false) =
Quaternion(promote(s, v1, v2, v3)..., n)
Quaternion(x::Real) = Quaternion(x, zero(x), zero(x), zero(x), abs(x) == one(x))
Expand Down Expand Up @@ -94,7 +97,7 @@ end

angleaxis(q::Quaternion) = angle(q), axis(q)

angle(q::Quaternion) = 2 * atan2((q.v1^2 + q.v2^2 + q.v3^2), q.s)
angle(q::Quaternion) = 2 * atan((q.v1^2 + q.v2^2 + q.v3^2), q.s)

function axis(q::Quaternion)
q = normalize(q)
Expand All @@ -121,7 +124,7 @@ function log(q::Quaternion)
q, a = normalizea(q)
s = q.s
M = abs_imag(q)
th = atan2(M, s)
th = atan(M, s)
if M > 0
M = th / M
return Quaternion(log(a), q.v1 * M, q.v2 * M, q.v3 * M)
Expand Down Expand Up @@ -208,7 +211,7 @@ function qrotation(rotvec::Vector{T}) where {T <: Real}
Quaternion(one(T), zero(T), zero(T), zero(T), true)
end

function qrotation{T<:Real}(dcm::Matrix{T})
function qrotation(dcm::Matrix{T}) where {T<:Real}
# See https://arxiv.org/pdf/math/0701759.pdf
a2 = 1 + dcm[1,1] + dcm[2,2] + dcm[3,3]
b2 = 1 + dcm[1,1] - dcm[2,2] - dcm[3,3]
Expand All @@ -230,7 +233,7 @@ function qrotation{T<:Real}(dcm::Matrix{T})
end
end

function qrotation{T<:Real}(dcm::Matrix{T}, qa::Quaternion)
function qrotation(dcm::Matrix{T}, qa::Quaternion) where {T<:Real}
q = qrotation(dcm)
abs(q-qa) < abs(q+qa) ? q : -q
end
Expand Down
8 changes: 7 additions & 1 deletion src/Quaternions.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
__precompile__()

module Quaternions
importall Base

using Compat

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

include("Quaternion.jl")
include("Octonion.jl")
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Base.Test
using Compat.Test
using Quaternions

test_associative(x, y, z, ) = @test (x y) z x (y z)
Expand Down
4 changes: 3 additions & 1 deletion test/test_Quaternion.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

import Quaternions.argq
using Quaternions: argq
using Compat
using Compat.LinearAlgebra

# creating random examples
sample(QT::Type{Quaternion{T}}) where {T <: Integer} = QT(rand(-100:100, 4)..., false)
Expand Down

0 comments on commit 09aff3e

Please sign in to comment.