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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
struct SaveVars {
INDEXS: StackArray<i32, 5>,
}
impl SaveInit for SaveVars {
fn new() -> Self {
let mut INDEXS = StackArray::<i32, 5>::new(1..=5);
{
use f2rust_std::data::Val;
let mut clist = [Val::I(3), Val::I(1), Val::I(2), Val::I(3), Val::I(1)].into_iter();
INDEXS
.iter_mut()
.for_each(|n| *n = clist.next().unwrap().into_i32());
debug_assert!(clist.next().is_none(), "DATA not fully initialised");
}
Self { INDEXS }
}
}
/// Transform a vector via a rotation
///
/// Transform a vector to a new reference frame rotated by ANGLE
/// radians about axis IAXIS. This transformation rotates V1 by
/// -ANGLE radians about the specified axis.
///
/// # Required Reading
///
/// * [ROTATION](crate::required_reading::rotation)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// V1 I Vector whose coordinate system is to be rotated.
/// ANGLE I Angle of rotation in radians.
/// IAXIS I Axis of rotation (X=1, Y=2, Z=3).
/// VOUT O Resulting vector expressed in the new frame.
/// ```
///
/// # Detailed Input
///
/// ```text
/// V1 is a vector (typically representing a vector fixed in
/// inertial space) which is to be expressed in another
/// reference frame. The vector remains fixed but the
/// reference frame changes.
///
/// ANGLE is an angle given in radians, through which the rotation
/// is performed.
///
/// IAXIS is the index of the axis of rotation. The X, Y, and Z
/// axes have indices 1, 2 and 3 respectively.
/// ```
///
/// # Detailed Output
///
/// ```text
/// VOUT is the vector expressed in the new reference frame
/// specified by the angle of rotation and axis. If
///
/// M = [ANGLE]
/// IAXIS
///
/// represents the rotation matrix described by the ANGLE
/// and IAXIS, (refer to the routine ROTATE) then
///
/// VOUT = M * V1 = [ANGLE] * V1
/// IAXIS
/// ```
///
/// # Exceptions
///
/// ```text
/// Error free.
///
/// 1) If the IAXIS index is not in the range 1 to 3, it will be
/// treated the same as that integer 1, 2, or 3 that is congruent
/// to it mod 3.
/// ```
///
/// # Particulars
///
/// ```text
/// A rotation about the first, i.e. X-axis, is described by
///
/// .- -.
/// | 1 0 0 |
/// | 0 cos(theta) sin(theta) |
/// | 0 -sin(theta) cos(theta) |
/// `- -'
///
/// A rotation about the second, i.e. Y-axis, is described by
///
/// .- -.
/// | cos(theta) 0 -sin(theta) |
/// | 0 1 0 |
/// | sin(theta) 1 cos(theta) |
/// `- -'
///
/// A rotation about the third, i.e. Z-axis, is described by
///
/// .- -.
/// | cos(theta) sin(theta) 0 |
/// | -sin(theta) cos(theta) 0 |
/// | 0 0 1 |
/// `- -'
///
/// ROTVEC decides which form is appropriate according to the value
/// of IAXIS and applies the rotation to the input vector.
/// ```
///
/// # 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) Apply a rotation of -45.D0 degrees about the +Z axis to
/// a 3 dimensional vector.
///
/// Example code begins here.
///
///
/// PROGRAM ROTVEC_EX1
/// IMPLICIT NONE
///
/// C
/// C SPICELIB functions
/// C
/// DOUBLE PRECISION PI
///
/// C
/// C Local variables.
/// C
/// DOUBLE PRECISION ANGLE
/// DOUBLE PRECISION V1 ( 3 )
/// DOUBLE PRECISION VOUT ( 3 )
///
/// INTEGER I
/// INTEGER IAXIS
///
/// C
/// C Input values.
/// C
/// DATA V1 / 1.414D0, 0.D0, 0.D0 /
///
/// ANGLE = PI( )/4
/// IAXIS = 3
///
/// C
/// C Rotate V1 by ANGLE radians about IAXIS
/// C
/// CALL ROTVEC (V1, ANGLE, IAXIS, VOUT)
///
/// WRITE(*,'(A,3F10.3)') 'Input vector :',
/// . ( V1(I), I=1,3 )
/// WRITE(*,'(A,3F10.3)') 'Rotated vector:',
/// . ( VOUT(I), I=1,3 )
///
/// END
///
///
/// When this program was executed on a Mac/Intel/gfortran/64-bit
/// platform, the output was:
///
///
/// Input vector : 1.414 0.000 0.000
/// Rotated vector: 1.000 -1.000 0.000
/// ```
///
/// # Author and Institution
///
/// ```text
/// N.J. Bachman (JPL)
/// J. Diaz del Rio (ODC Space)
/// W.M. Owen (JPL)
/// W.L. Taber (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 06-JUL-2021 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard. Created
/// complete code example from existing code fragments.
///
/// Changed "coordinate system" to "reference frame" to follow
/// NAIF conventions. Added ROTATION required reading.
///
/// - SPICELIB Version 1.0.3, 23-APR-2010 (NJB)
///
/// Header correction: assertions that the output
/// can overwrite the input have been removed.
///
/// - SPICELIB Version 1.0.2, 04-OCT-1999 (NJB)
///
/// Procedure line and abstract were changed to dispel the
/// impression that the input vector is rotated by +ANGLE
/// radians about the specified axis.
///
/// - SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)
///
/// Comment section for permuted index source lines was added
/// following the header.
///
/// - SPICELIB Version 1.0.0, 31-JAN-1990 (WMO) (WLT)
/// ```
///
/// # Revisions
///
/// ```text
/// - Beta Version 1.1.0, 04-JAN-1989 (WLT)
///
/// Upgrade the routine to work with negative axis indexes. Also
/// take care of the funky way the indices (other than the input)
/// were obtained via the MOD function. It works but isn't as
/// clear (or fast) as just reading the axes from data.
/// ```
pub fn rotvec(ctx: &mut SpiceContext, v1: &[f64; 3], angle: f64, iaxis: i32, vout: &mut [f64; 3]) {
ROTVEC(v1, angle, iaxis, vout, ctx.raw_context());
}
//$Procedure ROTVEC ( Transform a vector via a rotation )
pub fn ROTVEC(V1: &[f64], ANGLE: f64, IAXIS: i32, VOUT: &mut [f64], ctx: &mut Context) {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
let V1 = DummyArray::new(V1, 1..=3);
let mut VOUT = DummyArrayMut::new(VOUT, 1..=3);
let mut S: f64 = 0.0;
let mut C: f64 = 0.0;
let mut TMP: i32 = 0;
let mut I1: i32 = 0;
let mut I2: i32 = 0;
let mut I3: i32 = 0;
let mut TEMP = StackArray::<f64, 3>::new(1..=3);
//
// Local variables
//
//
// Get the sine and cosine of ANGLE
//
S = f64::sin(ANGLE);
C = f64::cos(ANGLE);
//
// Get indices for axes. The first index is for the axis of rotation.
// The next two axes follow in right hand order (XYZ). First get the
// non-negative value of IAXIS mod 3 .
//
TMP = intrinsics::MOD((intrinsics::MOD(IAXIS, 3) + 3), 3);
I1 = save.INDEXS[(TMP + 1)];
I2 = save.INDEXS[(TMP + 2)];
I3 = save.INDEXS[(TMP + 3)];
//
// The coordinate along the axis of rotation does not change.
//
TEMP[1] = V1[I1];
TEMP[2] = ((C * V1[I2]) + (S * V1[I3]));
TEMP[3] = (-(S * V1[I2]) + (C * V1[I3]));
//
// Move the buffered vector to the output
//
VOUT[I1] = TEMP[1];
VOUT[I2] = TEMP[2];
VOUT[I3] = TEMP[3];
}