home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 341_01 / enu.c < prev    next >
Text File  |  1991-02-26  |  2KB  |  85 lines

  1. /*
  2. HEADER:       enu.c        
  3. TITLE:        Convert between eccentric and tru anomaly.         
  4. VERSION:      1.0    
  5. DESCRIPTION:  This routine converts eccentric to true anomaly and vice
  6.               versa.  To convert eccentric to true anomaly, inputs
  7.               are eccentric anomaly, eccentricity, and the input switch
  8.               is set to 1.  To convert true to eccentric anomaly, inputs
  9.               are true anomaly, eccentricity, and the input switch is set
  10.               to zero.  Input and output anomalies are in degrees.
  11. KEYWORDS:     Astrodynamics, orbital mechanics, Kepler's equation
  12. SYSTEM:       MS-DOS, PC-DOS (Coded with Ver. 3.3, but should be version
  13.               independent)         
  14. FILENAME:     enu.c    
  15. WARNINGS:      This routine was coded for educational purposes, using
  16.               the method given in the reference.  No attempt has been made
  17.               to insure optimal numerical stability or optimal convergence
  18.               rate.
  19. SEE-ALSO:     ---    
  20. AUTHORS:      Rodney Long
  21.               19003 Swan Drive
  22.               Gaithersburg, MD 20879     
  23. COMPILERS:    Microsoft C 5.1    
  24. REFERENCE:    Bate, Mueller, White: Fundamentals of Astrodynamics
  25. */
  26.  
  27. #include <stdio.h>
  28. #include <float.h>
  29. #include <math.h>
  30. #include "orbcons.h"
  31.  
  32. double enu();
  33.  
  34. main()
  35.  
  36. {
  37.   double x,w;
  38.   double e;
  39.   int i;
  40.  
  41.   x = 302.4241917;
  42.   e = .00006769996759;
  43.  
  44.   printf("Inputs: \n");
  45.   printf("    x = %25.16lf\n",x);
  46.   printf("    e = %25.16lf\n",e);
  47.   printf("    i = 1\n");
  48.   w = enu(x,e,1);
  49.  
  50.   printf("output true anomaly      = %25.16lf \n",w);
  51.  
  52.   x = w;
  53.   printf("Inputs: \n");
  54.   printf("    x = %25.16lf\n",x);
  55.   printf("    e = %25.16lf\n",e);
  56.   printf("    i = 0\n");
  57.  
  58.   w = enu(x,e,0);
  59.  
  60.   printf("output eccentric anomaly = %25.16lf \n",w);
  61.  
  62. }
  63.   
  64.  
  65. double enu(double x, double e, int i)
  66.  
  67. {
  68.  
  69.   double cosy,y;
  70.  
  71.   x = x * DTR;
  72.   if (i) {
  73.     // Convert eccen to true anomaly
  74.     cosy = (e - cos(x))/(e*cos(x) - 1);
  75.   } else {
  76.     // Convert true to eccen anomaly
  77.     cosy = (e + cos(x))/(1+e*cos(x));
  78.   }
  79.   y = acos(cosy);     // y is 0 to pi
  80.   if (x > PI)
  81.     y = TWOPI - y;
  82.   return(y*RTD);
  83.  
  84. }
  85.