Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Orbit.cxx

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/FluxSvc/src/Orbit.cxx,v 1.12 2002/08/04 00:52:45 srobinsn Exp $
00002 
00003 #include "Orbit.h"
00004 
00005 #include "CLHEP/Random/RandFlat.h"
00006 #include "GPS.h"
00007 
00008 #include <cmath>
00009 #include <cassert>
00010 #include "CLHEP/Vector/Rotation.h"
00011 
00012 Orbit::Orbit(double asclon, double alt, double inc, double phs
00013              , double pitch , double yaw, double roll) :
00014 // constructor
00015 m_ascendingLon(asclon),
00016 m_altitude(alt),
00017 m_period(1.6612e-4 * pow(alt+6371.2, 1.5)),// Kepler's Law
00018 m_startphase(phs),
00019 m_precessPeriod(66.*24.*60.),
00020 m_degsPerRad(360./6.2831853),
00021 m_secsperday(24.*60.*60.)
00022 
00023 {
00024     inclination( inc );
00025     
00026 }
00027 
00028 void    Orbit::inclination ( double inc )
00029 {
00030     m_inclination = inc;
00031     m_sini = (sin(m_inclination*M_2PI/360.));
00032     m_cosi = (cos(m_inclination*M_2PI/360.));
00033 }
00034 
00035 void    Orbit::ascendingLon ( double asc )
00036 {
00037     m_ascendingLon = asc;
00038 }
00039 
00040 void    Orbit::startphase ( double phs )
00041 {
00042     m_startphase = phs;
00043 }
00044 
00045 double Orbit::latitude(double timeInSeconds) const {
00046     double time = timeInSeconds/60.;
00047     // Purpose:  Return the latitude as a function of time (in minutes)
00048     // Input:  the current time
00049     return (360./M_2PI) * asin(m_sini * sin(M_2PI*time/m_period + startphase()));
00050 }
00051 
00052 double Orbit::longitude(double timeInSeconds) const {
00053     double time = timeInSeconds/60.;
00054     // Purpose:  Return the longitude as a function of time, taking into account the starting
00055     // longitude and the eastward rotation of the earth
00056     // Input:  current time
00057     double phase = M_2PI * time / m_period + startphase();
00058     double lon = (360./M_2PI) * atan2(m_cosi*sin(phase), cos(phase)) -
00059         360.* time /1440. + m_ascendingLon; // orbital motion - earth rotation
00060     lon = fmod(lon, 360.);   // Fold into the range [0, 360)
00061     if (lon < 0.) lon += 360.;
00062     return lon;
00063 }
00064 
00065 double Orbit::pitch (double timeInSeconds) const {
00066     double time = timeInSeconds/60.;
00067     return 0.;
00068 }
00069 
00070 double Orbit::yaw (double timeInSeconds) const {
00071     double time = timeInSeconds/60.;
00072     return 0.;
00073 }
00074 
00075 double Orbit::roll (double timeInSeconds) const {
00076     double time = timeInSeconds/60.;
00077     return 0.;
00078 }
00079 
00080 double Orbit::phase (double timeInSeconds) const {
00081     double time = timeInSeconds/60.;
00082     double p = period();
00083     return (p == 0) ? 0. : (time/p) * 2*M_PI + startphase();
00084 }
00085 
00086 std::pair<double,double> Orbit::coords(double timeInSeconds) const {
00087     return std::make_pair(latitude(timeInSeconds), longitude(timeInSeconds));
00088 }
00089 
00090 Rotation Orbit::CELTransform(double timeInSeconds){
00091     double time = timeInSeconds/60.;
00092     // Purpose:  Return the 3x3 matrix which transforms a vector from a galactic 
00093     // coordinate system to a local coordinate system.
00094     
00095     //THIS IS THE PART WHERE WE MAKE THE MATRIX CEL INTO SOMETHING WE CAN USE
00096     Rotation gal,cel,cel1,cel2,cel3,cel4;
00097     
00098     //the x axis must eventually be rotated so that it points east, instead of along
00099     //the direction of orbital travel
00100     double makeXeast = (m_inclination/m_degsPerRad)*cos(phase(timeInSeconds));
00101     
00102     //and here we construct the rotation matrices
00103     
00104     //gal is the matrix which rotates (cartesian)celestial coordiantes into (cartesian)galactic ones
00105     gal.rotateZ(-282.25/m_degsPerRad).rotateX(-62.6/m_degsPerRad).rotateZ(33./m_degsPerRad);
00106     
00107     //cel is the matrix which rotates (cartesian)local coordinates into (cartesian)celestial ones
00108     cel1.rotateZ(makeXeast);
00109     cel2.rotateY(phase(timeInSeconds));
00110     cel3.rotateZ(-m_inclination*M_2PI/360.);
00111     cel4.rotateY((time/m_precessPeriod)*M_2PI);
00112     
00113     //so gal*cel should be the matrix that makes local coordiates into galactic ones.
00114     Rotation glstToGal = gal*cel4*cel3*cel2*cel1;
00115     
00116     //displayRotation(glstToGal);
00117     
00118     //we want the rotation from galactic to local.
00119     return glstToGal.inverse();
00120 }
00121 
00122 
00123 
00124 void Orbit::computeAttitudes(double timeInSeconds){
00125     double time = timeInSeconds/60.;
00126     // Purpose: computation of pointing characteristics of GLAST - assumed, here, to be zenith-pointing
00127     
00128     //lat, lon, sidereal??? time becomes J2000.0 coordinates here:
00129     m_raz=((time/(24.0*60.0*60.0))*360.0)+longitude(timeInSeconds);  //need to take into account starting phase too!
00130     if(m_raz > 360.0) m_raz-=360.0;
00131     if(m_raz < 0.0 ) m_raz+=360.0;
00132     m_decz=latitude(timeInSeconds);
00133     //and then the eastward-pointing x-axis should have 90 degrees more ascension, and declination=0
00134     m_rax=m_raz-90.0;
00135     if(m_rax > 360.0) m_rax-=360.0;
00136     if(m_rax < 0.0 ) m_rax+=360.0;
00137     m_decx=0.;
00138 }
00139 
00140 
00141 //NEEDS TO BE CHECKED, since CELTransform has changed.
00142 Rotation Orbit::latLonTransform(double timeInSeconds) const {
00143     double time = timeInSeconds/60.;
00144     Rotation CELtoLOC;  
00145     
00146     CELtoLOC.rotateZ(phase(timeInSeconds)).rotateX(m_inclination*M_2PI/360.).rotateZ((timeInSeconds/m_precessPeriod)*M_2PI);
00147     Rotation getLatLon=(CELtoLOC).rotateZ(((m_ascendingLon/360.)+((time)/1440.))*M_2PI*-1.);
00148     
00149     return getLatLon;
00150 }
00151 
00152 //NEEDS TO BE CHECKED
00153 double Orbit::testLongitude(double timeInSeconds) const {
00154     double time = timeInSeconds/60.;
00155     // longitude as a function of time (in minutes)
00156     Vector v(1.,0,0);
00157     v=latLonTransform(time)*v;
00158     double lon = (360./M_2PI) * atan(v[1]/v[0]);
00159     lon = fmod(lon, 360.);   // Fold into the range [0, 360)
00160     if (lon < 0.) lon += 360.;
00161     return lon;
00162 }
00163 
00164 //NEEDS FIXING
00165 double Orbit::testLatitude(double timeInSeconds) const {
00166     // latitude as a function of time (in minutes)
00167     Vector v(1.,0,0);
00168     v=latLonTransform(timeInSeconds)*v;
00169     return (360./M_2PI) * atan(v[2]/sqrt(pow(v[0],2)+pow(v[1],2)));
00170 }
00171 
00172 
00173 
00174 void Orbit::displayRotation(Rotation rot){
00175     
00176     std::cout << "{" << rot.xx() << ' ' << rot.xy() << ' ' << rot.xz() << std::endl
00177         << rot.yx() << ' ' << rot.yy() << ' ' << rot.yz() << std::endl
00178         << rot.zx() << ' ' << rot.zy() << ' ' << rot.zz() << "}" << std::endl;
00179 }

Generated on Wed Oct 16 14:01:30 2002 by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001