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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
/// Sharpen a rotation
///
/// Adjust the columns of a matrix that is "nearly" a rotation
/// so that they are numerically unit length and orthogonal,
/// going from left to right in the usual printed presentation
/// of a matrix.
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// ROT I-O The rotation matrix to be sharpened.
/// ```
///
/// # Detailed Input
///
/// ```text
/// ROT is a 3x3 matrix that is nearly a rotation matrix.
/// ```
///
/// # Detailed Output
///
/// ```text
/// ROT is the input after sharpening the columns.
/// ```
///
/// # Exceptions
///
/// ```text
/// Error free.
///
/// 1) This routine is not meant to be used on singular or near-
/// singular matrices (in other words, matrices with determinant
/// close to zero).
///
/// If the input matrix is singular, the output matrix may not
/// be a rotation matrix. In any case, the results should be
/// considered unreliable in this case.
///
/// No error handling is done for invalid input matrices.
/// ```
///
/// # Particulars
///
/// ```text
/// This routine "sharpens" the orthogonality of a potential
/// rotation matrix. It is intended for use in those situations
/// in which you have a rotation matrix that may be derived
/// from single precision inputs or that may have experienced
/// round off errors in its construction.
/// ```
///
/// # Examples
///
/// ```text
/// Suppose that you have a rotation matrix that needs to be
/// converted to a quaternion. The SPICE matrix to quaternion
/// conversion routine M2Q performs error checks on the input
/// matrix and signals an error if it does not meet the checks
/// for a quaternion. By calling this routine you can ensure that
/// your rotation matrix (provided it's non-singular) will pass
/// the restrictions imposed by M2Q.
///
/// CALL SHARPR ( ROT )
/// CALL M2Q ( ROT, Q )
/// ```
///
/// # Restrictions
///
/// ```text
/// 1) See the $Exceptions section above.
/// ```
///
/// # Author and Institution
///
/// ```text
/// N.J. Bachman (JPL)
/// J. Diaz del Rio (ODC Space)
/// W.L. Taber (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.1, 26-OCT-2021 (JDR)
///
/// Edited the header to comply with NAIF standard. Removed
/// unnecessary $Revisions section.
///
/// - SPICELIB Version 1.1.0, 13-OCT-2005 (NJB)
///
/// Updated to remove non-standard use of duplicate arguments
/// in VHAT call. Some header updates were made.
///
/// - SPICELIB Version 1.0.0, 16-SEP-1999 (WLT)
/// ```
pub fn sharpr(rot: &mut [[f64; 3]; 3]) {
SHARPR(rot.as_flattened_mut());
}
//$Procedure SHARPR ( Sharpen a rotation )
pub fn SHARPR(ROT: &mut [f64]) {
let mut ROT = DummyArrayMut2D::new(ROT, 1..=3, 1..=3);
//
// Unitize the first column of the rotation.
//
VHATIP(ROT.subarray_mut([1, 1]));
//
// Unitize the third column of the rotation and make it
// orthogonal to the first two columns.
//
UCRSS(
&ROT.subarray([1, 1]).to_vec(),
&ROT.subarray([1, 2]).to_vec(),
ROT.subarray_mut([1, 3]),
);
//
// Unitize the second column of the rotation and make it
// orthogonal to the first and third columns.
//
UCRSS(
&ROT.subarray([1, 3]).to_vec(),
&ROT.subarray([1, 1]).to_vec(),
ROT.subarray_mut([1, 2]),
);
}