Star catalogue: am I using the right formula to convert RA/Dec into Euler angles?

Wishbone

Clueless developer
Addon Developer
Joined
Sep 12, 2010
Messages
2,420
Reaction score
2
Points
0
Location
Moscow
Okay, please be patient with me. I'm using the formula picked up in Meeus:
Code:
lon = atan2(sin(RA)*cos(e)+tan(Dec)*sin(e),cos(RA))
lat = asin(sin(Dec)*cos(e)-cos(Dec)*sin(e)*cos(RA))

where e = 23.43 etc. is the obliquity in J2000.0, RA right ascension, Dec declination as stated in Orbiter's star marker files (Config\Sol\*.mkr)

If I use these ecliptic angles as Euler angles to point my spacecraft, I consistently end up a dozen degrees' distance away from the Orbiter-indicated position of the marker. What am I doing wrong?

TIA

EDIT: yes, I am using radians throughout :P
 
The formula look right.

If I use these ecliptic angles as Euler angles to point my spacecraft, I consistently end up a dozen degrees' distance away from the Orbiter-indicated position of the marker. What am I doing wrong?
IIRC Orbiter uses X-Y-Z convention for the Euler angles. Lat/lon is equivalent to X-(-Y')-(N/A) convention.
 
If I use these ecliptic angles as Euler angles to point my spacecraft, I consistently end up a dozen degrees' distance away from the Orbiter-indicated position of the marker. What am I doing wrong?
If I understand you right, you want to point your vessel at a star without using planetarium mode, right? I had the problem with Orbiter Galaxy, and you can read about my plight here (towards the end of the page is where the interesting stuff happens). Although it's not quite the same, because I had the stellar positions in galactic frame and my major problem was rotating themrelative to sol.

Your current problem might be that you are rotating around the wrong axis... You have a X-Y-Z rotation, and Y is the axis PERPENDICULAR to the ecliptic, while intuitivly most people assume that would be Z.

Also, the 3d-starmap homepage from project RHO has more or less the whole process of converting to sol-centered coordinates covered.
 
The axis order bug is being looked into, thanks everybody for helping out. There's one observation about coding from me: whenever I write a routine, can be sure there is at least one bug in it...
 
There's one observation about coding from me: whenever I write a routine, can be sure there is at least one bug in it...

Only one? :blink: damn, you're good!
 
Hi,
this is pretty cack-handed, but it should put your vessel Z+ axis on the required RA and Dec. Don't know if it helps. It's adapted from some code I already had hanging about - only took a few mins to change.

A lot of the terms in the rotation matrices (RG*) come out to 1 or 0 so it could be cleaned up a lot.

Code:
{

	double dec_angle = ([COLOR="Red"]insert declination angle in radians here![/COLOR]);
	double ra_angle = ([COLOR="Red"]insert right ascension angle in radians here![/COLOR]);

	////// vessel axes in equatorial frame
	VECTOR3 vessel_x = _V(1,0,0);
	VECTOR3 vessel_y = _V(0,1,0);
	VECTOR3 vessel_z = _V(0,0,1);


	

	////// create rotation matrix for rotation by declination angle
	MATRIX3 RG1;

	double ct = cos(-dec_angle);
	double st = sin(-dec_angle);

	double ux = 1;
	double uy = 0;
	double uz = 0;
	double ux2 = 1;
	double uy2 = 0;
	double uz2 = 0;

	RG1.m11 = ux2+(1-ux2)*ct;
	RG1.m12 = ux*uy*(1-ct)-uz*st;
	RG1.m13 = ux*uz*(1-ct)+uy*st;
	RG1.m21 = ux*uy*(1-ct)+uz*st;
	RG1.m22 = uy2+(1-uy2)*ct;
	RG1.m23 = uy*uz*(1-ct)-ux*st;
	RG1.m31 = ux*uz*(1-ct)-uy*st;
	RG1.m32 = uy*uz*(1-ct)+ux*st;
	RG1.m33 = uz2+(1-uz2)*ct;

	////// vessel axes after rotation by declination angle
	vessel_x = mul(RG1,vessel_x);
	vessel_y = mul(RG1,vessel_y);
	vessel_z = mul(RG1,vessel_z);



	////// create rotation matrix for rotation by right ascension angle
	MATRIX3 RG2;

	ct = cos((PI/2)-ra_angle);	////// 90 deg offset
	st = sin((PI/2)-ra_angle);	////// 90 deg offset

	ux = 0;
	uy = 1;
	uz = 0;
	ux2 = 0;
	uy2 = 1;
	uz2 = 0;

	RG2.m11 = ux2+(1-ux2)*ct;
	RG2.m12 = ux*uy*(1-ct)-uz*st;
	RG2.m13 = ux*uz*(1-ct)+uy*st;
	RG2.m21 = ux*uy*(1-ct)+uz*st;
	RG2.m22 = uy2+(1-uy2)*ct;
	RG2.m23 = uy*uz*(1-ct)-ux*st;
	RG2.m31 = ux*uz*(1-ct)-uy*st;
	RG2.m32 = uy*uz*(1-ct)+ux*st;
	RG2.m33 = uz2+(1-uz2)*ct;


	////// vessel axes after rotation by right ascension angle
	vessel_x = mul(RG2,vessel_x);
	vessel_y = mul(RG2,vessel_y);
	vessel_z = mul(RG2,vessel_z);



	////// create rotation matrix for rotation into ecliptic frame
	MATRIX3 RG3;

	double ecliptic_inc = 23.45*RAD;

	ct = cos(ecliptic_inc);
	st = sin(ecliptic_inc);

	ux = 1;
	uy = 0;
	uz = 0;
	ux2 = 1;
	uy2 = 0;
	uz2 = 0;

	RG3.m11 = ux2+(1-ux2)*ct;
	RG3.m12 = ux*uy*(1-ct)-uz*st;
	RG3.m13 = ux*uz*(1-ct)+uy*st;
	RG3.m21 = ux*uy*(1-ct)+uz*st;
	RG3.m22 = uy2+(1-uy2)*ct;
	RG3.m23 = uy*uz*(1-ct)-ux*st;
	RG3.m31 = ux*uz*(1-ct)-uy*st;
	RG3.m32 = uy*uz*(1-ct)+ux*st;
	RG3.m33 = uz2+(1-uz2)*ct;

	////// vessel axes after rotation into ecliptic frame
	vessel_x = mul(RG3,vessel_x);
	vessel_y = mul(RG3,vessel_y);
	vessel_z = mul(RG3,vessel_z);


	////// convert vectors to euler angles
	double gamma = atan2( vessel_x.x, vessel_y.x);
	double beta = -1*(asin(vessel_z.x));
	double alpha = atan2(vessel_z.y, vessel_z.z);

	SetGlobalOrientation (_V(alpha, beta, (PI/2)-gamma));
	


}

All the best,
Brian
 
Thanks Brian.
I'll be doing a review/re-implementation/streamlining of my haphazard collection of rotation routines, since there's only one solution for the geometrically challenged like me - draw everything on a sheet of paper and verify every sign and sine geometrically.
 
Done (the star pointing thing, not yet - the generic frame conversion code) in the build 12 of Precession MFD.
 
Back
Top