1 /* 2 3 -Procedure reccyl_c ( Rectangular to cylindrical coordinates ) 4 5 -Abstract 6 7 Convert from rectangular to cylindrical coordinates. 8 9 10 -Disclaimer 11 12 THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE 13 CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. 14 GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE 15 ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE 16 PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" 17 TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY 18 WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A 19 PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC 20 SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE 21 SOFTWARE AND RELATED MATERIALS, HOWEVER USED. 22 23 IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA 24 BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT 25 LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, 26 INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, 27 REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE 28 REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. 29 30 RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF 31 THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY 32 CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE 33 ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. 34 35 -Required_Reading 36 37 None. 38 39 -Keywords 40 41 CONVERSION, COORDINATES 42 43 */ 44 45 #include <math.h> 46 #include "SpiceUsr.h" 47 #include "SpiceZmc.h" 48 #include "SpiceZim.h" 49 #undef reccyl_c 50 51 reccyl_c(ConstSpiceDouble rectan[3],SpiceDouble * r,SpiceDouble * lon,SpiceDouble * z)52 void reccyl_c ( ConstSpiceDouble rectan[3], 53 SpiceDouble * r, 54 SpiceDouble * lon, 55 SpiceDouble * z ) 56 57 /* 58 59 -Brief_I/O 60 61 VARIABLE I/O DESCRIPTION 62 -------- --- ------------------------------------------------- 63 rectan I Rectangular coordinates of a point. 64 r O Distance of the point from Z axis. 65 lon O Angle (radians) of the point from XZ plane 66 z O Height of the point above XY plane. 67 68 -Detailed_Input 69 70 rectan Rectangular coordinates of the point of interest. 71 72 -Detailed_Output 73 74 r Distance of the point of interest from Z axis. 75 76 lon Cylindrical angle (in radians) of the point of 77 interest from XZ plane. The `lon' range is [0, 2pi]. 78 79 z Height of the point above XY plane. 80 81 -Parameters 82 83 None. 84 85 -Exceptions 86 87 Error free. 88 89 -Files 90 91 None. 92 93 -Particulars 94 95 This routine transforms the coordinates of a point from 96 rectangular to cylindrical coordinates. 97 98 -Examples 99 100 Below are two tables. 101 102 Listed in the first table (under x(1), x(2) and x(3) ) are a 103 number of points whose rectangular coordinates coorindates are 104 taken from the set {-1, 0, 1}. 105 106 The result of the code fragment 107 108 reccyl_c ( x, r, lon, z ); 109 110 Use the CSPICE routine convrt_c to convert the angular 111 quantities to degrees 112 113 convrt_c ( lon, "RADIANS", "DEGREES", lon ); 114 115 are listed to 4 decimal places in the second parallel table under 116 r (radius), lon (longitude), and z (same as rectangular z 117 coordinate). 118 119 120 x(1) x(2) x(3) r lon z 121 -------------------------- ------------------------- 122 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 123 1.0000 0.0000 0.0000 1.0000 0.0000 0.0000 124 0.0000 1.0000 0.0000 1.0000 90.0000 0.0000 125 0.0000 0.0000 1.0000 0.0000 0.0000 1.0000 126 -1.0000 0.0000 0.0000 1.0000 180.0000 0.0000 127 0.0000 -1.0000 0.0000 1.0000 270.0000 0.0000 128 0.0000 0.0000 -1.0000 0.0000 0.0000 -1.0000 129 1.0000 1.0000 0.0000 1.4142 45.0000 0.0000 130 1.0000 0.0000 1.0000 1.0000 0.0000 1.0000 131 0.0000 1.0000 1.0000 1.0000 90.0000 1.0000 132 1.0000 1.0000 1.0000 1.4142 45.0000 1.0000 133 134 -Restrictions 135 136 None. 137 138 -Literature_References 139 140 None. 141 142 -Author_and_Institution 143 144 W.L. Taber (JPL) 145 146 -Version 147 148 -CSPICE Version 1.2.1, 26-JUL-2016 (BVS) 149 150 Minor headers edits. 151 152 -CSPICE Version 1.2.0, 28-AUG-2001 (NJB) 153 154 Removed tab characters from source file. Include interface 155 macro definition header SpiceZim.h. 156 157 -CSPICE Version 1.1.0, 21-OCT-1998 (NJB) 158 159 Made input vector const. 160 161 -CSPICE Version 1.0.0, 08-FEB-1998 (EDW) 162 163 -Index_Entries 164 165 rectangular to cylindrical coordinates 166 167 -& 168 */ 169 170 { /* Begin reccyl_c */ 171 172 /* 173 Local variables 174 */ 175 176 SpiceDouble x; 177 SpiceDouble y; 178 SpiceDouble big; 179 180 181 /* Computing max absolute value of x and y components */ 182 big = MaxAbs( rectan[0], rectan[1] ); 183 184 185 /* Convert to cylindrical coordinates */ 186 187 *z = rectan[2]; 188 189 if ( big == 0.) 190 { 191 *r = 0.; 192 *lon = 0.; 193 } 194 else 195 { 196 x = rectan[0] / big; 197 y = rectan[1] / big; 198 *r = big * sqrt(x * x + y * y); 199 *lon = atan2(y, x); 200 } 201 202 if ( *lon < 0.) 203 { 204 *lon += twopi_c(); 205 } 206 207 208 } /* End reccyl_c */ 209