-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
284 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ deps/windows/usr/ | |
deps/windows/x64 | ||
docs/build/ | ||
test/kernels/ | ||
deps/build.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export eul2m | ||
|
||
""" | ||
eul2m(angle3, angle2, angle1, axis3, axis2, axis1) | ||
Construct a rotation matrix from a set of Euler angles. | ||
### Arguments ### | ||
- `angle3`, `angle2`, `angle1`: Rotation angles about third, second, and first rotation axes (radians) | ||
- `axis3`, `axis2`, `axis1`: Axis numbers of third, second, and first rotation axes | ||
### Output ### | ||
A rotation matrix corresponding to the product of the 3 rotations. | ||
### References ### | ||
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/eul2m_c.html) | ||
""" | ||
function eul2m(angle3, angle2, angle1, axis3, axis2, axis1) | ||
r = Matrix{SpiceDouble}(undef, 3, 3) | ||
ccall((:eul2m_c, libcspice), Cvoid, | ||
(SpiceDouble, SpiceDouble, SpiceDouble, SpiceInt, SpiceInt, SpiceInt, Ptr{SpiceDouble}), | ||
angle3, angle2, angle1, axis3, axis2, axis1, r) | ||
handleerror() | ||
permutedims(r) | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
export | ||
q2m, | ||
qxq | ||
|
||
""" | ||
q2m(q...) | ||
Find the rotation matrix corresponding to a specified unit quaternion. | ||
### Arguments ### | ||
- `q`: A unit quaternion (as any kind of iterable with four elements) | ||
### Output ### | ||
A rotation matrix corresponding to `q`. | ||
### References ### | ||
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/q2m_c.html) | ||
""" | ||
q2m(q...) = q2m(collect(q)) | ||
|
||
function q2m(q) | ||
length(q) != 4 && throw(ArgumentError("`q` needs to be an iterable with four elements.")) | ||
r = Matrix{SpiceDouble}(undef, 3, 3) | ||
ccall((:q2m_c, libcspice), Cvoid, (Ptr{SpiceDouble}, Ptr{SpiceDouble}), collect(q), r) | ||
permutedims(r) | ||
end | ||
|
||
""" | ||
qxq(q1,q2...) | ||
Multiply two quaternions. | ||
### Arguments ### | ||
- `q1`: First SPICE quaternion factor (as any kind of iterable with four elements) | ||
- `q2`: Second SPICE quaternion factor (as any kind of iterable with four elements) | ||
### Output ### | ||
A quaternion corresponding to the product of `q1' and `q2' | ||
### References ### | ||
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/qxq_c.html) | ||
""" | ||
qxq(q1,q2...) = qxq(collect(q1),collect(q2)) | ||
|
||
function qxq(q1, q2) | ||
length(q1) != 4 && throw(ArgumentError("`q1` needs to be an iterable with four elements.")) | ||
length(q2) != 4 && throw(ArgumentError("`q2` needs to be an iterable with four elements.")) | ||
q = Array{SpiceDouble}(undef, 4) | ||
ccall((:qxq_c, libcspice), Cvoid, (Ptr{SpiceDouble}, Ptr{SpiceDouble}, Ptr{SpiceDouble}), collect(q1), collect(q2), q) | ||
q | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@testset "E" begin | ||
let | ||
act = eul2m(3, 2, 1, 3, 2, 1) | ||
|
||
@test size(act) == (3, 3) | ||
|
||
exp = [0.411982245665683 -0.6812427202564033 0.6051272472413688; | ||
0.05872664492762098 -0.642872836134547 -0.7637183366502791; | ||
0.9092974268256817 0.35017548837401463 -0.2248450953661529] | ||
|
||
@testset for i in eachindex(act, exp) | ||
@test act[i] ≈ exp[i] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,20 @@ | ||
@testset "M" begin | ||
matrix = [1. 1. 1. | ||
let | ||
matrix = [1. 1. 1. | ||
2. 3. 4.] | ||
vecgood = [1., 2., 3.] | ||
@test mxvg(matrix, vecgood) == [6.,20.] | ||
vecgood = [1., 2., 3.] | ||
@test mxvg(matrix, vecgood) == [6.,20.] | ||
end | ||
|
||
let | ||
r = rotate(π/2, 3) | ||
|
||
act = m2q(r) | ||
|
||
exp = [sqrt(2)/2.0, 0.0, 0.0, -sqrt(2)/2.0] | ||
|
||
@testset for i in eachindex(act, exp) | ||
@test act[i] ≈ exp[i] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
@testset "Q" begin | ||
let expected = [0.607843137254902 0.27450980392156854 0.7450980392156862; | ||
0.6666666666666666 0.33333333333333326 -0.6666666666666666; | ||
-0.43137254901960775 0.9019607843137255 0.019607843137254832] | ||
actual = q2m(0.5, 0.4, 0.3, 0.1) | ||
@testset for i in eachindex(actual, expected) | ||
@test actual[i] ≈ expected[i] | ||
end | ||
q = [0.5, 0.4, 0.3, 0.1] | ||
actual = q2m(q) | ||
@testset for i in eachindex(actual, expected) | ||
@test actual[i] ≈ expected[i] | ||
end | ||
q = (0.5, 0.4, 0.3, 0.1) | ||
actual = q2m(q) | ||
@testset for i in eachindex(actual, expected) | ||
@test actual[i] ≈ expected[i] | ||
end | ||
end | ||
|
||
let angle = deg2rad.([-20.0, 50.0, -60.0]) | ||
|
||
m = eul2m(angle[3], angle[2], angle[1], 3, 1, 3) | ||
|
||
q = m2q(m) | ||
|
||
expav = [1.0, 2.0, 3.0] | ||
|
||
qav = [0.0, 1.0, 2.0, 3.0] | ||
|
||
dq = qxq(q, qav) | ||
|
||
#dq = [-0.5 * x for x in dq] | ||
|
||
#av = spice.qdq2av(q, dq) | ||
|
||
# npt.assert_array_almost_equal(av, expav) | ||
end | ||
|
||
let qID = [1.0, 0.0, 0.0, 0.0] | ||
|
||
nqID = [-1.0, 0.0, 0.0, 0.0] | ||
|
||
qI = [0.0, 1.0, 0.0, 0.0] | ||
|
||
qJ = [0.0, 0.0, 1.0, 0.0] | ||
|
||
qK = [0.0, 0.0, 0.0, 1.0] | ||
|
||
qIJ=qxq(qI, qJ) | ||
@testset for i in eachindex(qIJ, qK) | ||
@test qIJ[i] ≈ qK[i] | ||
end | ||
|
||
qJK=qxq(qJ, qK) | ||
@testset for i in eachindex(qJK, qI) | ||
@test qJK[i] ≈ qI[i] | ||
end | ||
|
||
qKI=qxq(qK, qI) | ||
@testset for i in eachindex(qKI, qJ) | ||
@test qKI[i] ≈ qJ[i] | ||
end | ||
|
||
qII=qxq(qI, qI) | ||
@testset for i in eachindex(qII, nqID) | ||
@test qII[i] ≈ nqID[i] | ||
end | ||
|
||
qJJ=qxq(qJ, qJ) | ||
@testset for i in eachindex(qJJ, nqID) | ||
@test qJJ[i] ≈ nqID[i] | ||
end | ||
|
||
qKK=qxq(qK, qK) | ||
@testset for i in eachindex(qKK, nqID) | ||
@test qKK[i] ≈ nqID[i] | ||
end | ||
|
||
qIDI=qxq(qID, qI) | ||
@testset for i in eachindex(qIDI, qI) | ||
@test qIDI[i] ≈ qI[i] | ||
end | ||
|
||
qIID=qxq(qI, qID) | ||
@testset for i in eachindex(qIID, qI) | ||
@test qIID[i] ≈ qI[i] | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@testset "R" begin | ||
let | ||
act = rotate(π/4, 3) | ||
|
||
exp = [sqrt(2)/2.0 sqrt(2)/2.0 0.0; | ||
-sqrt(2)/2.0 sqrt(2)/2.0 0.0; | ||
0.0 0.0 1.0] | ||
|
||
@testset for i in eachindex(act, exp) | ||
@test act[i] ≈ exp[i] | ||
end | ||
end | ||
|
||
|
||
end |