| Last change
 on this file since 3632 was             3477, checked in by cmv, 18 years ago | 
        
          | 
mise a jour Xephem 3.7.3 , cmv 25/03/2008
 | 
        
          | File size:
            1.1 KB | 
      
      
| Line |  | 
|---|
| 1 | #include <math.h> | 
|---|
| 2 | #include <stdio.h> | 
|---|
| 3 |  | 
|---|
| 4 | #include "astro.h" | 
|---|
| 5 |  | 
|---|
| 6 | /* transformation from spherical to cartesian coordinates */ | 
|---|
| 7 | void | 
|---|
| 8 | sphcart ( | 
|---|
| 9 | double l, double b, double r,           /* source: spherical coordinates */ | 
|---|
| 10 | double *x, double *y, double *z)        /* result: rectangular coordinates */ | 
|---|
| 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 | 
|---|
| 21 | cartsph ( | 
|---|
| 22 | double x, double y, double z,           /* source: rectangular coordinates */ | 
|---|
| 23 | double *l, double *b, double *r)        /* result: spherical coordinates */ | 
|---|
| 24 | { | 
|---|
| 25 | double rho = x*x + y*y; | 
|---|
| 26 |  | 
|---|
| 27 | if (rho > 0) {  /* 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 */ | 
|---|
| 43 | static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: sphcart.c,v $ $Date: 2008-03-25 17:45:20 $ $Revision: 1.7 $ $Name: not supported by cvs2svn $"}; | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.