00001
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
00015 m_ascendingLon(asclon),
00016 m_altitude(alt),
00017 m_period(1.6612e-4 * pow(alt+6371.2, 1.5)),
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
00048
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
00055
00056
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;
00060 lon = fmod(lon, 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
00093
00094
00095
00096 Rotation gal,cel,cel1,cel2,cel3,cel4;
00097
00098
00099
00100 double makeXeast = (m_inclination/m_degsPerRad)*cos(phase(timeInSeconds));
00101
00102
00103
00104
00105 gal.rotateZ(-282.25/m_degsPerRad).rotateX(-62.6/m_degsPerRad).rotateZ(33./m_degsPerRad);
00106
00107
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
00114 Rotation glstToGal = gal*cel4*cel3*cel2*cel1;
00115
00116
00117
00118
00119 return glstToGal.inverse();
00120 }
00121
00122
00123
00124 void Orbit::computeAttitudes(double timeInSeconds){
00125 double time = timeInSeconds/60.;
00126
00127
00128
00129 m_raz=((time/(24.0*60.0*60.0))*360.0)+longitude(timeInSeconds);
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
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
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
00153 double Orbit::testLongitude(double timeInSeconds) const {
00154 double time = timeInSeconds/60.;
00155
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.);
00160 if (lon < 0.) lon += 360.;
00161 return lon;
00162 }
00163
00164
00165 double Orbit::testLatitude(double timeInSeconds) const {
00166
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 }