1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
/// Transform to rotation and angular velocity
///
/// Determine the rotation matrix and angular velocity of the
/// rotation from a state transformation matrix.
///
/// # Required Reading
///
/// * [ROTATION](crate::required_reading::rotation)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// XFORM I is a state transformation matrix.
/// ROT O is the rotation associated with XFORM.
/// AV O is the angular velocity associated with XFORM.
/// ```
///
/// # Detailed Input
///
/// ```text
/// XFORM is a state transformation matrix from one frame
/// FRAME1 to some other frame FRAME2.
/// ```
///
/// # Detailed Output
///
/// ```text
/// ROT is a rotation that gives the transformation from
/// some frame FRAME1 to another frame FRAME2.
///
/// AV is the angular velocity of the transformation.
/// In other words, if P is the position of a fixed
/// point in FRAME2, then from the point of view of
/// FRAME1, P rotates (in a right handed sense) about
/// an axis parallel to AV. Moreover the rate of rotation
/// in radians per unit time is given by the length of
/// AV.
///
/// More formally, the velocity V of P in FRAME1 is
/// given by
/// T
/// V = AV x ( ROT * P )
///
/// The components of AV are given relative to FRAME1.
/// ```
///
/// # Exceptions
///
/// ```text
/// Error free.
///
/// 1) No checks are performed on XFORM to ensure that it is indeed
/// a state transformation matrix.
/// ```
///
/// # Particulars
///
/// ```text
/// This routine is essentially a macro routine for converting
/// state transformation matrices into the equivalent representation
/// in terms of a rotation and angular velocity.
///
/// This routine is an inverse of the routine RAV2XF.
/// ```
///
/// # Examples
///
/// ```text
/// The numerical results shown for this example may differ across
/// platforms. The results depend on the SPICE kernels used as
/// input, the compiler and supporting libraries, and the machine
/// specific arithmetic implementation.
///
/// 1) Suppose that you wanted to determine the angular velocity
/// of the Earth body-fixed reference frame with respect to
/// J2000 at a particular epoch ET. The following code example
/// illustrates a procedure for computing the angular velocity.
///
/// Use the meta-kernel shown below to load the required SPICE
/// kernels.
///
///
/// KPL/MK
///
/// File name: xf2rav_ex1.tm
///
/// This meta-kernel is intended to support operation of SPICE
/// example programs. The kernels shown here should not be
/// assumed to contain adequate or correct versions of data
/// required by SPICE-based user applications.
///
/// In order for an application to use this meta-kernel, the
/// kernels referenced here must be present in the user's
/// current working directory.
///
/// The names and contents of the kernels referenced
/// by this meta-kernel are as follows:
///
/// File name Contents
/// --------- --------
/// earth_720101_070426.bpc Earth historical
/// binary PCK
/// naif0012.tls Leapseconds
///
/// \begindata
///
/// KERNELS_TO_LOAD = ( 'earth_720101_070426.bpc',
/// 'naif0012.tls' )
///
/// \begintext
///
/// End of meta-kernel
///
///
/// Example code begins here.
///
///
/// PROGRAM XF2RAV_EX1
/// IMPLICIT NONE
///
/// C
/// C Local parameters.
/// C
/// CHARACTER*(*) META
/// PARAMETER ( META = 'xf2rav_ex1.tm' )
///
/// CHARACTER*(*) UTCSTR
/// PARAMETER ( UTCSTR = '2005-OCT-10 16:00:00' )
///
/// C
/// C Local variables.
/// C
/// DOUBLE PRECISION AV ( 3 )
/// DOUBLE PRECISION ET
/// DOUBLE PRECISION FTMTRX ( 6, 6 )
/// DOUBLE PRECISION ROT ( 3, 3 )
///
/// INTEGER I
/// INTEGER J
///
/// C
/// C Load SPICE kernels.
/// C
/// CALL FURNSH ( META )
///
/// C
/// C Convert the input time to seconds past J2000 TDB.
/// C
/// CALL STR2ET ( UTCSTR, ET )
///
/// C
/// C Get the transformation matrix from J2000 frame to
/// C ITRF93.
/// C
/// CALL SXFORM ( 'J2000', 'ITRF93', ET, FTMTRX )
///
/// C
/// C Now get the angular velocity by calling XF2RAV
/// C
/// CALL XF2RAV ( FTMTRX, ROT, AV )
///
/// C
/// C Display the results.
/// C
/// WRITE(*,'(A)') 'Rotation matrix:'
/// DO I = 1, 3
///
/// WRITE(*,'(3F16.11)') ( ROT(I,J), J=1,3 )
///
/// END DO
///
/// WRITE(*,*)
/// WRITE(*,'(A)') 'Angular velocity:'
/// WRITE(*,'(3F16.11)') AV
///
/// END
///
///
/// When this program was executed on a Mac/Intel/gfortran/64-bit
/// platform, the output was:
///
///
/// Rotation matrix:
/// -0.18603277688 -0.98254352801 0.00014659080
/// 0.98254338275 -0.18603282936 -0.00053610915
/// 0.00055402128 0.00004429795 0.99999984555
///
/// Angular velocity:
/// 0.00000004025 0.00000000324 0.00007292114
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// W.L. Taber (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.1, 19-MAY-2020 (JDR)
///
/// Edited the header to comply with NAIF standard. Added complete
/// code example based on existing example.
///
/// Added ROTATION to the required readings.
///
/// - SPICELIB Version 1.1.0, 28-JUL-1997 (WLT)
///
/// The example in version 1.0.0 was incorrect. The example
/// in version 1.1.0 fixes the previous problem.
///
/// - SPICELIB Version 1.0.0, 19-SEP-1995 (WLT)
/// ```
pub fn xf2rav(xform: &[[f64; 6]; 6], rot: &mut [[f64; 3]; 3], av: &mut [f64; 3]) {
XF2RAV(xform.as_flattened(), rot.as_flattened_mut(), av);
}
//$Procedure XF2RAV ( Transform to rotation and angular velocity)
pub fn XF2RAV(XFORM: &[f64], ROT: &mut [f64], AV: &mut [f64]) {
let XFORM = DummyArray2D::new(XFORM, 1..=6, 1..=6);
let mut ROT = DummyArrayMut2D::new(ROT, 1..=3, 1..=3);
let mut AV = DummyArrayMut::new(AV, 1..=3);
let mut DRDT = StackArray2D::<f64, 9>::new(1..=3, 1..=3);
let mut OMEGA = StackArray2D::<f64, 9>::new(1..=3, 1..=3);
//
// A state transformation matrix XFORM has the following form
//
//
// [ | ]
// | R | 0 |
// | | |
// | -----+-----|
// | dR | |
// | -- | R |
// [ dt | ]
//
//
// where R is a rotation and dR/dt is the time derivative of that
// rotation. From this we can immediately read the rotation and
// its derivative.
//
for I in 1..=3 {
for J in 1..=3 {
ROT[[I, J]] = XFORM[[I, J]];
DRDT[[I, J]] = XFORM[[(I + 3), J]];
}
}
//
// Recall that ROT is a transformation that converts positions
// in some frame FRAME1 to positions in a second frame FRAME2.
//
// The angular velocity matrix OMEGA (the cross product matrix
// corresponding to AV) has the following property.
//
// If P is the position of an object that is stationary with
// respect to FRAME2 then the velocity V of that object in FRAME1
// is given by:
// t
// V = OMEGA * ROT * P
//
// But V is also given by
//
// t
// d ROT
// V = ----- * P
// dt
//
// So that
// t
// t d ROT
// OMEGA * ROT = -------
// dt
//
// Hence
// t
// d ROT
// OMEGA = ------- * ROT
// dt
//
//
//
MTXM(DRDT.as_slice(), ROT.as_slice(), OMEGA.as_slice_mut());
//
// Recall that OMEGA has the form
//
// _ _
// | |
// | 0 -AV(3) AV(2) |
// | |
// | AV(3) 0 -AV(1) |
// | |
// | -AV(2) AV(1) 0 |
// |_ _|
//
AV[1] = OMEGA[[3, 2]];
AV[2] = OMEGA[[1, 3]];
AV[3] = OMEGA[[2, 1]];
}