Return to “Technical”

Post

Maths behind landing/docking

#1
Greetings young Master Josh!
I've seen on one of the videos, that ships can dock on bigger ships, or land on them. I'd like to know how do you make it possible.
Do you use vectors or matrices for that, and how do you combine the one ship's orientation with the bigger ones?

Thank you for your attention!

Tora out!
Post

Re: Maths behind landing/docking

#2
TorakunSama wrote:Greetings young Master Josh!
I've seen on one of the videos, that ships can dock on bigger ships, or land on them. I'd like to know how do you make it possible.
Do you use vectors or matrices for that, and how do you combine the one ship's orientation with the bigger ones?

Thank you for your attention!

Tora out!
Hi again Tora,

In general it is the same math that allows a weapon or thruster to be attached to a ship, a smoke trail attached to a missile, etc.

The usual formulation is composition of frames via matrix multiplication:

If A is the orientation matrix for the parent and B is the orientation matrix for the child, then A * B is the orientation matrix for the child when attached to the parent. Reading right to left you think of this as "first, apply the child's matrix B, then apply the parent's matrix A." Which really just means that B is attached to A.

It doesn't have to be matrices, as discussed in recent dev logs, but in general you have some way of "composing" frames so that you can handle "attached" entities like hardpoints. It really just means that you apply one frame after another. The parent frame is applied after a child frame to create the perception that the child is attached to the parent. Another way to think of it is that the child's frame is interpreted as being specified with respect to the local space of the parent (instead of in world space). So you go from local space -> parent space -> world space (i.e., A * B). A ship being docked is the exact same as a hardpoint being attached!

Hope it helps!
“Whether you think you can, or you think you can't--you're right.” ~ Henry Ford
Post

Re: Maths behind landing/docking

#3
Thanks YMaster Josh,
It's not very mathis but I think it might help, I'll give it a shot.
Matrix multiplication, hein?
I saw it as adding the host's position to the difference between the two . That gives the right position, but the guest ship can't move on it's own.
Now I don't see how to keep the guest's position relative or local to the host's.

Once again, thank you for your time!
Post

Re: Maths behind landing/docking

#4
TorakunSama wrote:Thanks YMaster Josh,
It's not very mathis but I think it might help, I'll give it a shot.
Matrix multiplication, hein?
I saw it as adding the host's position to the difference between the two . That gives the right position, but the guest ship can't move on it's own.
Now I don't see how to keep the guest's position relative or local to the host's.

Once again, thank you for your time!
Oh I left that bit out:

When you first dock, you need to compute the guest frame with respect to the host frame (since at the time of docking, the guest will still be in world space). You mentioned "difference between the two" ~ that's exactly the right concept, but we need the generalized version of it. The formula is:

B' = A^ * B

Where ^ means inverse. If you have a B in world space and want to convert it to A's space, the way to do so is multiplication by A's inverse frame. To check that it makes sense, just note that if you transform B' by A again, you get the original B:

A * B' = A * (A^ * B) = B

Which is exactly what you want: it means that we preserved the world space orientation of B when we moved it from world space to A's space.
“Whether you think you can, or you think you can't--you're right.” ~ Henry Ford
Post

Re: Maths behind landing/docking

#5
Ah, I see, seems straight forward, however, how do you invert the object's transform, do you invert all components, or is there a math function to invert it? As far as I know, the transform I use is a 4 Vectors Matrix. I can't have a vector or matrix to the exponent -1!

I probably don't get the invertion part.

Note: Forgive my ignorance, I was denied this part of high school maths!
Post

Re: Maths behind landing/docking

#6
TorakunSama wrote:Ah, I see, seems straight forward, however, how do you invert the object's transform, do you invert all components, or is there a math function to invert it? As far as I know, the transform I use is a 4 Vectors Matrix. I can't have a vector or matrix to the exponent -1!

I probably don't get the invertion part.

Note: Forgive my ignorance, I was denied this part of high school maths!
Yes there's an analagous inverse operation for matrices, but not quite as straightforward as inverting all the components.

Have a look at a bunch of fancy symbols to convince yourself that I'm speaking the mathematical truth, then go gently lift the code from this stackoverflow post if you'd like an implementation of a 4x4 inversion function.
“Whether you think you can, or you think you can't--you're right.” ~ Henry Ford
Post

Re: Maths behind landing/docking

#7
Have a look at a bunch of fancy symbols to convince yourself that I'm speaking the mathematical truth, then go gently lift the code from this stackoverflow post if you'd like an implementation of a 4x4 inversion function.
I'm not doubting! I'm asking! As I said, I did not have the opportunity to see this in school, even then it's been some years since I left schools! Sorry, should have done some research before asking!
One more question, is the vector (x,y,z) the inverse of (z,x,y) or of (-x,-y,z) or again (1/x, 1/y, 1/z)? Depending on the outcome, maybe one can just manually swap/invert each element of the matrix (a 4 vectors one).
Post

Re: Maths behind landing/docking

#8
TorakunSama wrote:
Have a look at a bunch of fancy symbols to convince yourself that I'm speaking the mathematical truth, then go gently lift the code from this stackoverflow post if you'd like an implementation of a 4x4 inversion function.
I'm not doubting! I'm asking! As I said, I did not have the opportunity to see this in school, even then it's been some years since I left schools! Sorry, should have done some research before asking!
One more question, is the vector (x,y,z) the inverse of (z,x,y) or of (-x,-y,z) or again (1/x, 1/y, 1/z)? Depending on the outcome, maybe one can just manually swap/invert each element of the matrix (a 4 vectors one).
well if you represent the vector as a matrix [x,y,z] then it would be 1/determinant [x,y,z] where the determinant is x-y+z I believe

~Sly
IVE BEEN OUT OF MY MIND A LONG TIME
Post

Re: Maths behind landing/docking

#9
TorakunSama wrote:
Have a look at a bunch of fancy symbols to convince yourself that I'm speaking the mathematical truth, then go gently lift the code from this stackoverflow post if you'd like an implementation of a 4x4 inversion function.
I'm not doubting! I'm asking! As I said, I did not have the opportunity to see this in school, even then it's been some years since I left schools! Sorry, should have done some research before asking!
One more question, is the vector (x,y,z) the inverse of (z,x,y) or of (-x,-y,z) or again (1/x, 1/y, 1/z)? Depending on the outcome, maybe one can just manually swap/invert each element of the matrix (a 4 vectors one).
I suppose you could say that v' = (1/x, 1/y, 1/z) would be the multiplicative inverse, since v * v' = 1, and that (-x, -y, -z) would be the additive inverse, since v + v' = 0. But AFAIK one doesn't usually talk about vector inverses.

For a matrix, the situation is different, the inverse M' is defined such that M * M' = I, where I is the identity matrix. You can't obtain M' just be 'inverting' the vector components, unfortunately. The general formula involves something called a determinant and something called an adjoint matrix, neither of which are particularly easy to explain ;)
Slymodi wrote:well if you represent the vector as a matrix [x,y,z] then it would be 1/determinant [x,y,z] where the determinant is x-y+z I believe

~Sly
Although you can think of the vector as a matrix, it is not a square matrix, so it has neither a determinant nor an inverse. An inverse M' needs to satisfy both M * M' = I and M' * M = I. This doesn't make sense for a non-square matrix M since the size requirement of M' (how many rows/cols it has) would change depending on whether it was left-multiplied or right-multiplied, due to the nature of matrix multiplication. So you can't possibly have a single matrix M' that satisfies both if M is non-square.
“Whether you think you can, or you think you can't--you're right.” ~ Henry Ford
Post

Re: Maths behind landing/docking

#11
If you're using c++ I strongly recommend the glm library. You can always remake specific classes if you find you need different performance later.
It can handle anything glsl can, which means matrix, vectors, and many useful functions related to them, are immediately available with a simple syntax.
woops, my bad, everything & anything actually means specific and conformed

Online Now

Users browsing this forum: No registered users and 5 guests

cron