1 /* ucrss.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 /* $Procedure      UCRSS ( Unitized cross product, 3x3 ) */
ucrss_(doublereal * v1,doublereal * v2,doublereal * vout)9 /* Subroutine */ int ucrss_(doublereal *v1, doublereal *v2, doublereal *vout)
10 {
11     /* System generated locals */
12     doublereal d__1, d__2;
13 
14     /* Local variables */
15     doublereal vmag, maxv1, maxv2;
16     extern doublereal vnorm_(doublereal *);
17     doublereal vcross[3], tv1[3], tv2[3];
18 
19 /* $ Abstract */
20 
21 /*      Compute the normalized cross product of two 3-vectors. */
22 
23 /* $ Disclaimer */
24 
25 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
26 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
27 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
28 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
29 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
30 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
31 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
32 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
33 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
34 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
35 
36 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
37 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
38 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
39 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
40 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
41 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
42 
43 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
44 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
45 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
46 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
47 
48 /* $ Required_Reading */
49 
50 /*     None. */
51 
52 /* $ Keywords */
53 
54 /*      VECTOR */
55 
56 /* $ Declarations */
57 /* $ Brief_I/O */
58 
59 /*      VARIABLE  I/O  DESCRIPTION */
60 /*      --------  ---  -------------------------------------------------- */
61 /*       V1        I     Left vector for cross product. */
62 /*       V2        I     Right vector for cross product. */
63 /*       VOUT      O     Normalized cross product (V1xV2) / |V1xV2|. */
64 
65 /* $ Detailed_Input */
66 
67 /*      V1   A 3-vector. */
68 
69 /*      V2   A 3-vector. */
70 
71 /* $ Detailed_Output */
72 
73 /*      VOUT is the result of the computation (V1xV2)/|V1xV2| */
74 
75 /* $ Parameters */
76 
77 /*      None. */
78 
79 /* $ Particulars */
80 
81 /*      None. */
82 
83 /* $ Examples */
84 
85 /*      To get a unit normal to the plane spanned by two vectors */
86 /*      V1 and V2. Simply call */
87 
88 /*         CALL UCRSS ( V1, V2, NORMAL ) */
89 
90 /* $ Restrictions */
91 
92 /*      None. */
93 
94 /* $ Exceptions */
95 
96 /*     Error free. */
97 
98 /*     1) If the cross product of V1 and V2 yields the zero-vector, then */
99 /*        the zero-vector is returned instead of a vector of unit length. */
100 
101 /* $ Files */
102 
103 /*      None. */
104 
105 /* $ Author_and_Institution */
106 
107 /*      W.M. Owen       (JPL) */
108 /*      W.L. Taber      (JPL) */
109 
110 /* $ Literature_References */
111 
112 /*      None */
113 
114 /* $ Version */
115 
116 /* -    SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
117 
118 /*        Comment section for permuted index source lines was added */
119 /*        following the header. */
120 
121 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (WMO) */
122 
123 /* -& */
124 /* $ Index_Entries */
125 
126 /*     unitized cross product */
127 
128 /* -& */
129 /* $ Revisions */
130 
131 /* -    Beta Version 1.1.0, 10-JAN-1989 (WLT) */
132 
133 /*     Error free specification added. In addition the algorithm was made */
134 /*     more robust in the sense that floating point overflows cannot */
135 /*     occur. */
136 
137 /* -& */
138 
139 /*     Get the biggest component of each of the two vectors. */
140 
141 /* Computing MAX */
142     d__1 = abs(v1[0]), d__2 = abs(v1[1]), d__1 = max(d__1,d__2), d__2 = abs(
143 	    v1[2]);
144     maxv1 = max(d__1,d__2);
145 /* Computing MAX */
146     d__1 = abs(v2[0]), d__2 = abs(v2[1]), d__1 = max(d__1,d__2), d__2 = abs(
147 	    v2[2]);
148     maxv2 = max(d__1,d__2);
149 
150 /*     Scale V1 and V2 by 1/MAXV1 and 1/MAXV2 respectively */
151 
152     if (maxv1 != 0.) {
153 	tv1[0] = v1[0] / maxv1;
154 	tv1[1] = v1[1] / maxv1;
155 	tv1[2] = v1[2] / maxv1;
156     } else {
157 	tv1[0] = 0.;
158 	tv1[1] = 0.;
159 	tv1[2] = 0.;
160     }
161     if (maxv2 != 0.) {
162 	tv2[0] = v2[0] / maxv2;
163 	tv2[1] = v2[1] / maxv2;
164 	tv2[2] = v2[2] / maxv2;
165     } else {
166 	tv2[0] = 0.;
167 	tv2[1] = 0.;
168 	tv2[2] = 0.;
169     }
170 
171 /*  Calculate the cross product of V1 and V2 */
172 
173     vcross[0] = tv1[1] * tv2[2] - tv1[2] * tv2[1];
174     vcross[1] = tv1[2] * tv2[0] - tv1[0] * tv2[2];
175     vcross[2] = tv1[0] * tv2[1] - tv1[1] * tv2[0];
176 
177 /*  Get the magnitude of VCROSS and normalize it */
178 
179     vmag = vnorm_(vcross);
180     if (vmag > 0.) {
181 	vout[0] = vcross[0] / vmag;
182 	vout[1] = vcross[1] / vmag;
183 	vout[2] = vcross[2] / vmag;
184     } else {
185 	vout[0] = 0.;
186 	vout[1] = 0.;
187 	vout[2] = 0.;
188     }
189     return 0;
190 } /* ucrss_ */
191 
192