| 
            Last change
 on this file since 3891 was             3654, checked in by cmv, 16 years ago           | 
        
        
          | 
             
mise a niveau Xephem 3.7.4, cmv 16/07/2009 
 
           | 
        
        
          | 
            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: 2009-07-16 10:34:39 $ $Revision: 1.8 $ $Name: not supported by cvs2svn $"};
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.