sgp4/libsgp4/Observer.cpp

66 lines
1.5 KiB
C++
Raw Normal View History

2011-12-24 00:26:41 +00:00
#include "Observer.h"
#include "CoordTopocentric.h"
2012-10-11 18:52:51 +00:00
2011-12-24 00:26:41 +00:00
/*
* calculate lookangle between the observer and the passed in Eci object
*/
CoordTopocentric Observer::GetLookAngle(const Eci &eci)
2011-12-24 00:26:41 +00:00
{
/*
* update the observers Eci to match the time of the Eci passed in
* if necessary
*/
2012-10-11 18:52:51 +00:00
Update(eci.GetDateTime());
2011-12-24 00:26:41 +00:00
/*
* calculate differences
*/
Vector range_rate = eci.Velocity() - m_eci.Velocity();
Vector range = eci.Position() - m_eci.Position();
2011-12-24 00:26:41 +00:00
range.w = range.Magnitude();
2011-12-24 00:26:41 +00:00
/*
* Calculate Local Mean Sidereal Time for observers longitude
*/
2012-10-11 18:52:51 +00:00
double theta = eci.GetDateTime().ToLocalMeanSiderealTime(m_geo.longitude);
2011-12-24 00:26:41 +00:00
2012-10-11 18:52:51 +00:00
double sin_lat = sin(m_geo.latitude);
double cos_lat = cos(m_geo.latitude);
2011-12-24 00:26:41 +00:00
double sin_theta = sin(theta);
double cos_theta = cos(theta);
double top_s = sin_lat * cos_theta * range.x
+ sin_lat * sin_theta * range.y - cos_lat * range.z;
double top_e = -sin_theta * range.x
+ cos_theta * range.y;
double top_z = cos_lat * cos_theta * range.x
+ cos_lat * sin_theta * range.y + sin_lat * range.z;
double az = atan(-top_e / top_s);
if (top_s > 0.0)
{
az += kPI;
}
if (az < 0.0)
{
az += 2.0 * kPI;
}
double el = asin(top_z / range.w);
double rate = range.Dot(range_rate) / range.w;
/*
* azimuth in radians
* elevation in radians
* range in km
* range rate in km/s
*/
return CoordTopocentric(az,
2011-12-24 00:26:41 +00:00
el,
range.w,
rate);
}