Question Rotating Vessel around Local Axis in MFD

technomage

New member
Joined
Sep 9, 2011
Messages
2
Reaction score
0
Points
1
I'm trying to duplicate the yaw, pitch and roll buttons in the scenario editor in an MFD. Specifically, I want to yaw a vessel 1 degree relative to it's local frame. I've tried to look at posts about vessel orientation and translation between local and global orientation but either they don't apply or they're way above my head. Coordinate translation is easy but angles are confusing me.

Changing the arot property of the vessel status works if the vessel is aligned with the ecliptic but fails once it is rotated away. I tried altering the rotation matrix directly but that didn't work. I think I need to:

Code:
VESSEL *localVessel = oapiGetFocusInterface();
MATRIX3 localRotationMatrix;
VESSELSTATUS2 localVesselStatus; //memset, etc.
localVessel->GetStatusEx(&localVesselStatus);
localVessel->GetRotationMatrix(localRotationMatrix);
//Use localRotationMatrix to get a localVector from localStatus.arot
localVector.y += RAD*1;
//Use localRotationMatrix to convert localVector to localStatus.arot

Or maybe I need to get, alter and set the vessel's rotation matrix. I just can't get my head around how to use the rotation matrix.
 

BrianJ

Addon Developer
Addon Developer
Joined
Apr 19, 2008
Messages
1,680
Reaction score
902
Points
128
Location
Code 347
Hi,
there's probably a more efficient way to do this using rotation matrices - but I like vectors, so I do it with vectors :) Try this:

Code:
////////////////
	VECTOR3 x_loc = _V(1,0,0); // axes in local vessel frame
	VECTOR3 y_loc = _V(0,1,0);
	VECTOR3 z_loc = _V(0,0,1);

	/////// create rotation matrix
	double rot_angle = 1 * RAD; // angle that vessel will be rotated by
	VECTOR3 rot_vec = _V(0,1,0); // axis that vessel will be rotated around (unit vector)

	double ct = cos(rot_angle);
	double st = sin(rot_angle);

	double ux = rot_vec.x;
	double uy = rot_vec.y;
	double uz = rot_vec.z;
	double ux2 = ux*ux;
	double uy2 = uy*uy;
	double uz2 = uz*uz;

	MATRIX3 RG;

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

	VECTOR3 new_x_loc = mul(RG, x_loc); // rotated vessel axes in current vessel frame
	VECTOR3 new_y_loc = mul(RG, y_loc);
	VECTOR3 new_z_loc = mul(RG, z_loc);

	VECTOR3 x_global; // rotated vessel axes in global frame
	VECTOR3 y_global;
	VECTOR3 z_global;

	GlobalRot(new_x_loc,x_global); // transform local to global
	GlobalRot(new_y_loc,y_global);
	GlobalRot(new_z_loc,z_global);

	normalise(x_global); // just to make sure it's a unit vector
	normalise(y_global);
	normalise(z_global);

	//// convert axes vectors to euler angles
	double gamma = atan2( x_global.x, y_global.x);
	double beta = -1*(asin(z_global.x));
	double alpha = atan2(z_global.y, z_global.z);

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

I think this should work - any good?
Cheers,
Brian
 

martins

Orbiter Founder
Orbiter Founder
Joined
Mar 31, 2008
Messages
2,448
Reaction score
462
Points
83
Website
orbit.medphys.ucl.ac.uk
Also, the source code for the scenario editor is part of the SDK (Orbitersdk\samples\ScnEditor). If you want to see how it is done there, just look for the EditorTab_Orientation class in Editor.cpp, in particular the Rotate method.

It is just a matter of building a local rotation matrix for rotating around one of the principal axes, and post-multiplying it to the vessel's global rotation matrix.
 

Donamy

Addon Developer
Addon Developer
Donator
Beta Tester
Joined
Oct 16, 2007
Messages
6,924
Reaction score
232
Points
138
Location
Cape
Would this have anything to do, with the rotation errors of the RMS in SSU ?
 

DaveS

Addon Developer
Addon Developer
Donator
Beta Tester
Joined
Feb 4, 2008
Messages
9,459
Reaction score
712
Points
203
Top