Last change
on this file since 1460 was 1457, checked in by cmv, 24 years ago |
import de la partie libastro de Xephem cmv+rz 10/4/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 */
|
---|
6 | void
|
---|
7 | sphcart (l, b, r, x, y, z)
|
---|
8 | double l, b, r; /* source: spherical coordinates */
|
---|
9 | double *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 */
|
---|
19 | void
|
---|
20 | cartsph (x, y, z, l, b, r)
|
---|
21 | double x, y, z; /* source: rectangular coordinates */
|
---|
22 | double *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 */
|
---|
42 | static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: sphcart.c,v $ $Date: 2001-04-10 14:40:47 $ $Revision: 1.1.1.1 $ $Name: not supported by cvs2svn $"};
|
---|
Note:
See
TracBrowser
for help on using the repository browser.