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
astro::celestialCartToEquatorial
RA/Declination
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
Thanks,
Tim
-
- Site Admin
- Posts: 4211
- Joined: 28.01.2002
- With us: 22 years 9 months
- Location: Seattle, Washington, USA
Re: RA/Declination
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
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;
}
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;
}