Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

Moon.cpp

Go to the documentation of this file.
00001 /*
00002  * Moon.cpp
00003  *
00004  * Part of Fly! Legacy project
00005  *
00006  * Copyright 2003 Chris Wallace
00007  *
00008  * Fly! Legacy is free software; you can redistribute it and/or modify
00009  *   it under the terms of the GNU General Public License as published by
00010  *   the Free Software Foundation; either version 2 of the License, or
00011  *   (at your option) any later version.
00012  *
00013  * Fly! Legacy is distributed in the hope that it will be useful,
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  *   GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  *   along with Fly! Legacy; if not, write to the Free Software
00020  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  */
00023 
00031 #include <math.h>
00032 #include "../Include/Ephemeris.h"
00033 #include "../Include/Utility.h"
00034 
00035 
00036 // Default orbital elements
00037 static SOrbitalElements first =
00038 {
00039   125.1228,   // N, Longitude of the ascending node
00040   5.1454,     // i, Inclination to the ecliptic
00041   318.0634,   // w, Argument of perihelion
00042   60.266600,    // a, Semi-major axis
00043   0.054900,   // e, Eccentricity
00044   115.3654    // M, Mean anomaly
00045 };
00046 
00047 static SOrbitalElements second =
00048 {
00049   -0.0529538083,  // N, Longitude of the ascending node
00050   0.0,      // i, Inclination to the ecliptic
00051   0.1643573223, // w, Argument of perihelion
00052   0.0,      // a, Semi-major axis
00053   0.0,      // e, Eccentricity
00054   13.0649929509 // M, Mean anomaly
00055 };
00056 
00057 
00058 /*************************************************************************
00059  * CMoon::CMoon(double mjd)
00060  * Public constructor for class CMoon. Initializes the orbital elements
00061  * Argument: The current time.
00062  * the hard coded default orbital elements for CMoon are passed to 
00063  * CelestialBody::CelestialBody();
00064  ************************************************************************/
00065 CMoon::CMoon(double mjd) :
00066   CCelestialBody (first.N, first.i, first.w, first.a, first.e, first.M,
00067                 second.N, second.i, second.w, second.a, second.e, second.M,
00068           mjd)
00069 {
00070 }
00071 
00072 CMoon::CMoon() :
00073   CCelestialBody (first.N, first.i, first.w, first.a, first.e, first.M,
00074                 second.N, second.i, second.w, second.a, second.e, second.M)
00075 {
00076 }
00077 
00078 CMoon::~CMoon()
00079 {
00080 }
00081 
00082 
00083 /*****************************************************************************
00084  * void CMoon::updatePosition(double mjd, CSol *ourSun)
00085  * this member function calculates the actual topocentric position (i.e.) 
00086  * the position of the moon as seen from the current position on the surface
00087  * of the earth.
00088  ****************************************************************************/
00089 void CMoon::UpdatePosition (double mjd, double lst, double lat, CSol *ourSun)
00090 {
00091   // Update orbital elements
00092   double 
00093     eccAnom, ecl, actTime,
00094     xv, yv, v, r, xh, yh, zh, xg, yg, zg, xe, ye, ze,
00095     Ls, Lm, D, F, mpar, gclat, rho, HA, g,
00096     geoRa, geoDec;
00097   
00098   UpdateOrbElements(mjd);
00099   actTime = CalcActTime(mjd);
00100 
00101   // calculate the angle between ecliptic and equatorial coordinate system
00102   // in Radians
00103   ecl = ((SGD_DEGREES_TO_RADIANS * 23.4393) - (SGD_DEGREES_TO_RADIANS * 3.563E-7) * actTime);  
00104   eccAnom = CalcEccAnom(M, e);  // Calculate the eccentric anomaly
00105   xv = a * (cos(eccAnom) - e);
00106   yv = a * (sqrt(1.0 - e*e) * sin(eccAnom));
00107   v = atan2(yv, xv);               // the moon's true anomaly
00108   r = sqrt (xv*xv + yv*yv);       // and its distance
00109   
00110   // estimate the geocentric rectangular coordinates here
00111   xh = r * (cos(N) * cos (v+w) - sin (N) * sin(v+w) * cos(i));
00112   yh = r * (sin(N) * cos (v+w) + cos (N) * sin(v+w) * cos(i));
00113   zh = r * (sin(v+w) * sin(i));
00114 
00115   // calculate the ecliptic latitude and longitude here
00116   lonEcl = atan2 (yh, xh);
00117   latEcl = atan2(zh, sqrt(xh*xh + yh*yh));
00118 
00119   /* Calculate a number of perturbatioin, i.e. disturbances caused by the 
00120    * gravitational infuence of the sun and the other major planets.
00121    * The largest of these even have a name */
00122   Ls = ourSun->getM() + ourSun->getw();
00123   Lm = M + w + N;
00124   D = Lm - Ls;
00125   F = Lm - N;
00126   
00127   lonEcl += SGD_DEGREES_TO_RADIANS * (-1.274 * sin (M - 2*D)
00128         +0.658 * sin (2*D)
00129         -0.186 * sin(ourSun->getM())
00130         -0.059 * sin(2*M - 2*D)
00131         -0.057 * sin(M - 2*D + ourSun->getM())
00132         +0.053 * sin(M + 2*D)
00133         +0.046 * sin(2*D - ourSun->getM())
00134         +0.041 * sin(M - ourSun->getM())
00135         -0.035 * sin(D)
00136         -0.031 * sin(M + ourSun->getM())
00137         -0.015 * sin(2*F - 2*D)
00138         +0.011 * sin(M - 4*D)
00139         );
00140   latEcl += SGD_DEGREES_TO_RADIANS * (-0.173 * sin(F-2*D)
00141         -0.055 * sin(M - F - 2*D)
00142         -0.046 * sin(M + F - 2*D)
00143         +0.033 * sin(F + 2*D)
00144         +0.017 * sin(2*M + F)
00145         );
00146   r += (-0.58 * cos(M - 2*D)
00147   -0.46 * cos(2*D)
00148   );
00149 
00150   xg = r * cos(lonEcl) * cos(latEcl);
00151   yg = r * sin(lonEcl) * cos(latEcl);
00152   zg = r *               sin(latEcl);
00153   
00154   xe = xg;
00155   ye = yg * cos(ecl) -zg * sin(ecl);
00156   ze = yg * sin(ecl) +zg * cos(ecl);
00157 
00158   geoRa  = atan2(ye, xe);
00159   geoDec = atan2(ze, sqrt(xe*xe + ye*ye));
00160 
00161   // Given the moon's geocentric ra and dec, calculate its 
00162   // topocentric ra and dec. i.e. the position as seen from the
00163   // surface of the earth, instead of the center of the earth
00164 
00165   // First calculate the moon's parallax, that is, the apparent size of the 
00166   // (equatorial) radius of the earth, as seen from the moon 
00167   mpar = asin ( 1 / r);
00168 
00169   gclat = lat - 0.003358 * 
00170       sin (2 * SGD_DEGREES_TO_RADIANS * lat );
00171 
00172   rho = 0.99883 + 0.00167 * cos(2 * SGD_DEGREES_TO_RADIANS * lat);
00173   
00174   if (geoRa < 0)
00175     geoRa += (2*SGD_PI);
00176   
00177   HA = lst - (3.8197186 * geoRa);
00178 
00179   g = atan (tan(gclat) / cos ((HA / 3.8197186)));
00180 
00181   rightAscension = geoRa - mpar * rho * cos(gclat) * sin(HA) / cos (geoDec);
00182   if (fabs(lat) > 0) {
00183       declination
00184     = geoDec - mpar * rho * sin (gclat) * sin (g - geoDec) / sin(g);
00185   } else {
00186       declination = geoDec;
00187   }
00188 
00189   // Update age (days since last new moon)
00190   age = LUNATION_DAYS * WrapTwoPi (GetLon() - ourSun->GetLon()) / (SGD_PI * 2);
00191 }
00192 
00193 
00194 float CMoon::GetAge (void)
00195 {
00196   return age;
00197 }
00198 
00199 /**************************************************************************
00200  * moonpos.cxx
00201  * Written by Durk Talsma. Originally started October 1997, for distribution  
00202  * with the FlightGear project. Version 2 was written in August and 
00203  * September 1998. This code is based upon algorithms and data kindly 
00204  * provided by Mr. Paul Schlyter. (pausch@saaf.se). 
00205  *
00206  * This library is free software; you can redistribute it and/or
00207  * modify it under the terms of the GNU Library General Public
00208  * License as published by the Free Software Foundation; either
00209  * version 2 of the License, or (at your option) any later version.
00210  *
00211  * This library is distributed in the hope that it will be useful,
00212  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00213  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00214  * Library General Public License for more details.
00215  *
00216  * You should have received a copy of the GNU Library General Public
00217  * License along with this library; if not, write to the
00218  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00219  * Boston, MA  02111-1307, USA.
00220  *
00221  **************************************************************************/
00222 
SourceForge.net Logo Documentation generated by doxygen