1+ using FrameTransformations
2+ using Ephemerides
3+ using RemoteFiles
4+ using Test
5+ using LinearAlgebra
6+ using StaticArrays
7+
8+ @RemoteFileSet KERNELS " Spice Kernels Set" begin
9+ LEAP = @RemoteFile " https://naif.jpl.nasa.gov/pub/naif/generic_kernels/lsk/latest_leapseconds.tls" dir = joinpath (
10+ @__DIR__ , " .." , " assets"
11+ )
12+ DE432 = @RemoteFile " https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/planets/de432s.bsp" dir = joinpath (
13+ @__DIR__ , " .." , " assets"
14+ )
15+ end ;
16+
17+ download (KERNELS; verbose= true , force= false )
18+
19+ atol = 1e-8
20+
21+ # Define two non parallel vectors and their 1st, 2nd and 3rd order time derivatives!
22+ function get_v1 (t)
23+ return SA[cos (3 t), t* sin (t), t^ 2 * cos (t)]
24+ end
25+ get_v2 (t) = SA[t^ 3 , t^ 2 , t]
26+
27+ @testset " Sequence assembly" begin
28+ for _ = 1 : 100
29+
30+ θ = rand ()
31+ a, b = get_v1 (θ)[1 : 3 ], get_v2 (θ)[1 : 3 ]
32+ c = cross (a, b)
33+
34+ aᵤ, bᵤ, cᵤ = a / norm (a), b / norm (b), c / norm (c)
35+
36+ # XY
37+ R = FrameTransformations. twodir_to_dcm (a, b, :XY )
38+
39+ @test R' * [1 , 0 , 0 ] ≈ aᵤ atol = atol
40+ @test R' * [0 , 0 , 1 ] ≈ cᵤ atol = atol
41+ @test dot (R' * [0 , 1 , 0 ], aᵤ) ≈ 0 atol = atol
42+
43+ # YX
44+ R = FrameTransformations. twodir_to_dcm (a, b, :YX )
45+
46+ @test R' * [0 , 1 , 0 ] ≈ aᵤ atol = atol
47+ @test R' * [0 , 0 , 1 ] ≈ - cᵤ atol = atol
48+ @test dot (R' * [1 , 0 , 0 ], aᵤ) ≈ 0 atol = atol
49+
50+ # XZ
51+ R = FrameTransformations. twodir_to_dcm (a, b, :XZ )
52+
53+ @test R' * [1 , 0 , 0 ] ≈ aᵤ atol = atol
54+ @test R' * [0 , 1 , 0 ] ≈ - cᵤ atol = atol
55+ @test dot (R' * [0 , 1 , 0 ], aᵤ) ≈ 0 atol = atol
56+
57+ # ZX
58+ R = FrameTransformations. twodir_to_dcm (a, b, :ZX )
59+
60+ @test R' * [0 , 0 , 1 ] ≈ aᵤ atol = atol
61+ @test R' * [0 , 1 , 0 ] ≈ cᵤ atol = atol
62+ @test dot (R' * [1 , 0 , 0 ], aᵤ) ≈ 0 atol = atol
63+
64+ # YZ
65+ R = FrameTransformations. twodir_to_dcm (a, b, :YZ )
66+
67+ @test R' * [0 , 1 , 0 ] ≈ aᵤ atol = atol
68+ @test R' * [1 , 0 , 0 ] ≈ cᵤ atol = atol
69+ @test dot (R' * [0 , 0 , 1 ], aᵤ) ≈ 0 atol = atol
70+
71+ # ZY
72+ R = FrameTransformations. twodir_to_dcm (a, b, :ZY )
73+
74+ @test R' * [0 , 0 , 1 ] ≈ aᵤ atol = atol
75+ @test R' * [1 , 0 , 0 ] ≈ - cᵤ atol = atol
76+ @test dot (R' * [0 , 1 , 0 ], aᵤ) ≈ 0 atol = atol
77+
78+ end
79+ end ;
80+
81+ @testset " Frames" begin
82+
83+ frames = FrameSystem {4,Float64} ()
84+ add_axes_icrf! (frames)
85+
86+ eph = EphemerisProvider (path (KERNELS[:DE432 ]))
87+ add_point! (frames, :SSB , 0 , 1 )
88+ add_point_ephemeris! (frames, eph, :Sun , 10 )
89+ add_point_ephemeris! (frames, eph, :EarthB , 3 )
90+ add_point_ephemeris! (frames, eph, :Earth , 399 )
91+ add_direction_position! (frames, :SunEarthPos , :Sun , :Earth , :ICRF )
92+ add_direction_velocity! (frames, :SunEarthVel , :Sun , :Earth , :ICRF )
93+ add_axes_twodir! (frames, :SunEarthRot , 2 , :ICRF , :SunEarthPos , :SunEarthVel , :XY )
94+
95+ @test_throws ArgumentError add_axes_twodir! (frames, :SunEarthRot , 2 , :ICRF , :A , :SunEarthVel , :XY )
96+ @test_throws ArgumentError add_axes_twodir! (frames, :SunEarthRot , 2 , :ICRF , :SunEarthPos , :B , :XY )
97+
98+ for _ = 1 : 100
99+ e = rand (0 : 1e8 )
100+ v = vector3 (frames, :Sun , :Earth , :SunEarthRot , e)
101+ v /= norm (v)
102+ @test v[1 ] ≈ 1.0
103+ end
104+
105+ end ;
0 commit comments