Advanced Question get_progradedir + vectors stuff + fisheye scope

Goth

Occasional orbinaut
Donator
Joined
Aug 1, 2008
Messages
424
Reaction score
2
Points
0
I noticed the function "get_progradedir" on Lua's help. Why there are no such function in the OAPI?
How to get this vector anyway?
 
Last edited:

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
It's done via API by calling VESSEL::GetGravityRef, VESSEL::GetRelativeVel and VESSEL::GetRotationMatrix, and then by doing calculations, and I assume that doing the same via LUA would be slower, so those operations are combined into get_progradedir.

The LUA's get_progradedir function is implemented in LuaInterpreter.dll, by simply calling aforementioned VESSEL methods and then calculation of the vector, and not by calling a single function, which doesn't exist in the API. The returned value is a normalized direction vector.

You get it like other variables, so if 'v' is a vessel:
Code:
prog_dir = v:get_progradedir()
The components of the vector will be in prog_dir.x, prog_dir.y and prog_dir.z.

---------- Post added ----------

I just thought you wanted to do it in C++, so the source code for that function is in "Orbitersdk/samples/LuaScript/LuaInterpreter/Interpreter.cpp" - Interpreter::vesselGetProgradeDir method.

A snippet:
Code:
OBJHANDLE hRef = v->GetGravityRef();
VECTOR3 vel;
MATRIX3 rot;
v->GetRelativeVel (hRef, vel);
v->GetRotationMatrix (rot);
vel = tmul (rot, vel);  // rotate into vessel frame
normalise (vel);
 

Goth

Occasional orbinaut
Donator
Joined
Aug 1, 2008
Messages
424
Reaction score
2
Points
0
OK it works fine but there's a strange behaviour about the X and Y coordinates. They go from -1 to 1 but if I rotate the ship around its Y axis, when X (example) reaches something like 0.97, it increases slowly. Then it reaches 0.9999 and start going backward (this is right), and again decreasing really slow (problem), even though i do NOT change my rotation speed.
Then it reaches again 0.97 and the "decreasing speed" goes back to normal.
I ask why and a possible solution.
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
And what are the other coordinates at the moment? The vector is normalized, so its radius should be always 1.
r = 1 = sqrt(x2 + y2 + z2);
 

Goth

Occasional orbinaut
Donator
Joined
Aug 1, 2008
Messages
424
Reaction score
2
Points
0
And what are the other coordinates at the moment? The vector is normalized, so its radius should be always 1.
Thanks for the answer but this is not what I was complaining about: the problem is this (bold font):
if I rotate the ship around its Y axis, when X (example) reaches something like 0.97, it increases slowly. Then it reaches 0.9999 and start going backward (this is right), and again decreasing really slow (problem), even though i do NOT change my rotation speed.

The problem is not the normalisation, because the same strange behaviour appears even without the normalise(vel); piece of code.
 
Last edited:

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
Slowly, like a sinusoid, or similar?

x = sin(inclination) * cos(azimuth);
y = cos(inclination);
z = sin(inclination) * sin(azimuth);

y and z might be switched or have opposite signs. Inclination and azimuth are to the prograde vector.
 

Goth

Occasional orbinaut
Donator
Joined
Aug 1, 2008
Messages
424
Reaction score
2
Points
0
Yes, like a sine wave, while i want something like a triangle wave.
Y and Z doesn't seem switched, Y has opposite sign but it's not the problem.
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
Yes, like a sine wave, while i want something like a triangle wave.
That doesn't work this way. You are rotating relative to the vector, so it's a sphere you are drawing (or a circle if around one axis), and that's why the result won't have sharp edges, and closer to the direction of the vector the speed of coordinate change will be slower.

----- Post added: -----

What you can do is change Cartesian to Spherical, and then inclination and azimuth will change with constant speed.
 

Goth

Occasional orbinaut
Donator
Joined
Aug 1, 2008
Messages
424
Reaction score
2
Points
0
I see. Actually far to the direction of the vector is slower.
 
Last edited:

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
I see. Actually far to the direction of the vector is slower.
At 180 degrees Cartesian coordinates will change as slow as at 0 degrees, and +/-90 degrees is the fastest. You can convert Cartesian coordinates to spherical as I added, so you'll have constant speed / triangle wave like you wanted.
 

Goth

Occasional orbinaut
Donator
Joined
Aug 1, 2008
Messages
424
Reaction score
2
Points
0
At 180 degrees Cartesian coordinates will change as slow as at 0 degrees, and +/-90 degrees is the fastest.
Indeed, the vector direction is at +90 degrees, so it changes fast.
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
So I'm asking here: how to actually change cartesian to spherical?
Orbiter is left-handed with y pointing 'up', so:
[math]r=\sqrt{x^2+y^2+z^2}[/math][math]\Theta=\arccos\left(\frac{y}{r}\right)[/math][math]\phi = \arctan2\left(z,x\right)[/math]
Note that r = 1 for normalized vectors.

Is this the right way to obtain that fish eye scope?
I'm sorry, I don't think I understand you. Can you elaborate?
 

Goth

Occasional orbinaut
Donator
Joined
Aug 1, 2008
Messages
424
Reaction score
2
Points
0
Thanks orb for answering again in this topic.

I'm sorry, I don't think I understand you. Can you elaborate?
If you check the link I've provided you can see what I'm trying to do. I have to print vessels/stations positions on the MFD with a view of 180°.
Basically I want to obtain this:
[ame="http://en.wikipedia.org/wiki/Azimuthal_equidistant_projection"]Azimuthal equidistant projection - Wikipedia, the free encyclopedia[/ame]
or:
[ame="http://en.wikipedia.org/wiki/Fisheye_lens"]Fisheye lens - Wikipedia, the free encyclopedia[/ame]

With your formulae I get an angle Theta, an angle Phi and the radius, but I can't draw anything with all this. Or better, I could draw but reversing again everything, obtaining again those accelerations far from the center.
I've already tried to apply equidistant projection formulae to my coordinates but I didn't manage to get nice results.

EDIT:
actually because I had cartesian data, I will try now to code the equidistant projection formulae using BEFORE the formulae you suggested.

EDIT 2:
no, I totally have no idea
 
Last edited:

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
With your formulae I get an angle Theta, an angle Phi and the radius, but I can't draw anything with all this. Or better, I could draw but reversing again everything, obtaining again those accelerations far from the center.
I've already tried to apply equidistant projection formulae to my coordinates but I didn't manage to get nice results.

EDIT:
actually because I had cartesian data, I will try now to code the equidistant projection formulae using BEFORE the formulae you suggested.

EDIT 2:
no, I totally have no idea
For 2D projection you only need Theta as a radius and Phi for the angle, and radius isn't used for drawing, but can by displayed as a numerical distance.

In this case, for 3D coordinates, 'z' is your 'y', as 'z' axis is pointing in the vessel's front direction, so you need to modify formulas.

In 2D coordinates relative to the center of MFD:
[math]x'=\Theta\sin\phi[/math][math]y'=\Theta\cos\phi[/math]I didn't check it with numbers, so you may additionally need to exchange x with y.
 

Goth

Occasional orbinaut
Donator
Joined
Aug 1, 2008
Messages
424
Reaction score
2
Points
0
I've caught a glimpse of success. But it seems you've given me a 360° view.
I'm trying to understand how to change that.
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
I've caught a glimpse of success. But it seems you've given me a 360° view.
Isn't Theta only -90..90°? And the Phi angle should be in 360 degrees span, otherwise you'd get only a half of the circle for your projection.
 

Goth

Occasional orbinaut
Donator
Joined
Aug 1, 2008
Messages
424
Reaction score
2
Points
0
Starting from a normalized vector, after your formulae Theta goes from PI to zero and from zero to PI, with zero forward from the vessel, and PI behind. At least retrieving Theta doing this:
Code:
double theta = acos(Z);
Phi is
Code:
double phi = atan2(Y,X);

otherwise you'd get only a half of the circle for your projection.
Isn't what I want? A 180° degrees scope.
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
Theta should be only from 0 at the center to PI at the outer radius. If you only want a half of it, limit it to PI/2 - I think this is what you mean.

Regarding the Phi, I thought you want this, i.e. the whole 360 degrees circle, and not only upper half of it, if you had only 180 degrees span of Phi:



This is what you'd get with 360 degrees span Phi and 180 degrees span Theta (the bright part):
300px-Azimuthal_Equidistant_N90.jpg


A half of Theta it would be only from the pole to equator.
 
Top