/*! \fn void ln_get_ell_geo_rect_posn (struct ln_ell_orbit* orbit, double JD, struct ln_rect_posn* posn);
* \param orbit Orbital parameters of object.
* \param JD Julian day
* \param posn Position pointer to store objects position
*
* Calculate the objects rectangular geocentric position given it's orbital
* elements for the given julian day. 
*/
void ln_get_ell_geo_rect_posn (struct ln_ell_orbit* orbit, double JD, struct ln_rect_posn* posn)
{
	struct ln_rect_posn p_posn, e_posn;
	struct ln_helio_posn earth;
	
	/* elliptic helio rect coords */
	ln_get_ell_helio_rect_posn (orbit, JD, &p_posn);
	
	/* earth rect coords */
	ln_get_earth_helio_coords (JD, &earth);
	ln_get_rect_from_helio (&earth, &e_posn);

	posn->X = e_posn.X - p_posn.X;
	posn->Y = e_posn.Y - p_posn.Y;
	posn->Z = e_posn.Z - p_posn.Z;
}
/*! \fn void ln_get_par_geo_rect_posn (struct ln_par_orbit* orbit, double JD, struct ln_rect_posn* posn);
* \param orbit Orbital parameters of object.
* \param JD Julian day
* \param posn Position pointer to store objects position
*
* Calculate the objects rectangular geocentric position given it's orbital
* elements for the given julian day. 
*/
void ln_get_par_geo_rect_posn (struct ln_par_orbit* orbit, double JD, struct ln_rect_posn* posn)
{
	struct ln_rect_posn p_posn, e_posn;
	struct ln_helio_posn earth;
	
	/* parabolic helio rect coords */
	ln_get_par_helio_rect_posn (orbit, JD, &p_posn);
	
	/* earth rect coords */
	ln_get_earth_helio_coords (JD, &earth);
	
	ln_get_rect_from_helio (&earth, &e_posn);
	posn->X = p_posn.X - e_posn.X;
	posn->Y = p_posn.Y - e_posn.Y;
	posn->Z = p_posn.Z - e_posn.Z;
}
/*! \fn double ln_get_heliocentric_time_diff (double JD, struct ln_equ_posn * object)
* \param JD Julian day
* \param object Pointer to object (RA, DEC) for which heliocentric correction will be caculated
*
* \return Heliocentric correction in fraction of day
*
* Calculate heliocentric corection for object at given coordinates and on given
* date.
*/
double ln_get_heliocentric_time_diff (double JD, struct ln_equ_posn *object)
{
	double theta, ra, dec, c_dec, obliq;

	struct ln_nutation nutation;
	struct ln_helio_posn earth;

	ln_get_nutation (JD, &nutation);
	ln_get_earth_helio_coords (JD, &earth);

	theta = ln_deg_to_rad (ln_range_degrees (earth.L + 180));
	ra = ln_deg_to_rad (object->ra);
	dec = ln_deg_to_rad (object->dec);
	c_dec = cos (dec);
	obliq = ln_deg_to_rad (nutation.ecliptic);

	/* L.Binnendijk Properties of Double Stars, Philadelphia, University of Pennselvania Press, pp. 228-232, 1960 */
	return -0.0057755 * earth.R * (
		cos (theta) * cos (ra) * c_dec
		+ sin (theta) * (sin (obliq) * sin (dec) + cos (obliq) * c_dec * sin (ra)));
}