head	1.4;
access;
symbols;
locks; strict;
comment	@# @;


1.4
date	2002.09.07.01.50.38;	author curt;	state Exp;
branches;
next	1.3;

1.3
date	2002.08.31.19.01.55;	author curt;	state Exp;
branches;
next	1.2;

1.2
date	2002.08.31.18.54.02;	author curt;	state Exp;
branches;
next	1.1;

1.1
date	2002.02.15.17.21.57;	author curt;	state Exp;
branches;
next	;


desc
@@


1.4
log
@Updated doxygen docs.
@
text
@<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>moonpos.cxx Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.2.16 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; </center>
<hr><h1>moonpos.cxx</h1><div class="fragment"><pre>00001 <font class="comment">/**************************************************************************</font>
00002 <font class="comment"> * moonpos.cxx</font>
00003 <font class="comment"> * Written by Durk Talsma. Originally started October 1997, for distribution  </font>
00004 <font class="comment"> * with the FlightGear project. Version 2 was written in August and </font>
00005 <font class="comment"> * September 1998. This code is based upon algorithms and data kindly </font>
00006 <font class="comment"> * provided by Mr. Paul Schlyter. (pausch@@saaf.se). </font>
00007 <font class="comment"> *</font>
00008 <font class="comment"> * This library is free software; you can redistribute it and/or</font>
00009 <font class="comment"> * modify it under the terms of the GNU Library General Public</font>
00010 <font class="comment"> * License as published by the Free Software Foundation; either</font>
00011 <font class="comment"> * version 2 of the License, or (at your option) any later version.</font>
00012 <font class="comment"> *</font>
00013 <font class="comment"> * This library is distributed in the hope that it will be useful,</font>
00014 <font class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00015 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</font>
00016 <font class="comment"> * Library General Public License for more details.</font>
00017 <font class="comment"> *</font>
00018 <font class="comment"> * You should have received a copy of the GNU Library General Public</font>
00019 <font class="comment"> * License along with this library; if not, write to the</font>
00020 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330,</font>
00021 <font class="comment"> * Boston, MA  02111-1307, USA.</font>
00022 <font class="comment"> *</font>
00023 <font class="comment"> * $Id: moonpos.cxx,v 1.7 2001/06/10 15:12:09 curt Exp $</font>
00024 <font class="comment"> **************************************************************************/</font>
00025 
00026 
00027 <font class="preprocessor">#include &lt;string.h&gt;</font>
00028 
00029 <font class="preprocessor">#include &lt;<a class="code" href="logstream_8hxx.html">simgear/debug/logstream.hxx</a>&gt;</font>
00030 
00031 <font class="preprocessor">#ifdef __BORLANDC__</font>
00032 <font class="preprocessor"></font><font class="preprocessor">#  define exception c_exception</font>
00033 <font class="preprocessor"></font><font class="preprocessor">#endif</font>
00034 <font class="preprocessor"></font><font class="preprocessor">#include &lt;math.h&gt;</font>
00035 
00036 <font class="comment">// #include &lt;FDM/flight.hxx&gt;</font>
00037 
00038 <font class="preprocessor">#include "moonpos.hxx"</font>
00039 
00040 
00041 <font class="comment">/*************************************************************************</font>
00042 <font class="comment"> * MoonPos::MoonPos(double mjd)</font>
00043 <font class="comment"> * Public constructor for class MoonPos. Initializes the orbital elements and </font>
00044 <font class="comment"> * sets up the moon texture.</font>
00045 <font class="comment"> * Argument: The current time.</font>
00046 <font class="comment"> * the hard coded orbital elements for MoonPos are passed to </font>
00047 <font class="comment"> * CelestialBody::CelestialBody();</font>
00048 <font class="comment"> ************************************************************************/</font>
00049 MoonPos::MoonPos(<font class="keywordtype">double</font> mjd) :
00050   CelestialBody(125.1228, -0.0529538083,
00051                 5.1454,    0.00000,
00052                 318.0634,  0.1643573223,
00053                 60.266600, 0.000000,
00054                 0.054900,  0.000000,
00055                 115.3654,  13.0649929509, mjd)
00056 {
00057 }
00058 
00059 MoonPos::MoonPos() :
00060   CelestialBody(125.1228, -0.0529538083,
00061                 5.1454,    0.00000,
00062                 318.0634,  0.1643573223,
00063                 60.266600, 0.000000,
00064                 0.054900,  0.000000,
00065                 115.3654,  13.0649929509)
00066 {
00067 }
00068 
00069 
00070 MoonPos::~MoonPos()
00071 {
00072 }
00073 
00074 
00075 <font class="comment">/*****************************************************************************</font>
00076 <font class="comment"> * void MoonPos::updatePosition(double mjd, Star *ourSun)</font>
00077 <font class="comment"> * this member function calculates the actual topocentric position (i.e.) </font>
00078 <font class="comment"> * the position of the moon as seen from the current position on the surface</font>
00079 <font class="comment"> * of the moon. </font>
00080 <font class="comment"> ****************************************************************************/</font>
00081 <font class="keywordtype">void</font> MoonPos::updatePosition(<font class="keywordtype">double</font> mjd, <font class="keywordtype">double</font> lst, <font class="keywordtype">double</font> lat, Star *ourSun)
00082 {
00083   <font class="keywordtype">double</font> 
00084     eccAnom, ecl, actTime,
00085     xv, yv, v, r, xh, yh, zh, xg, yg, zg, xe, ye, ze,
00086     Ls, Lm, D, F, mpar, gclat, rho, HA, g,
00087     geoRa, geoDec;
00088   
00089   updateOrbElements(mjd);
00090   actTime = sgCalcActTime(mjd);
00091 
00092   <font class="comment">// calculate the angle between ecliptic and equatorial coordinate system</font>
00093   <font class="comment">// in Radians</font>
00094   ecl = ((SGD_DEGREES_TO_RADIANS * 23.4393) - (SGD_DEGREES_TO_RADIANS * 3.563E-7) * actTime);  
00095   eccAnom = sgCalcEccAnom(M, e);  <font class="comment">// Calculate the eccentric anomaly</font>
00096   xv = a * (cos(eccAnom) - e);
00097   yv = a * (sqrt(1.0 - e*e) * sin(eccAnom));
00098   v = atan2(yv, xv);               <font class="comment">// the moon's true anomaly</font>
00099   r = sqrt (xv*xv + yv*yv);       <font class="comment">// and its distance</font>
00100   
00101   <font class="comment">// estimate the geocentric rectangular coordinates here</font>
00102   xh = r * (cos(N) * cos (v+w) - sin (N) * sin(v+w) * cos(i));
00103   yh = r * (sin(N) * cos (v+w) + cos (N) * sin(v+w) * cos(i));
00104   zh = r * (sin(v+w) * sin(i));
00105 
00106   <font class="comment">// calculate the ecliptic latitude and longitude here</font>
00107   lonEcl = atan2 (yh, xh);
00108   latEcl = atan2(zh, sqrt(xh*xh + yh*yh));
00109 
00110   <font class="comment">/* Calculate a number of perturbatioin, i.e. disturbances caused by the </font>
00111 <font class="comment">   * gravitational infuence of the sun and the other major planets.</font>
00112 <font class="comment">   * The largest of these even have a name */</font>
00113   Ls = ourSun-&gt;getM() + ourSun-&gt;getw();
00114   Lm = M + w + N;
00115   D = Lm - Ls;
00116   F = Lm - N;
00117   
00118   lonEcl += SGD_DEGREES_TO_RADIANS * (-1.274 * sin (M - 2*D)
00119                           +0.658 * sin (2*D)
00120                           -0.186 * sin(ourSun-&gt;getM())
00121                           -0.059 * sin(2*M - 2*D)
00122                           -0.057 * sin(M - 2*D + ourSun-&gt;getM())
00123                           +0.053 * sin(M + 2*D)
00124                           +0.046 * sin(2*D - ourSun-&gt;getM())
00125                           +0.041 * sin(M - ourSun-&gt;getM())
00126                           -0.035 * sin(D)
00127                           -0.031 * sin(M + ourSun-&gt;getM())
00128                           -0.015 * sin(2*F - 2*D)
00129                           +0.011 * sin(M - 4*D)
00130                           );
00131   latEcl += SGD_DEGREES_TO_RADIANS * (-0.173 * sin(F-2*D)
00132                           -0.055 * sin(M - F - 2*D)
00133                           -0.046 * sin(M + F - 2*D)
00134                           +0.033 * sin(F + 2*D)
00135                           +0.017 * sin(2*M + F)
00136                           );
00137   r += (-0.58 * cos(M - 2*D)
00138         -0.46 * cos(2*D)
00139         );
00140   <font class="comment">// SG_LOG(SG_GENERAL, SG_INFO, "Running moon update");</font>
00141   xg = r * cos(lonEcl) * cos(latEcl);
00142   yg = r * sin(lonEcl) * cos(latEcl);
00143   zg = r *               sin(latEcl);
00144   
00145   xe = xg;
00146   ye = yg * cos(ecl) -zg * sin(ecl);
00147   ze = yg * sin(ecl) +zg * cos(ecl);
00148 
00149   geoRa  = atan2(ye, xe);
00150   geoDec = atan2(ze, sqrt(xe*xe + ye*ye));
00151 
00152   <font class="comment">/* SG_LOG( SG_GENERAL, SG_INFO, </font>
00153 <font class="comment">          "(geocentric) geoRa = (" &lt;&lt; (SGD_RADIANS_TO_DEGREES * geoRa) </font>
00154 <font class="comment">          &lt;&lt; "), geoDec= (" &lt;&lt; (SGD_RADIANS_TO_DEGREES * geoDec) &lt;&lt; ")" ); */</font>
00155 
00156 
00157   <font class="comment">// Given the moon's geocentric ra and dec, calculate its </font>
00158   <font class="comment">// topocentric ra and dec. i.e. the position as seen from the</font>
00159   <font class="comment">// surface of the earth, instead of the center of the earth</font>
00160 
00161   <font class="comment">// First calculate the moon's parrallax, that is, the apparent size of the </font>
00162   <font class="comment">// (equatorial) radius of the earth, as seen from the moon </font>
00163   mpar = asin ( 1 / r);
00164   <font class="comment">// SG_LOG( SG_GENERAL, SG_INFO, "r = " &lt;&lt; r &lt;&lt; " mpar = " &lt;&lt; mpar );</font>
00165   <font class="comment">// SG_LOG( SG_GENERAL, SG_INFO, "lat = " &lt;&lt; f-&gt;get_Latitude() );</font>
00166 
00167   gclat = lat - 0.003358 * 
00168       sin (2 * SGD_DEGREES_TO_RADIANS * lat );
00169   <font class="comment">// SG_LOG( SG_GENERAL, SG_INFO, "gclat = " &lt;&lt; gclat );</font>
00170 
00171   rho = 0.99883 + 0.00167 * cos(2 * SGD_DEGREES_TO_RADIANS * lat);
00172   <font class="comment">// SG_LOG( SG_GENERAL, SG_INFO, "rho = " &lt;&lt; rho );</font>
00173   
00174   <font class="keywordflow">if</font> (geoRa &lt; 0)
00175     geoRa += (2*SGD_PI);
00176   
00177   HA = lst - (3.8197186 * geoRa);
00178   <font class="comment">/* SG_LOG( SG_GENERAL, SG_INFO, "t-&gt;getLst() = " &lt;&lt; t-&gt;getLst() </font>
00179 <font class="comment">          &lt;&lt; " HA = " &lt;&lt; HA ); */</font>
00180 
00181   g = atan (tan(gclat) / cos ((HA / 3.8197186)));
00182   <font class="comment">// SG_LOG( SG_GENERAL, SG_INFO, "g = " &lt;&lt; g );</font>
00183 
00184   rightAscension = geoRa - mpar * rho * cos(gclat) * sin(HA) / cos (geoDec);
00185   <font class="keywordflow">if</font> (fabs(lat) &gt; 0) {
00186       declination
00187           = geoDec - mpar * rho * sin (gclat) * sin (g - geoDec) / sin(g);
00188   } <font class="keywordflow">else</font> {
00189       declination = geoDec;
00190       <font class="comment">// cerr &lt;&lt; "Geocentric vs. Topocentric position" &lt;&lt; endl;</font>
00191       <font class="comment">// cerr &lt;&lt; "RA (difference)  : "</font>
00192       <font class="comment">//      &lt;&lt; SGD_RADIANS_TO_DEGREES * (geoRa - rightAscension) &lt;&lt; endl;</font>
00193       <font class="comment">// cerr &lt;&lt; "Dec (difference) : "</font>
00194       <font class="comment">//      &lt;&lt; SGD_RADIANS_TO_DEGREES * (geoDec - declination) &lt;&lt; endl;</font>
00195   }
00196 
00197   <font class="comment">/* SG_LOG( SG_GENERAL, SG_INFO, </font>
00198 <font class="comment">          "Ra = (" &lt;&lt; (SGD_RADIANS_TO_DEGREES *rightAscension) </font>
00199 <font class="comment">          &lt;&lt; "), Dec= (" &lt;&lt; (SGD_RADIANS_TO_DEGREES *declination) &lt;&lt; ")" ); */</font>
00200 }
</pre></div><hr><address align="right"><small>Generated on Fri Sep 6 20:46:34 2002 for SimGear by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 
width=110 height=53></a>1.2.16 </small></address>
</body>
</html>
@


1.3
log
@Oops, try again.
@
text
@d209 1
a209 1
</pre></div><hr><address align="right"><small>Generated on Sat Aug 31 13:59:38 2002 for SimGear by
@


1.2
log
@Regenerated doxygen files.
@
text
@d209 1
a209 1
</pre></div><hr><address align="right"><small>Generated on Sat Aug 31 13:45:09 2002 for SimGear by
@


1.1
log
@More web page updates (added doxygen docs to repository.)
@
text
@d5 2
a6 2
</head><body bgcolor="#ffffff">
<!-- Generated by Doxygen 1.2.12 -->
d209 1
a209 1
</pre></div><hr><address><small>Generated on Fri Feb 15 11:15:31 2002 for SimGear by
d211 2
a212 3
<img src="doxygen.gif" alt="doxygen" align="middle" border=0 
width=110 height=53></a>1.2.12 written by <a href="mailto:dimitri@@stack.nl">Dimitri van Heesch</a>,
 &copy;&nbsp;1997-2001</small></address>
@

