How to calculate the values of the orbit HUD

Topper

Addon Developer
Addon Developer
Donator
Joined
Mar 28, 2008
Messages
671
Reaction score
32
Points
43
Hi,
i need the values of the orbit MFD for some further calculation.
I need the ship orientation, but not related to the local horizon, but related to the speed vector.
I can't help me with the shipAirspeedVector, because it's depending to the bank also.
So my question os, how can i calc the x/y orientation values of the orbit MFD?

I've tried it on so much ways.
I think i have to use the relativ velocity to the reference body and the orientation of the ship, but i can't solve this problem...

p.s.
I just can calculate the "total" angel, it's r=acos(cos(vessel->getSlipAngel())*cos(vessel->getAOA())) but i need it for x/y also (without somethink related to the roll angel)...
 
Last edited:
You may find this helpful. It's GPL, so you can use/abuse it as you like:

[ame="http://www.orbithangar.com/searchid.php?ID=3609"]Free Orbit MFD 1.2[/ame]

Not sure it will help with finding the velocity vector, but you may find some clues in the code.
 
Hi,

thank you!
But i was a bit tired when i've started this post.
I don't wanted to know the values of orbit MFD, i need the values of the orbit HUD :)
In Orbit MFD there are no informations about the orientation...
 
What attitude information do you need? If you use oapiGetRelativeVel, you'll know the velocity vector in the HUD, if you get oapiGetRelativePos, you'll know the radius-vector, and their cross-product (with + and -) gives you normal and antinormal vectors.
 
Hi,
ok what i need is what you can see in the screenshot.
I need the 10° value and the 20° value, and maybe the "roll value".
It's the orbit MFD and it's relativ to the reference body (Moon in this example).

Sorry i'm not such a math expert, but that i have to use something with the relativ velocity to the reference body is clear to me.

I now it's sounds easy to get this angles and i've tried many things, but i will not get the result i want to have ...

I don't understand your last point with the cross product.
Do you talking about the cross product of oapiGetRelativePos and oapiGetRelativeVel?
Sorry i've forgotten all this stuff about polar angles and so on :facepalm:
 

Attachments

  • hud.jpg
    hud.jpg
    33.9 KB · Views: 20
I can't solve this, doese someone give me some more tips please...?
I hope the problem is clear...???
It's enogh for the first if someone tells me how to calculate the 20° angle value in the example of the thumbnail using the orbiter api...
 
Last edited:
lets see... you're talking about figuring the angles between you and your orbital plane...


well, the plane is defined by it's normal.... that should be easy enough, for you can get it by calculating the cross product between your velocity relative to your reference body and your position, relative to it as well...


that gives you a "horizon" of sorts to work with, since that vector basically defines what's "up" and what's "down" in your orbital plane....

now, for the orbital "pitch" you see in the hud - you can figure that based on the dot product between your nose direction and the aforementioned "up" vector...

the dot between two vectors represents the cosine of the angle between them

so with acos(dot(noseFwdDir, orbitPlaneNrml)) * DEG; you get your pitch :thumbup:


do the same with the ship's "up" vector, and you'll get your bank indication


and remember to look alive when taking advice from me - i just might be completely wrong at (many) times :cheers:
 
Hi Moach, thanks for your answer,
I'm realy despair because of this problem!
Sorry if i don't understand you right mabye it's because of my limited english and math knowlege...

lets see... you're talking about figuring the angles between you and your orbital plane...


well, the plane is defined by it's normal.... that should be easy enough, for you can get it by calculating the cross product between your velocity relative to your reference body and your position, relative to it as well...
ok,
so this is:

Code:
    VESSEL *v = this->openHandle()->vessel;
    VECTOR3 relvel;
    VECTOR3 relpos;
    v->GetRelativePos(v->GetGravityRef(),relpos);
    v->GetRelativeVel(v->GetGravityRef(),relvel);
    normalise(relpos);
    normalise(relvel);
    VECTOR3 horizon = crossp(relvel,relpos);
right?

...
now, for the orbital "pitch" you see in the hud - you can figure that based on the dot product between your nose direction and the aforementioned "up" vector...
Ok but sorry i don't understand,
whats the "nose direction"? Is it the global orientation? Or is it a VECTOR3 with the values of the AOA , Pitch, heading, slipangle,...??
Or is it the normalised value of the v->GetShipAirspeedVector(...) function of the orbiter api??

...
so with acos(dot(noseFwdDir, orbitPlaneNrml)) * DEG; you get your pitch ...

Ok and the orbitPlaneNrml is one element of the "horizon" var in my example??
 
Last edited:
actually, "orbitPlaneNrml" IS your "horizon" vector...

you see, in 3D geometry, a plane is described by the vector perpendicular to it, and you get that by calculating the "cross product"

thik of it this way, bring up your hand facing palm up and stretch out your index and middle fingers to the shape of a letter "V" - now, notice that it is always possible to position the palm of your other hand in a way that it touches the full length of both sides of the "V" (as much as you can possibly flatten out your palm, that is)

ok, so if your index finger points in the direction of your velocity, and your middle finger points to the reference body - then your up-facing palm is your "orbital plane" - and now, if you hold up your thumb in a way that it's in a right angle with your palm and V-pointed fingers - that's your CROSS VECTOR, aka: the "horizon" reference for your pitch ladder on the HUD


so you see, the "cross vector" is simply the vector perpendicular to the given two


by the way - your code is very much correct - you only left out the last part of it, which allows you to figure out your needed angle....


for that, you need your "nose-forward vector", which you've asked about - this is a simple one...
your nose isn't necessarily aligned with your velocity (usually isn't), but it's still easy to get - simply rotate the absolute Z axis (0,0,1) over your ship's rotation matrix, like this:

VECTOR3 noseDirVec(0,0,1);
vmult(noseDirVec, vsl->GetRotMatrix);

...or something... (can't remember the exact name of the function, but you get the point, right?)

and it really is that simple - by rotating Z (multiply it with matrix) to the orientation of your ship, you have the direction of the nose in "global space"...

the dot between that direction and your "horizon" gives you your pitch... - but note that it describes the angle from the plane normal to the nose, which is perpendicular - so 90° marks "zero pitch", then :thumbup:


it really isn't as hard as it sounds once you get your head around it.... this is much more an exercise of visualizing these directions in your head than one of actually solving formulas and stuff (the CPU does the numbers, you need do just the general thinking)

be patient, young padawan - you're on the right path - good luck :salute:

:cheers:
 
Thank you very much master Moach!
This allready works acceptable for me, but with one limitation (even if this is not so important for me):

The code shows only "nearly" the right angle.
for example, for 20° in the HUD, i got a value of 19.56°
for 40°, 36.85°
for 90°, 57.28° ??
Does i have everything right in the code?
It's not so important for me to have the exact value, a good tendency is still ok for me and i'm happy with this result.
The most important thing was just to have this value without any influence of the roll and pitch angle and this is still the case now...
But if it's no problem for you to say me whats wrong... than i'm very happy :)

Code:
    VESSEL *v = this->openHandle()->vessel;
    VECTOR3 relvel;
    VECTOR3 relpos;
    v->GetRelativePos(v->GetGravityRef(),relpos);
    v->GetRelativeVel(v->GetGravityRef(),relvel);
    normalise(relpos);
    normalise(relvel);
    VECTOR3 horizon = crossp(relvel,relpos);
    VECTOR3 noseForwardVector = {0,0,1};
    MATRIX3 rotationMatrix;
    v->GetRotationMatrix(rotationMatrix);
    noseForwardVector = mul(rotationMatrix,noseForwardVector);
    double virtualSlip= dotp(horizon,noseForwardVector);
    sprintf(oapiDebugString(),"%f", virtualSlip*180/PI);


---------- Post added at 08:31 PM ---------- Previous post was at 08:20 PM ----------

Oh i've found my mistake!
it must be:

double virtualSlip = asin(dotp(horizon,noseForwardVector));

i've forgotten the "asin" !

Thank you master Moach!
 
Last edited:
Rather than start a new thread on the same topic I thought I might ask this question here.

Topper's code gives a pitch measurement but how would you go about getting roll and yaw to go with it?
 
Ok, if nose forward is _V(0,0,1) then roll is given by

Code:
VECTOR3 RollVector = {1,0,0};
RollVector = mul(rotationMatrix,RollVector);
double vRoll = asin(dotp(horizon,RollVector));

Still at a loss to find yaw though.

---------- Post added at 05:03 PM ---------- Previous post was at 03:48 AM ----------

So as part of my continuing experimentation. I added the following lines to see if I could the local coordinates of the prograde vector.

Code:
	VECTOR3 input = (rVel);
	input = mul(rotationMatrix,input);
	normalise (input);
	sprintf_s(oapiDebugString(), 255, "X, %0.3f Y %0.3f, Z %0.3f", input.x, input.y, input.z); // Debuggery

In theory the function should return "0.000, 0.000, 1.000" when the nose is aligned with the prograde pipper.

Instead I get (-0.951, 0.000, 0.307). Now obviously I transposed my X and Z axes somewhere but that doesn't explain why X wouldn't be 1.000. What vector am I measuring if not prograde, and how do I find prograde?
 
Back
Top