1 /* 2 3 -Procedure sphrec_c ( Spherical to rectangular coordinates ) 4 5 -Abstract 6 7 Convert from spherical coordinates to rectangular coordinates. 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 CONVERSION, COORDINATES 41 42 */ 43 44 #include <math.h> 45 #include "SpiceUsr.h" 46 47 sphrec_c(SpiceDouble r,SpiceDouble colat,SpiceDouble lon,SpiceDouble rectan[3])48 void sphrec_c ( SpiceDouble r, 49 SpiceDouble colat, 50 SpiceDouble lon, 51 SpiceDouble rectan[3] ) 52 53 /* 54 55 -Brief_I/O 56 57 VARIABLE I/O DESCRIPTION 58 -------- --- -------------------------------------------------- 59 r I Distance of a point from the origin. 60 colat I Angle of the point from the Z-axis in radians. 61 lon I Angle of the point from the XZ plane in radians. 62 rectan O Rectangular coordinates of the point. 63 64 -Detailed_Input 65 66 r Distance of the point from the origin. 67 68 colat Angle between the point and the positive z-axis in 69 radians. 70 71 lon Angle of the projection of the point to the XY plane from 72 the positive X-axis in radians. The positive Y-axis is 73 at longitude PI/2 radians. 74 75 -Detailed_Output 76 77 rectan The rectangular coordinates of a point. 78 79 -Parameters 80 81 None. 82 83 -Exceptions 84 85 Error free. 86 87 -Files 88 89 None. 90 91 -Particulars 92 93 This routine returns the rectangular coordinates of a point 94 whose position is input in spherical coordinates. 95 96 Spherical coordinates are defined by a distance from a central 97 reference point, an angle from a reference meridian, and an angle 98 from the z-axis. The co-latitude of the positive Z-axis is 99 zero. The longitude of the posive Y-axis is PI/2 radians. 100 101 -Examples 102 103 Below are two tables. 104 105 Listed in the first table (under r, colat and lon ) are 106 spherical coordinate triples that approximately represent points 107 whose rectangular coordinates are taken from the set {-1, 0, 1}. 108 (Angular quantities are given in degrees.) 109 110 The result of the code fragment 111 112 Use the CSPICE routine convrt_c to convert the angular 113 quantities to radians 114 115 convrt_c ( colat, "DEGREES", "RADIANS", lat ) 116 convrt_c ( lon, "DEGREES", "RADIANS", lon ) 117 118 sphrec_c ( r, colat, lon, X ) 119 120 121 are listed in the second parallel table under X(1), X(2) and X(3). 122 123 r colat lon X(1) X(2) X(3) 124 ---------------------------- -------------------------- 125 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 126 1.0000 90.0000 0.0000 1.0000 0.0000 0.0000 127 1.0000 90.0000 90.0000 0.0000 1.0000 0.0000 128 1.0000 0.0000 0.0000 0.0000 0.0000 1.0000 129 1.0000 90.0000 180.0000 -1.0000 0.0000 0.0000 130 1.0000 90.0000 -90.0000 0.0000 -1.0000 0.0000 131 1.0000 180.0000 0.0000 0.0000 0.0000 -1.0000 132 1.4142 90.0000 45.0000 1.0000 1.0000 0.0000 133 1.4142 45.0000 0.0000 1.0000 0.0000 1.0000 134 1.4142 45.0000 90.0000 0.0000 1.0000 1.0000 135 1.7320 54.7356 45.0000 1.0000 1.0000 1.0000 136 137 138 -Restrictions 139 140 None. 141 142 -Literature_References 143 144 None. 145 146 -Author_and_Institution 147 148 W.L. Taber (JPL) 149 E.D. Wright (JPL) 150 151 -Version 152 153 -CSPICE Version 1.0.1, 26-JUL-2016 (BVS) 154 155 Minor headers edits. 156 157 -CSPICE Version 1.0.0, 08-FEB-1998 (EDW) 158 159 -Index_Entries 160 161 spherical to rectangular coordinates 162 163 -& 164 */ 165 166 { /* Begin sphrec_c */ 167 168 /* 169 Local variables 170 */ 171 172 SpiceDouble x; 173 SpiceDouble y; 174 SpiceDouble z; 175 176 177 /* Function Body */ 178 179 x = r * cos( lon ) * sin( colat ); 180 y = r * sin( lon ) * sin( colat ); 181 z = r * cos( colat ); 182 183 184 /* Move the results to the output variables */ 185 186 rectan[0] = x; 187 rectan[1] = y; 188 rectan[2] = z; 189 190 191 } /* End sphrec_c */ 192