1 /* 2 3 -Procedure vcrss_c ( Vector cross product, 3 dimensions ) 4 5 -Abstract 6 7 Compute the cross product of two 3-dimensional vectors. 8 9 -Disclaimer 10 11 THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE 12 CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. 13 GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE 14 ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE 15 PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" 16 TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY 17 WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A 18 PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC 19 SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE 20 SOFTWARE AND RELATED MATERIALS, HOWEVER USED. 21 22 IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA 23 BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT 24 LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, 25 INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, 26 REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE 27 REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. 28 29 RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF 30 THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY 31 CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE 32 ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. 33 34 -Required_Reading 35 36 None. 37 38 -Keywords 39 40 VECTOR 41 42 */ 43 44 #include "SpiceUsr.h" 45 #include "SpiceZmc.h" 46 #undef vcrss_c 47 48 vcrss_c(ConstSpiceDouble v1[3],ConstSpiceDouble v2[3],SpiceDouble vout[3])49 void vcrss_c ( ConstSpiceDouble v1[3], 50 ConstSpiceDouble v2[3], 51 SpiceDouble vout[3] ) 52 /* 53 54 -Brief_I/O 55 56 VARIABLE I/O DESCRIPTION 57 -------- --- -------------------------------------------------- 58 v1 I Left hand vector for cross product. 59 v2 I Right hand vector for cross product. 60 vout O Cross product v1xv2. 61 vout can overwrite either v1 or v2. 62 63 -Detailed_Input 64 65 v1 This may be any 3-dimensional vector. Typically, this 66 might represent the (possibly unit) vector to a planet, 67 sun, or a star which defines the orientation of axes of 68 some coordinate system. 69 70 v2 Ditto. 71 72 -Detailed_Output 73 74 vout This variable represents the cross product of v1 and v2. 75 vout may overwrite v1 or v2. 76 77 -Parameters 78 79 None. 80 81 -Particulars 82 83 vcrss_c calculates the three dimensional cross product of two 84 vectors according to the definition. The cross product is stored 85 in a buffer vector until the calculation is complete. Thus vout 86 may overwrite v1 or v2 without interfering with intermediate 87 computations. 88 89 If v1 and v2 are large in magnitude (taken together, their 90 magnitude surpasses the limit allow by the computer) then it may 91 be possible to generate a floating point overflow from an 92 intermediate computation even though the actual cross product 93 may be well within the range of double precision numbers. 94 vcrss_c does NOT check the magnitude of v1 or v2 to insure that 95 overflow will not occur. 96 97 -Examples 98 99 v1 v2 vout (=v1Xv2) 100 ----------------------------------------------------------------- 101 (0, 1, 0) (1, 0, 0) (0, 0, -1) 102 (5, 5, 5) (-1, -1, -1) (0, 0, 0) 103 104 -Restrictions 105 106 No checking of v1 or v2 is done to prevent floating point 107 overflow. The user is required to determine that the magnitude 108 of each component of the vectors is within an appropriate range 109 so as not to cause floating point overflow. In almost every case 110 there will be no problem and no checking actually needs to be 111 done. 112 113 -Exceptions 114 115 Error free. 116 117 -Files 118 119 None. 120 121 -Author_and_Institution 122 123 W.M. Owen (JPL) 124 E.D. Wright (JPL) 125 126 -Literature_References 127 128 None. 129 130 -Version 131 132 -CSPICE Version 1.1.0, 22-OCT-1998 (NJB) 133 134 Made input vectors const. 135 136 -CSPICE Version 1.0.1, 06-MAR-1998 (EDW) 137 138 Minor header correction. Added use of MOVED. 139 140 -CSPICE Version 1.0.0, 08-FEB-1998 (EDW) 141 142 -Index_Entries 143 144 vector cross product 145 146 -& 147 */ 148 149 { /* Begin vcrss_c */ 150 151 /* 152 Local variables 153 */ 154 155 SpiceDouble vtemp[3]; 156 157 158 /* 159 Calculate the cross product of v1 and v2, store in vtemp. 160 */ 161 162 vtemp[0] = v1[1]*v2[2] - v1[2]*v2[1]; 163 vtemp[1] = v1[2]*v2[0] - v1[0]*v2[2]; 164 vtemp[2] = v1[0]*v2[1] - v1[1]*v2[0]; 165 166 167 /* 168 Now move the result into vout. 169 */ 170 171 MOVED ( vtemp, 3, vout ); 172 173 174 } /* End vcrss_c */ 175