|
Last change
on this file since 2631 was 2551, checked in by cmv, 21 years ago |
|
nouvelle version de xephem/libastro (3.6) cmv 15/6/04
|
|
File size:
1.1 KB
|
| Rev | Line | |
|---|
| [1457] | 1 | #include <math.h>
|
|---|
| [2551] | 2 | #include <stdio.h>
|
|---|
| 3 |
|
|---|
| [1457] | 4 | #include "astro.h"
|
|---|
| 5 |
|
|---|
| 6 | /* transformation from spherical to cartesian coordinates */
|
|---|
| 7 | void
|
|---|
| [2551] | 8 | sphcart (
|
|---|
| 9 | double l, double b, double r, /* source: spherical coordinates */
|
|---|
| 10 | double *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 */
|
|---|
| 20 | void
|
|---|
| [2551] | 21 | cartsph (
|
|---|
| 22 | double x, double y, double z, /* source: rectangular coordinates */
|
|---|
| 23 | double *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 */
|
|---|
| [2551] | 43 | static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: sphcart.c,v $ $Date: 2004-06-15 16:52:40 $ $Revision: 1.3 $ $Name: not supported by cvs2svn $"};
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.