-
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
8 changed files
with
171 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export q2m | ||
|
||
""" | ||
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 |
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,18 @@ | ||
@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 = spice.rotate(spice.halfpi(), 3) | ||
|
||
# q = spice.m2q(r) | ||
|
||
# expected = [np.sqrt(2) / 2.0, 0.0, 0.0, -np.sqrt(2) / 2.0] | ||
|
||
# np.testing.assert_array_almost_equal(expected, q, decimal = 6) | ||
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,40 @@ | ||
@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 = spice.m2q(m) | ||
|
||
# expav = [1.0, 2.0, 3.0] | ||
|
||
# qav = [0.0, 1.0, 2.0, 3.0] | ||
|
||
# dq = spice.qxq(q, qav) | ||
|
||
# dq = [-0.5 * x for x in dq] | ||
|
||
# av = spice.qdq2av(q, dq) | ||
|
||
# npt.assert_array_almost_equal(av, expav) | ||
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 |