00001 /************************************************************************** 00002 * star.cxx 00003 * Written by Durk Talsma. Originally started October 1997, for distribution 00004 * with the FlightGear project. Version 2 was written in August and 00005 * September 1998. This code is based upon algorithms and data kindly 00006 * provided by Mr. Paul Schlyter. (pausch@saaf.se). 00007 * 00008 * This library is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Library General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2 of the License, or (at your option) any later version. 00012 * 00013 * This library 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 GNU 00016 * Library General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00021 * 00022 * $Id: star_8cxx_source.html,v 1.3 2010/02/23 22:10:16 curt Exp $ 00023 **************************************************************************/ 00024 00025 #include <math.h> 00026 00027 #include <simgear/debug/logstream.hxx> 00028 00029 #include "star.hxx" 00030 00031 00032 /************************************************************************* 00033 * Star::Star(double mjd) 00034 * Public constructor for class Star 00035 * Argument: The current time. 00036 * the hard coded orbital elements our sun are passed to 00037 * CelestialBody::CelestialBody(); 00038 * note that the word sun is avoided, in order to prevent some compilation 00039 * problems on sun systems 00040 ************************************************************************/ 00041 Star::Star(double mjd) : 00042 CelestialBody (0.000000, 0.0000000000, 00043 0.0000, 0.00000, 00044 282.9404, 4.7093500E-5, 00045 1.0000000, 0.000000, 00046 0.016709, -1.151E-9, 00047 356.0470, 0.98560025850, mjd) 00048 { 00049 distance = 0.0; 00050 } 00051 00052 Star::Star() : 00053 CelestialBody (0.000000, 0.0000000000, 00054 0.0000, 0.00000, 00055 282.9404, 4.7093500E-5, 00056 1.0000000, 0.000000, 00057 0.016709, -1.151E-9, 00058 356.0470, 0.98560025850) 00059 { 00060 distance = 0.0; 00061 } 00062 00063 Star::~Star() 00064 { 00065 } 00066 00067 00068 /************************************************************************* 00069 * void Star::updatePosition(double mjd, Star *ourSun) 00070 * 00071 * calculates the current position of our sun. 00072 *************************************************************************/ 00073 void Star::updatePosition(double mjd) 00074 { 00075 double 00076 actTime, eccAnom, 00077 xv, yv, v, r, 00078 xe, ecl; 00079 00080 updateOrbElements(mjd); 00081 00082 actTime = sgCalcActTime(mjd); 00083 ecl = SGD_DEGREES_TO_RADIANS * (23.4393 - 3.563E-7 * actTime); // Angle in Radians 00084 eccAnom = sgCalcEccAnom(M, e); // Calculate the eccentric Anomaly (also known as solving Kepler's equation) 00085 00086 xv = cos(eccAnom) - e; 00087 yv = sqrt (1.0 - e*e) * sin(eccAnom); 00088 v = atan2 (yv, xv); // the sun's true anomaly 00089 distance = r = sqrt (xv*xv + yv*yv); // and its distance 00090 00091 lonEcl = v + w; // the sun's true longitude 00092 latEcl = 0; 00093 00094 // convert the sun's true longitude to ecliptic rectangular 00095 // geocentric coordinates (xs, ys) 00096 xs = r * cos (lonEcl); 00097 ys = r * sin (lonEcl); 00098 00099 // convert ecliptic coordinates to equatorial rectangular 00100 // geocentric coordinates 00101 00102 xe = xs; 00103 ye = ys * cos (ecl); 00104 ze = ys * sin (ecl); 00105 00106 // And finally, calculate right ascension and declination 00107 rightAscension = atan2 (ye, xe); 00108 declination = atan2 (ze, sqrt (xe*xe + ye*ye)); 00109 }