Page 1 of 1

astro::celestialCartToEquatorial

Posted: 05.02.2007, 14:07
by tec
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

Posted: 05.02.2007, 15:11
by symaski62

RA/Declination

Posted: 05.02.2007, 21:01
by tec
Thanks for the link. I downloaded the celx file and tried to load it into Celestia but it crashed. Is there a specific version of Celestia that I need to import this file?

Thanks,
Tim

Re: RA/Declination

Posted: 06.02.2007, 21:35
by chris
tec wrote:Thanks for the link. I downloaded the celx file and tried to load it into Celestia but it crashed. Is there a specific version of Celestia that I need to import this file?

Thanks,
Tim


Tim, I can provide you with this function tonight . . .

--Chris

celestialCartToEquatorial

Posted: 14.02.2007, 18:04
by tec
Hello Everyone,

I wanted to share (and document) with everyone my astro method for converting cartesian coords to Equatorial. Chris walked me through the equations and fix my problem for me.

// Convert equatorial coordinates to Cartesian celestial (or ecliptical)
// coordinates.
void astro::celestialCartToEquatorial(Point3f pos, double *ra, double *dec, double *distance )
{
Point3f eq_pos = pos*equatorialToCelestial.transpose();

*distance = pos.distanceFromOrigin();

double x, y, z;
x = eq_pos.x;
y = -eq_pos.z;
z = eq_pos.y;
double phi = atan2( y, x );
double theta = asin( z/(*distance ) );
*dec = 180.0/PI*theta; // degree
// get ra in degrees
*ra = phi*(180.0/PI); // degrees
// most people use ra as positive numbers
if( (*ra) < 0.0 )
(*ra) += 360.0;
}