00001
00002
00003
00004 #include "astro/EarthCoordinate.h"
00005
00006 namespace {
00007
00008 double EarthFlat= (1/298.25);
00009 double J2000= astro::JulianDate(2000,1,1,12);
00010
00011 inline double sqr(double x){return x*x;}
00012 }
00013
00014
00015 namespace astro {
00016 double EarthCoordinate::s_EarthRadius = 6378145.;
00017
00018
00019
00020 EarthCoordinate::EarthCoordinate(Hep3Vector pos, JulianDate jd)
00021 {
00022 m_lat = M_PI/2- pos.theta();
00023 double GMST0 = GetGMST(jd);
00024 m_lon = GetGMST(jd)*M_PI/180 - pos.phi();
00025 m_lon = fmod(m_lon, 2*M_PI); if(m_lon>M_PI) m_lon -= 2*M_PI;
00026
00027
00028 m_lat=(atan(tan(m_lat))/(sqr(1.-EarthFlat)) );
00029
00030
00031
00032
00033 m_altitude=sqrt(sqr(pos.x())+sqr(pos.y())/cos(m_lat) )
00034 -s_EarthRadius / (1000.*sqrt(1.-sqr(0.00669454*sin(m_lat))));
00035
00036 }
00037
00038
00039 EarthCoordinate::EarthCoordinate(double latDeg, double lonDeg, double alt)
00040 : m_lat(latDeg*M_PI/180), m_lon(lonDeg*M_PI/180), m_altitude(alt)
00041 {}
00042
00043
00044 double EarthCoordinate::GetGMST(JulianDate jd)
00045 {
00046 double J_D=jd;
00047 double M, Ora_Un_Dec=modf(J_D-0.5,&M)*24; J_D-=Ora_Un_Dec/24;
00048 double T = (J_D - J2000) / 36525.;
00049 double T1 = (24110.54841 + 8640184.812866 * T + 0.0093103 * T * T)/86400.0;
00050 double Tempo_Siderale_0 = modf(T1,&M) * 24.;
00051 double Tempo_Siderale_Ora = Tempo_Siderale_0 + Ora_Un_Dec * 1.00273790935;
00052 if (Tempo_Siderale_Ora < 0.) Tempo_Siderale_Ora = Tempo_Siderale_Ora + 24.;
00053 if (Tempo_Siderale_Ora >= 24.) Tempo_Siderale_Ora = Tempo_Siderale_Ora - 24.;
00054 return Tempo_Siderale_Ora*15.;
00055 }
00056
00057 bool EarthCoordinate::insideSAA()const
00058 {
00059 double perim[7][2] = {{-88.,-30.},{-88.,-12.},{-55.,-0.1},{-32.,-0.1},{-7,-12},
00060 {50.,-25},{50.,-30.}};
00061 double longmin=-88;
00062 double longmax=50.;
00063 double latmin=-30;
00064 double latmax=-0.1;
00065 double diffx[7],diffy[7],diffd[7];
00066 double lon=longitude(), lat=latitude();
00067 if((lon>=longmin)&&(lon<=longmax)&&(lat>=latmin)&&(lat<=latmax)){
00068 for (int i=0;i<6;i++){
00069 diffx[i]=perim[i+1][0]-perim[i][0];
00070 diffy[i]=perim[i+1][1]-perim[i][1];
00071
00072 }
00073 diffx[6]=perim[0][0]-perim[6][0];
00074 diffy[6]=perim[0][1]-perim[6][1];
00075
00076 for (i=0;i<7;i++){
00077 diffd[i]=sqrt(sqr(diffx[i])+sqr(diffy[i]));
00078 }
00079 double xnew[7],ynew[7];
00080 int inside[7];
00081 int xtemp[7],txtemp=0,tins=0;
00082 for (i=0;i<7;i++){
00083 xnew[i]=((lon-perim[i][0])*diffx[i]+(lat-perim[i][1])*diffy[i])/diffd[i];
00084 ynew[i]=(lat-perim[i][1])*diffx[i]-(lon-perim[i][0])*diffy[i];
00085 xtemp[i]=((xnew[i] >=0.)&&(xnew[i]<=diffd[i]));
00086 inside[i]=(xtemp[i] == 1) && (ynew[i]<0.);
00087 txtemp+=xtemp[i];
00088 tins+=inside[i];
00089
00090 }
00091 bool insaa=(txtemp==tins)&&(txtemp >0);
00092
00093 return insaa;
00094 }
00095 else
00096 return false;
00097 }
00098
00099 }