SDK Question Orbit System

huddi

New member
Joined
Apr 20, 2009
Messages
38
Reaction score
0
Points
0
Hi,

I am trying to get the Tait-Bryan Angles to the Orbit System.
I am able to get the equivalents to Yaw and Pitch by a few conversions.
But I just cant find anything for the "bank-equivalent". This would be the
rotation around the vessels longitudinal axis to the orbital plane.

Can anybody help??
Thanks!

(Orbit System as it is in the standard HUD: one axis in direction of the orbitvelocity, one towards earth's center of mass and the third axis rightangled to both.)
 
should work like this:


Vc.X = Va.Y * Vb.Z - Vb.Y * Va.Z
Vc.Y = Va.Z * Vb.X - Vb.Z * Va.X
Vc.Z = Va.X * Vb.Y - Vb.X * Va.Y

Vl=SQR(Vc.X*Vc.X+Vc.Y*Vc.Y+Vc.Z*Vc.Z)

Vc.X=Vc.X/Vl
Vc.Y=Vc.Y/Vl
Vc.Z=Vc.Z/Vl

Va and Vb are the vectors you already got, Vc will be the vector perpendicular to the pane defined by them.
 
Last edited by a moderator:
^ That gives you Vc being the vector normal to the orbital plane but not the bank angle. To get the bank angle, you want to know the angle between the vessel's local vertical (+Y axis) and the normal to the local horizontal plane.

Try this:

Code:
VESSEL *pV; // pointer to vessel interface
VESSELSTATUS2 vs; // vessel status
MATRIX3 rotLocal2Global; // rotation matrix for transforming from local coords to global coords
VECTOR3 pos; // position vector
double bank; // bank angle, in radians

// Get a valid vessel pointer - implementation up to you

pV->GetStatusEx(&vs);
pV->GetRotationMatrix(rotLocal2Global);
pos = tmul(rotLocal2Global,vs.rpos/length(vs.rpos));
bank = atan2(-pos.x,pos.y); // bank is a right handed rotation
Note that at pitch= +/- 90 deg, the bank angle becomes +/- 90 deg because pos.y goes to zero.
 
Code:
VESSEL *pV; // pointer to vessel interface
VESSELSTATUS2 vs; // vessel status
MATRIX3 rotLocal2Global; // rotation matrix for transforming from local coords to global coords
VECTOR3 pos,tempVector; // position vector
double bank; // bank angle, in radians

pV=oapiGetVesselInterface(this->GetHandle());
pV->GetStatusEx(&vs);
pV->GetRotationMatrix(rotLocal2Global);
for(int j=0;j<3;j++)
    tempVector.data[j]=vs.rpos.data[j]/length(vs.rpos);
pos = tmul(rotLocal2Global,tempVector);
bank = atan2(-pos.x,pos.y); // bank is a right handed rotation

I had to modify the code a little because tmul() wouldn't work.

Could you maybe explain, how the code is supposed to work? Because right now it returns wrong angles.
(which are effected by e.g. position, yaw and pitch angle)
 
I had to modify the code a little because tmul() wouldn't work.
In what way would it not work? tmul is part of orbiterAPI.h.

Could you maybe explain, how the code is supposed to work? Because right now it returns wrong angles.
(which are effected by e.g. position, yaw and pitch angle)
That is expected behaviour but think perhaps I have misunderstood your objectives:
This would be the
rotation around the vessels longitudinal axis to the orbital plane.
I read that as you wanting the angle of rotation around your vessel's +Z axis such that, after the rotation, the +Y axis (heads up) would lie in the orbital plane. This angle is affected by pitch and yaw (think if you yawed right 45 degrees and then pitched down 45 degrees, your vessel's +Y axis would move out of the orbital plane).

I suspect what you want is the rotation angle around the vessel's +Z axis such that, after the rotation, the vessel's +X axis would lie in the local horizontal plane (wings level).
 
In what way would it not work? tmul is part of orbiterAPI.h.
Don't know why, but I think it is because of the second parameter vs.rot/length(vs.rot) looks like you have to do this operation seperately with a for-loop

That is expected behaviour but think perhaps I have misunderstood your objectives:

My objective is to get the Vessel's z-rotation to the orbital plane.
The behaviour is supposed to be exactly like the bank angle to the local surface plane.
so eg. if you have got 0° Pitch you can Yaw as much as you want without changing the Z-Rotation.
 
Don't know why, but I think it is because of the second parameter vs.rot/length(vs.rot) looks like you have to do this operation seperately with a for-loop
You should not. The orbiterAPI.h includes a VECTOR3 division operator overload. Not sure what is going on there. Do you get an error message from the compiler when you put it the way I have shown?
My objective is to get the Vessel's z-rotation to the orbital plane.
Just so we are clear here, the orbital plane is a plane that passes through the centre of mass of the body being orbited, through the centre of mass of the vessel and contains the orbital velocity vector. A vessel (such as the Delta-Glider) in the attitude pitch=yaw=bank=0 will have its wings perpendicular to this plane.

The behaviour is supposed to be exactly like the bank angle to the local surface plane.
so eg. if you have got 0° Pitch you can Yaw as much as you want without changing the Z-Rotation.
Yes, so it is the angle between the vessel's x-axis and the local horizontal plane (ie, the plane perpendicular to the orbital radius vector). That can be done, but I'll have to come back another time (maybe tomorrow?) with the code.
 
You should not. The orbiterAPI.h includes a VECTOR3 division operator overload. Not sure what is going on there. Do you get an error message from the compiler when you put it the way I have shown?

It returns -1.#IND for pos.x, pos.y and pos.z if i transform those into a string

Just so we are clear here, the orbital plane is a plane that passes through the centre of mass of the body being orbited, through the centre of mass of the vessel and contains the orbital velocity vector.
Yes this sounds right. Its just the plane opened by the velocity vector
and the vector from the vessels center of mass to the planets center of mass.

Yes, so it is the angle between the vessel's x-axis and the local horizontal plane (ie, the plane perpendicular to the orbital radius vector). That can be done, but I'll have to come back another time (maybe tomorrow?) with the code.

this would be so great... i'm stuck for a long time now :)
 
It returns -1.#IND for pos.x, pos.y and pos.z if i transform those into a string
Strange. I'll think on that further.

this would be so great... i'm stuck for a long time now :)
Try this:
Code:
// VESSEL *pV; // pointer to vessel interface
VESSELSTATUS2 vs; // vessel status
MATRIX3 rotLocal2Global; // rotation matrix for transforming from local coords to global coords
VECTOR3 pos,tempVector,an; // position vector
double bank; // bank angle, in radians

// pV=oapiGetVesselInterface(this->GetHandle()); // There is no need to do this if you are only using the "this" vessel.
GetStatusEx(&vs);
GetRotationMatrix(rotLocal2Global);
for(int j=0;j<3;j++)
    tempVector.data[j]=vs.rpos.data[j]/length(vs.rpos);
pos = tmul(rotLocal2Global,tempVector); // defines the local horizontal plane in local vessel coordinates
if (length(an = crossp(pos,_V(0,0,1))) > 0) // an == ascending node of the rotation through the local horizontal plane
    bank = atan2(an.y,an.x); // bank is a right handed rotation
else
    bank = 0; // when pitch == +/-90 degrees
 
Last edited:
unfortunately it does not work.

here is my try. it is not working either but i just cant find any mistake.

Code:
MATRIX3 rotLocal2Global; // rotation matrix for transforming from local coords to global coords
VECTOR3 rightWing, //vector to vessels right wing
        tempVector, //umrechnung
        CoMVector, // center of mass - earth in ecliptic (points away from earth)
        orbitVelocity, //orbitvelocity in ecliptic
        normalVector; //orthogonal to CoMVector and orbitVelocity
double  bank; // bank angle, in radians


this->GetRelativePos(this->GetSurfaceRef(),CoMVector);
this->GetRelativeVel(this->GetSurfaceRef(),orbitVelocity);
CoMVector/=-length(CoMVector); //normalisieren und umdrehen
orbitVelocity/=length(orbitVelocity); //normalisieren

normalVector.x=orbitVelocity.y*CoMVector.z-CoMVector.y*orbitVelocity.z;
normalVector.y=orbitVelocity.z*CoMVector.x-CoMVector.z*orbitVelocity.x;
normalVector.z=orbitVelocity.x*CoMVector.y-CoMVector.x*orbitVelocity.y;

GetRotationMatrix(rotLocal2Global);
rightWing.x=1;
rightWing.y=0;
rightWing.z=0;
rightWing=tmul(rotLocal2Global,rightWing);

bank=acos(rightWing.x*normalVector.x + rightWing.y*normalVector.y + rightWing.z*normalVector.z);

explanation:
I get the two vectors which open the reference plane. I normalize them
and build the cross product for the vector orthogonal to both.
This is in the ecliptic frame.

Now i get my vector to starboard in vesselcoordinates which is simply =1 in x direction.
This I transform to the ecliptic system so that I can build the angle
between both.

And here I think is the mistake. For example if I only rotate upwards
(pitch) the vessels starboardwing should not change direction in any
of the coordinate systems.
But after the conversion it does :/.

Any ideas?

Huddi
 
Any ideas?
No ideas right now, but I did not test my code before submitting it. I did test it just now and I am getting some funny numbers in the VESSELSTATUS structure. I'm not sure why that is but I can't debug it further until I get to the bottom of that. I've about run out of time for tonight but I'll have a look another day.

---------- Post added 25-07-09 at 20:43 ---------- Previous post was 24-07-09 at 21:05 ----------

This works for me and returns the same value as the bank indicator in the Surface MFD (it is the same maths as I had presented earlier but the code is slightly reworked to not use VESSELSTATUS):
Code:
    MATRIX3 rotLocal2Global; // rotation matrix for transforming from local coords to global coords
    VECTOR3 pos,an; // position vector
    double bank; // bank angle, in radians
    GetRotationMatrix(rotLocal2Global);
    GetRelativePos(GetGravityRef(),pos);
    pos /= length(pos);
    pos = tmul(rotLocal2Global,pos); // defines the local horizontal plane in local vessel coordinates
    if (length(an = crossp(pos,_V(0,0,1))) > 0) // an == ascending node of the rotation through the local horizontal plane
        bank = atan2(an.y,an.x); // bank is a right handed rotation
    else
        bank = 0; // when pitch == +/-90 degrees
    sprintf(oapiDebugString(),"%1.3f",bank*DEG);
 
Thanks a lot!! This works - even with the orbitplane.

But did you find out why it didn't work before?

edit: found it... was nothing about the vesselstatus structure. tmul uses the transposed matrix.
so you dont go from local to global, but the other way
 
Last edited:
Back
Top