source: Sophya/trunk/SophyaExt/XephemAstroLib/sphcart.c@ 1783

Last change on this file since 1783 was 1719, checked in by cmv, 24 years ago

Adapted to version 3.5 xephem cmv 22/10/2001

File size: 1.1 KB
Line 
1#include <math.h>
2#include "P_.h"
3#include "astro.h"
4
5/* transformation from spherical to cartesian coordinates */
6void
7sphcart (l, b, r, x, y, z)
8double l, b, r; /* source: spherical coordinates */
9double *x, *y, *z; /* result: rectangular coordinates */
10{
11 double rcb = r * cos(b);
12
13 *x = rcb * cos(l);
14 *y = rcb * sin(l);
15 *z = r * sin(b);
16}
17
18/* transformation from cartesian to spherical coordinates */
19void
20cartsph (x, y, z, l, b, r)
21double x, y, z; /* source: rectangular coordinates */
22double *l, *b, *r; /* result: spherical coordinates */
23{
24 double rho = x*x + y*y;
25
26 if (rho > 1e-35) { /* standard case: off axis */
27 *l = atan2(y, x);
28 range (l, 2*PI);
29 *b = atan2(z, sqrt(rho));
30 *r = sqrt(rho + z*z);
31 } else { /* degenerate case; avoid math error */
32 *l = 0.0;
33 if (z == 0.0)
34 *b = 0.0;
35 else
36 *b = (z > 0.0) ? PI/2. : -PI/2.;
37 *r = fabs(z);
38 }
39}
40
41/* For RCS Only -- Do Not Edit */
42static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: sphcart.c,v $ $Date: 2001-10-22 12:08:28 $ $Revision: 1.2 $ $Name: not supported by cvs2svn $"};
Note: See TracBrowser for help on using the repository browser.