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.15 2007-12-17 15:37:11 curt Exp $ 00023 **************************************************************************/ 00024 00025 00026 #ifdef __BORLANDC__ 00027 # define exception c_exception 00028 #endif 00029 #include <math.h> 00030 00031 #include <simgear/debug/logstream.hxx> 00032 00033 #include "star.hxx" 00034 00035 00036 /************************************************************************* 00037 * Star::Star(double mjd) 00038 * Public constructor for class Star 00039 * Argument: The current time. 00040 * the hard coded orbital elements our sun are passed to 00041 * CelestialBody::CelestialBody(); 00042 * note that the word sun is avoided, in order to prevent some compilation 00043 * problems on sun systems 00044 ************************************************************************/ 00045 Star::Star(double mjd) : 00046 CelestialBody (0.000000, 0.0000000000, 00047 0.0000, 0.00000, 00048 282.9404, 4.7093500E-5, 00049 1.0000000, 0.000000, 00050 0.016709, -1.151E-9, 00051 356.0470, 0.98560025850, mjd) 00052 { 00053 distance = 0.0; 00054 } 00055 00056 Star::Star() : 00057 CelestialBody (0.000000, 0.0000000000, 00058 0.0000, 0.00000, 00059 282.9404, 4.7093500E-5, 00060 1.0000000, 0.000000, 00061 0.016709, -1.151E-9, 00062 356.0470, 0.98560025850) 00063 { 00064 distance = 0.0; 00065 } 00066 00067 Star::~Star() 00068 { 00069 } 00070 00071 00072 /************************************************************************* 00073 * void Star::updatePosition(double mjd, Star *ourSun) 00074 * 00075 * calculates the current position of our sun. 00076 *************************************************************************/ 00077 void Star::updatePosition(double mjd) 00078 { 00079 double 00080 actTime, eccAnom, 00081 xv, yv, v, r, 00082 xe, ecl; 00083 00084 updateOrbElements(mjd); 00085 00086 actTime = sgCalcActTime(mjd); 00087 ecl = SGD_DEGREES_TO_RADIANS * (23.4393 - 3.563E-7 * actTime); // Angle in Radians 00088 eccAnom = sgCalcEccAnom(M, e); // Calculate the eccentric Anomaly (also known as solving Kepler's equation) 00089 00090 xv = cos(eccAnom) - e; 00091 yv = sqrt (1.0 - e*e) * sin(eccAnom); 00092 v = atan2 (yv, xv); // the sun's true anomaly 00093 distance = r = sqrt (xv*xv + yv*yv); // and its distance 00094 00095 lonEcl = v + w; // the sun's true longitude 00096 latEcl = 0; 00097 00098 // convert the sun's true longitude to ecliptic rectangular 00099 // geocentric coordinates (xs, ys) 00100 xs = r * cos (lonEcl); 00101 ys = r * sin (lonEcl); 00102 00103 // convert ecliptic coordinates to equatorial rectangular 00104 // geocentric coordinates 00105 00106 xe = xs; 00107 ye = ys * cos (ecl); 00108 ze = ys * sin (ecl); 00109 00110 // And finally, calculate right ascension and declination 00111 rightAscension = atan2 (ye, xe); 00112 declination = atan2 (ze, sqrt (xe*xe + ye*ye)); 00113 }
1.5.1