astro::celestialCartToEquatorial
Posted: 05.02.2007, 14:07
Hello Everyone,
I attempted to write a function in astro called celestialCartToEquatorial. It is the reverse of equatorialToCelestialCart. I need to acquire the RA and Dec of a star. I searched the forum for this topic but I was unable to find anything.
Here is my attempt.
void astro::celestialCartToEquatorial(Point3f pos, double *ra, double *dec, double *distance )
{
Point3f eq_pos = pos*equatorialToCelestial.transpose();
*distance = pos.distanceFromOrigin();
double phi = acos( eq_pos.y/(*distance) );
double theta = acos( eq_pos.x/(*distance)/sin( phi ) );
*ra = 12.0/PI*theta - 12.0; // degrees
*dec = 180.0/PI*phi + 90.0; // degrees
if( *ra > 180.0 ) *ra = 360.0 - (*ra);
if( *dec > 180.0 ) *dec = 360.0 - (*dec);
*dec = (*dec) - 180.0; // don't know why ????
}
The Declination comes out correct but the right ascension is wrong. Does anyone have this function? I basically took equatorialToCelestialCart and solved for RA and Dec.
Thanks,
Tim
I attempted to write a function in astro called celestialCartToEquatorial. It is the reverse of equatorialToCelestialCart. I need to acquire the RA and Dec of a star. I searched the forum for this topic but I was unable to find anything.
Here is my attempt.
void astro::celestialCartToEquatorial(Point3f pos, double *ra, double *dec, double *distance )
{
Point3f eq_pos = pos*equatorialToCelestial.transpose();
*distance = pos.distanceFromOrigin();
double phi = acos( eq_pos.y/(*distance) );
double theta = acos( eq_pos.x/(*distance)/sin( phi ) );
*ra = 12.0/PI*theta - 12.0; // degrees
*dec = 180.0/PI*phi + 90.0; // degrees
if( *ra > 180.0 ) *ra = 360.0 - (*ra);
if( *dec > 180.0 ) *dec = 360.0 - (*dec);
*dec = (*dec) - 180.0; // don't know why ????
}
The Declination comes out correct but the right ascension is wrong. Does anyone have this function? I basically took equatorialToCelestialCart and solved for RA and Dec.
Thanks,
Tim