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

Last change on this file since 2818 was 2818, checked in by cmv, 20 years ago

Update de Xephem 3.7 cmv 21/08/2005

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