1 /* vrotv.f -- translated by f2c (version 19980913).
2 You must link the resulting object file with the libraries:
3 -lf2c -lm (in that order)
4 */
5
6 #include "f2c.h"
7
8 /* Table of constant values */
9
10 static integer c__3 = 3;
11
12 /* $Procedure VROTV ( Vector rotation about an axis ) */
vrotv_(doublereal * v,doublereal * axis,doublereal * theta,doublereal * r__)13 /* Subroutine */ int vrotv_(doublereal *v, doublereal *axis, doublereal *
14 theta, doublereal *r__)
15 {
16 /* Builtin functions */
17 double cos(doublereal), sin(doublereal);
18
19 /* Local variables */
20 extern /* Subroutine */ int vadd_(doublereal *, doublereal *, doublereal *
21 ), vhat_(doublereal *, doublereal *), vsub_(doublereal *,
22 doublereal *, doublereal *);
23 doublereal c__, p[3], s, x[3];
24 extern /* Subroutine */ int moved_(doublereal *, integer *, doublereal *),
25 vlcom_(doublereal *, doublereal *, doublereal *, doublereal *,
26 doublereal *), vproj_(doublereal *, doublereal *, doublereal *);
27 extern doublereal vnorm_(doublereal *);
28 extern /* Subroutine */ int vcrss_(doublereal *, doublereal *, doublereal
29 *);
30 doublereal v1[3], v2[3], rplane[3];
31
32 /* $ Abstract */
33
34 /* Rotate a vector about a specified axis vector by a specified */
35 /* angle and return the rotated vector. */
36
37 /* $ Disclaimer */
38
39 /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
40 /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
41 /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
42 /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
43 /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
44 /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
45 /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
46 /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
47 /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
48 /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
49
50 /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
51 /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
52 /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
53 /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
54 /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
55 /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
56
57 /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
58 /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
59 /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
60 /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
61
62 /* $ Required_Reading */
63
64 /* ROTATION */
65
66 /* $ Keywords */
67
68 /* ROTATION, VECTOR */
69
70 /* $ Declarations */
71 /* $ Brief_I/O */
72
73 /* VARIABLE I/O DESCRIPTION */
74 /* -------- --- -------------------------------------------------- */
75 /* V I Vector to be rotated. */
76 /* AXIS I Axis of the rotation. */
77 /* THETA I Angle of rotation (radians). */
78 /* R O Result of rotating V about AXIS by THETA. */
79
80 /* $ Detailed_Input */
81
82 /* V is a 3-dimensional vector to be rotated. */
83
84 /* AXIS is the axis about which the rotation is to be */
85 /* performed. */
86
87 /* THETA is the angle through which V is to be rotated about */
88 /* AXIS. */
89
90 /* $ Detailed_Output */
91
92 /* R is the result of rotating V about AXIS by THETA. */
93 /* If AXIS is the zero vector, R = V. */
94
95 /* $ Parameters */
96
97 /* None. */
98
99 /* $ Exceptions */
100
101 /* Error free. */
102
103 /* 1) If the input axis is the zero vector R will be returned */
104 /* as V. */
105
106 /* $ Files */
107
108 /* None. */
109
110 /* $ Particulars */
111
112 /* This routine computes the result of rotating (in a right handed */
113 /* sense) the vector V about the axis represented by AXIS through */
114 /* an angle of THETA radians. */
115
116 /* If W is a unit vector parallel to AXIS, then R is given by: */
117
118 /* R = V + ( 1 - cos(THETA) ) Wx(WxV) + sin(THETA) (WxV) */
119
120 /* where "x" above denotes the vector cross product. */
121
122 /* $ Examples */
123
124 /* If AXIS = ( 0, 0, 1 ) and THETA = PI/2 then the following results */
125 /* for R will be obtained */
126
127 /* V R */
128 /* ------------- ---------------- */
129 /* ( 1, 2, 3 ) ( -2, 1, 3 ) */
130 /* ( 1, 0, 0 ) ( 0, 1, 0 ) */
131 /* ( 0, 1, 0 ) ( -1, 0, 0 ) */
132
133
134 /* If AXIS = ( 0, 1, 0 ) and THETA = PI/2 then the following results */
135 /* for R will be obtained */
136
137 /* V R */
138 /* ------------- ---------------- */
139 /* ( 1, 2, 3 ) ( 3, 2, -1 ) */
140 /* ( 1, 0, 0 ) ( 0, 0, -1 ) */
141 /* ( 0, 1, 0 ) ( 0, 1, 0 ) */
142
143
144 /* If AXIS = ( 1, 1, 1 ) and THETA = PI/2 then the following results */
145 /* for R will be obtained */
146
147 /* V R */
148 /* ----------------------------- ----------------------------- */
149 /* ( 1.0, 2.0, 3.0 ) ( 2.577.., 0.845.., 2.577.. ) */
150 /* ( 2.577.., 0.845.., 2.577.. ) ( 3.0 2.0, 1.0 ) */
151 /* ( 3.0 2.0, 1.0 ) ( 1.422.., 3.154.., 1.422.. ) */
152 /* ( 1.422.., 3.154.., 1.422.. ) ( 1.0 2.0, 3.0 ) */
153
154
155 /* $ Restrictions */
156
157 /* None. */
158
159 /* $ Author_and_Institution */
160
161 /* N.J. Bachman (JPL) */
162 /* H.A. Neilan (JPL) */
163 /* W.L. Taber (JPL) */
164
165 /* $ Literature_References */
166
167 /* None. */
168
169 /* $ Version */
170
171 /* - SPICELIB Version 1.0.2, 5-FEB-2003 (NJB) */
172
173 /* Header examples were corrected. Exceptions section */
174 /* filled in. Miscellaneous header corrections were made. */
175
176 /* - SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
177
178 /* Comment section for permuted index source lines was added */
179 /* following the header. */
180
181 /* - SPICELIB Version 1.0.0, 31-JAN-1990 (WLT) */
182
183 /* -& */
184 /* $ Index_Entries */
185
186 /* vector rotation about an axis */
187
188 /* -& */
189 /* $ Revisions */
190
191 /* - Beta Version 1.1.0, 17-FEB-1989 (HAN) (NJB) */
192
193 /* Contents of the Exceptions section was changed */
194 /* to "error free" to reflect the decision that the */
195 /* module will never participate in error handling. */
196 /* Also, the declarations of the unused variable I and the */
197 /* unused function VDOT were removed. */
198 /* -& */
199
200
201 /* SPICELIB functions */
202
203
204 /* Local Variables */
205
206
207 /* Just in case the user tries to rotate about the zero vector - */
208 /* check, and if so return the input vector */
209
210 if (vnorm_(axis) == 0.) {
211 moved_(v, &c__3, r__);
212 return 0;
213 }
214
215 /* Compute the unit vector that lies in the direction of the */
216 /* AXIS. Call it X. */
217
218 vhat_(axis, x);
219
220 /* Compute the projection of V onto AXIS. Call it P. */
221
222 vproj_(v, x, p);
223
224 /* Compute the component of V orthogonal to the AXIS. Call it V1. */
225
226 vsub_(v, p, v1);
227
228 /* Rotate V1 by 90 degrees about the AXIS and call the result V2. */
229
230 vcrss_(x, v1, v2);
231
232 /* Compute COS(THETA)*V1 + SIN(THETA)*V2. This is V1 rotated about */
233 /* the AXIS in the plane normal to the axis, call the result RPLANE */
234
235 c__ = cos(*theta);
236 s = sin(*theta);
237 vlcom_(&c__, v1, &s, v2, rplane);
238
239 /* Add the rotated component in the normal plane to AXIS to the */
240 /* projection of V onto AXIS (P) to obtain R. */
241
242 vadd_(rplane, p, r__);
243
244 return 0;
245 } /* vrotv_ */
246
247