astro::celestialCartToEquatorial

The place to discuss creating, porting and modifying Celestia's source code.
Topic author
tec
Posts: 51
Joined: 14.03.2006
With us: 18 years 8 months
Location: Huntsville, AL

astro::celestialCartToEquatorial

Post #1by tec » 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

symaski62
Posts: 610
Joined: 01.05.2004
Age: 41
With us: 20 years 6 months
Location: france, divion

Post #2by symaski62 » 05.02.2007, 15:11

windows 10 directX 12 version
celestia 1.7.0 64 bits
with a general handicap of 80% and it makes much d' efforts for the community and s' expimer, thank you d' to be understanding.

Topic author
tec
Posts: 51
Joined: 14.03.2006
With us: 18 years 8 months
Location: Huntsville, AL

RA/Declination

Post #3by tec » 05.02.2007, 21:01

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

chris
Site Admin
Posts: 4211
Joined: 28.01.2002
With us: 22 years 9 months
Location: Seattle, Washington, USA

Re: RA/Declination

Post #4by chris » 06.02.2007, 21:35

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

Topic author
tec
Posts: 51
Joined: 14.03.2006
With us: 18 years 8 months
Location: Huntsville, AL

celestialCartToEquatorial

Post #5by tec » 14.02.2007, 18:04

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;
}


Return to “Development”