00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "space/astronomy.hpp"
00035
00036 #include <cmath>
00037
00038 using namespace gsgl::math;
00039
00040 namespace periapsis
00041 {
00042
00043 namespace space
00044 {
00045
00046 double J2000 = 2451545.0;
00047
00048
00049
00050
00051 static gsgl::real_t eq_wrt_gal_pre_mult[] =
00052 {
00053 -0.0548755604f,
00054 -0.8734370902f,
00055 -0.4838350155f,
00056 0.0f,
00057
00058 0.4941094279f,
00059 -0.4448296300f,
00060 0.7469822445f,
00061 0.0f,
00062
00063 -0.8676661490f,
00064 -0.1980763734f,
00065 0.4559837762f,
00066 0.0f,
00067
00068 0.0f,
00069 0.0f,
00070 0.0f,
00071 1.0f
00072 };
00073
00074
00075 transform GALACTIC_WRT_EQUATORIAL(eq_wrt_gal_pre_mult);
00076 transform EQUATORIAL_WRT_GALACTIC = GALACTIC_WRT_EQUATORIAL.transpose();
00077
00078
00079
00080
00081 gsgl::real_t eq_wrt_ec_pre_mult[] =
00082 {
00083 1.0f,
00084 0.0f,
00085 0.0f,
00086 0.0f,
00087
00088 0.0f,
00089 0.9174820621f,
00090 0.3977771559f,
00091 0.0f,
00092
00093 0.0f,
00094 -0.3977771559f,
00095 0.9174820621f,
00096 0.0f,
00097
00098 0.0f,
00099 0.0f,
00100 0.0f,
00101 1.0f
00102 };
00103
00104
00105 transform ECLIPTIC_WRT_EQUATORIAL(eq_wrt_ec_pre_mult);
00106 transform EQUATORIAL_WRT_ECLIPTIC = ECLIPTIC_WRT_EQUATORIAL.transpose();
00107
00108
00109
00110
00111 transform ECLIPTIC_WRT_GALACTIC = EQUATORIAL_WRT_GALACTIC * ECLIPTIC_WRT_EQUATORIAL;
00112 transform GALACTIC_WRT_ECLIPTIC = ECLIPTIC_WRT_GALACTIC.transpose();
00113
00114
00115
00116
00117 void geocentric_to_geographic(const gsgl::real_t & polar_radius, const gsgl::real_t & equatorial_radius,
00118 const gsgl::real_t & x, const gsgl::real_t & y, const gsgl::real_t & z,
00119 gsgl::real_t & lat, gsgl::real_t & lon, gsgl::real_t & alt)
00120 {
00121 gsgl::real_t a = equatorial_radius;
00122 gsgl::real_t b = polar_radius;
00123
00124 gsgl::real_t e = ::sqrt(a*a - b*b) / a;
00125 gsgl::real_t phi = 0.0;
00126 gsgl::real_t N;
00127 gsgl::real_t h;
00128 gsgl::real_t sinphi;
00129
00130 for (int i = 0; i < 10; ++i)
00131 {
00132 sinphi = ::sin(phi);
00133 N = a / ::sqrt((gsgl::real_t) 1.0 - e*e*sinphi*sinphi);
00134 h = ::sqrt(x*x + y*y) / cos(phi) - N;
00135 phi = ::atan( (z + e*e*N*sinphi) / ::sqrt(x*x + y*y) );
00136 }
00137
00138 lat = phi;
00139 lon = ::atan2(y, x);
00140 alt = x / (::cos(lon) * ::cos(lat)) - N;
00141 }
00142
00143
00144 void geographic_to_geocentric(const gsgl::real_t & polar_radius, const gsgl::real_t & equatorial_radius,
00145 const gsgl::real_t & lat, const gsgl::real_t & lon, const gsgl::real_t & alt,
00146 gsgl::real_t & x, gsgl::real_t & y, gsgl::real_t & z)
00147 {
00148 gsgl::real_t a = equatorial_radius;
00149 gsgl::real_t b = polar_radius;
00150
00151 gsgl::real_t phi = lat;
00152 gsgl::real_t lambda = lon;
00153 gsgl::real_t h = alt;
00154
00155 gsgl::real_t e = ::sqrt(a*a - b*b) / a;
00156 gsgl::real_t sinphi = ::sin(phi);
00157 gsgl::real_t N = a / ::sqrt((gsgl::real_t) 1.0 - e*e*sinphi*sinphi);
00158
00159 x = (N + h) * ::cos(phi) * ::cos(lambda);
00160 y = (N + h) * ::cos(phi) * ::sin(lambda);
00161 z = (N * ((gsgl::real_t) 1.0 - e*e) + h) * ::sin(phi);
00162 }
00163
00164 }
00165
00166 }