| 
            Last change
 on this file since 3264 was             3111, checked in by cmv, 19 years ago           | 
        
        
          | 
             
mise en conformite xephem 3.7.2    cmv 22/11/2006 
 
           | 
        
        
          | 
            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 | 
 | 
|---|
| [3111] | 27 |         if (rho > 0) {  /* standard case: off axis */
 | 
|---|
| [1457] | 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 */
 | 
|---|
| [3111] | 43 | static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: sphcart.c,v $ $Date: 2006-11-22 13:53:31 $ $Revision: 1.6 $ $Name: not supported by cvs2svn $"};
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.