Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫  π  -¹ ² ³ °

You are not logged in.

#1 2014-06-21 00:35:20

Member
Registered: 2014-06-21
Posts: 12

Translate local vector to world vector

Greetings geniuses and geniuses in training!

I've been working on creating a space sim, just for laughs, see how far I'd get. and i think i have reached my limit. I was hoping someone here might be able to help me out.

I have a vector relative to the player's ship representing the velocity, the local vector. now, the physics engine I'm using can only work with vectors relative to the world, so I'm gonna have to translate
the local vector to a world vector. I was hoping someone here might be able to point me in the right vector (see what i did there? ^^)

Offline

#2 2014-06-21 00:53:17

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,037

Re: Translate local vector to world vector

So, the ship is movong in the direction of the vector with the velocity equal to the intesity of the vector?

Here lies the reader who will never open this book. He is forever dead.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

#3 2014-06-21 01:01:55

Member
Registered: 2014-06-21
Posts: 12

Re: Translate local vector to world vector

you are correct sir!

Offline

#4 2014-06-21 02:17:33

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,037

Re: Translate local vector to world vector

But, then that cannot be relative to the ship. The ship's velocity relative to the ship is 0.

Here lies the reader who will never open this book. He is forever dead.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

#5 2014-06-21 02:56:33

Member
Registered: 2014-06-21
Posts: 12

Re: Translate local vector to world vector

Now that you mention it, indeed. i hadn't thought of that... hmm... do you happen to know a way to calculate the velocity vector based on the objects rotation?

i tried it using 2 angles, alpha and beta, it's the only way i know how to calculate x, y, and z of a point on a sphere:
x = radius* cos(beta) * cos(alpha);
y = radius* cos(beta) * sin(alpha);
z = radius* sin(beta);

Radius in this case being the ship's velocity, and alpha and beta are the angles i adjust to rotate the vector.

however, this doesn't take into account the last rotation of the ship, the roll so to speak. and its exactly this what's been driving me nuts the past couple of days.

Offline

#6 2014-06-21 06:10:23

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,037

Re: Translate local vector to world vector

I'm not sure what you are asking. What I understood is that you are trying to get the x, y and z component of the velocity vector. Is that correct?

Here lies the reader who will never open this book. He is forever dead.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

#7 2014-06-21 06:16:55

bob bundy
Registered: 2010-06-20
Posts: 8,108

Re: Translate local vector to world vector

Welcome to the forum.

It's going to take me a few posts to focus in on exactly what you are asking.  Here's a sphere:

I've got the x axis coming 'forward'; the y axis going to the right; and the z axis going straight up.

O is the origin; B a point on the surface of the sphere; and A the projection downwards of that point onto the x-y plane.

beta is the angle BOA; alpha is the angle AOX.

OB is the radius.

So the z coordinate of B is BA = R.sin(beta)

OA is R.cos(beta)

And hence

the y coordinate of B is R.cos(beta).sin(alpha)

and the x coordinate of B is R.cos(beta).cos(alpha)

So far so good.

Now your ship is moving on the surface of the sphere with a certain vector relative to the world (sphere).

But you don't know what that is but you do know the vector relative to .....???  And that's where I come unstuck, because I don't know what its relative to.

If we can sort that out, then, maybe, the rest is plain sailing.

Bob

Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei

Offline

#8 2014-06-21 06:23:14

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,037

Re: Translate local vector to world vector

Hi Bob

Are you sure it is moving on the surface of the sphere?

I am also stuck with the point of view. The only reference frame that makes sense is the world, but it doesn't seem to be so...

Here lies the reader who will never open this book. He is forever dead.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

#9 2014-06-21 06:34:01

bob bundy
Registered: 2010-06-20
Posts: 8,108

Re: Translate local vector to world vector

Are you sure it is moving on the surface of the sphere?

In a word, no.  But here's the evidence:  (1) to a good approximation the world is a sphere; (2) those coordinates make sense on a sphere.

What worries me is maybe DeadBeef wants to allow for the rotation of the world on its axis.  I'm not going to enjoy that transformation.

I think you missed my plain sailing pun.

Bob

Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei

Offline

#10 2014-06-21 06:45:58

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,037

Re: Translate local vector to world vector

Those coordinates make sense because that's the way the vector can be decomposed in 3D.

I don't think it's around a world axis. It seems to be a rotation of the ship, but neither affect any coordinates, so I'm not sure what that's about.

Yes, I did miss the pun. I quite like it, unlike most people.

Here lies the reader who will never open this book. He is forever dead.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

#11 2014-06-21 07:02:58

bob bundy
Registered: 2010-06-20
Posts: 8,108

Re: Translate local vector to world vector

Hhmmm.  Over to the OP I think.  Oh yes; nearly forgot: (3) the word 'radius' is used.

There are many opportunities for puns in English as there are so many words that sound alike but have different meanings or are spelt the same but have different meanings.  Here they are mostly followed by a long groan, but I felt one was justified because of:

I was hoping someone here might be able to point me in the right vector

And being a sea-faring nation, there are many nautical opportunities.  Anyway, I'm signing off for a while; hopefully we'll get some clarification soon.

Bob

Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei

Offline

#12 2014-06-21 07:09:00

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,037

Re: Translate local vector to world vector

Well, he clarifies that "radius" refers to the velocity vector.

Also, I think you missed the word play in the last sentence of my last post.

Here lies the reader who will never open this book. He is forever dead.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

#13 2014-06-21 07:14:07

Member
Registered: 2014-06-21
Posts: 12

Re: Translate local vector to world vector

I apologize for the confusion. I'll try to clarify, but im not a mathwiz. if anything needs clearing up, please ask.

this isnt about relative vectors anymore, as anonimnystefy pointed out, the velocity relative to the ship will always be zero. so i have to find a different solution.

the ship has a rotation in quaternions. i can create a new euler and set its values to the current rotation of the ship, X, Y and Z rotation.
i need the velocity vector (relative to the world) to always point forward (relative to the ship)

so in a sense, its calculating a point on a sphere, using 3 angles, i do know how its done using 2 angles, like i described before, but there is a third angle.

perhaps if i show you the problem in action, the problem will be described better than i ever could, so here goes: http://77.174.19.60/dev/ this is the project i'm working on. (just enter a random username and pass and click register, db will get hundreds of wipes, also use a pass like 'adsfjday' because i havent gotten to encryptions yet)
now, rotation and all works perfect.
however when you havent rotated yet, the ship moves forward, like it should (by pressing the arrow keys you can control the rotation better than with the mouse) up/down also works surprisingly well, assuming you still havent rotated.
the left and right cause problems. this is because i dont calculate in the Z rotation of the ship. (it might be a bit hard to see, but the camera is chasing the ship, it should be looking at the back of the ship when you're moving for a few seconds)

the formula to calculate the vector i'm currently using is:

x = radius* cos(beta) * cos(alpha);
y = radius* cos(beta) * sin(alpha);
z = radius* sin(beta);

where the radius is the speed of the ship, alpha is the Y angle of the ship, and beta is the X angle of the ship. i need a way to calculate in the Z axis.

i hope this clarifies the problem a bit. your help and patience so far is greatly appreciated!

Last edited by DeadBeef (2014-06-21 07:17:06)

Offline

#14 2014-06-21 07:32:55

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,037

Re: Translate local vector to world vector

Okay, I think I see the problem here. But, if I'm not mistaken, and I might be, you would need two more angles for the rotation of the rocket.

Here lies the reader who will never open this book. He is forever dead.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

#15 2014-06-21 07:37:42

Member
Registered: 2014-06-21
Posts: 12

Re: Translate local vector to world vector

two? are there more than X y and Z?

Offline

#16 2014-06-21 07:39:08

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,037

Re: Translate local vector to world vector

No, no. You will need angles gamma and delta for the rotation of the ship.

Here lies the reader who will never open this book. He is forever dead.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

#17 2014-06-21 07:47:52

Member
Registered: 2014-06-21
Posts: 12

Re: Translate local vector to world vector

ah, i think i'm starting to understand it now... then... i would need all four angles. alpha, beta, delta and gamma, the euler angles i have now make no sense then...

Offline

#18 2014-06-21 08:13:38

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,037

Re: Translate local vector to world vector

Actually, I just looked at the info on wikipedia a bit. You are right, you don't need 4 angles. Three is enough.

Here lies the reader who will never open this book. He is forever dead.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

#19 2014-06-21 08:21:20

Member
Registered: 2014-06-21
Posts: 12

Re: Translate local vector to world vector

please, enlighten me ^^

Offline

#20 2014-06-21 08:50:29

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,037

Re: Translate local vector to world vector

Well, I think I need enlightenment myself. Your best bet is to wait for Bob, but I will try doing it in the mean time.

Here lies the reader who will never open this book. He is forever dead.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

#21 2014-06-21 08:57:53

Member
Registered: 2014-06-21
Posts: 12

Re: Translate local vector to world vector

ah, ok. i cant thank you both enough for helping me!

Offline

#22 2014-06-22 01:11:51

bob bundy
Registered: 2010-06-20
Posts: 8,108

Re: Translate local vector to world vector

I'm no gamer and my programming is 'out the ark', so you'll have to excuse me if I ask obvious questions.

I've looked at your development.  Nice graphics.    Especially like the spinning Earth.  I played with the arrow keys and observed that the space ship can be made to pitch and yaw.  In space there's effectively no friction so once you start a motion it carries on until you introduce the opposite motion.    I couldn't get control well enough to be certain about this.

So what is the mission?  To 'home in' on the Earth and maybe land ?  With the car racing games I've seen, the car graphic is fixed and the background moves, giving the illusion that you're the driver hurtling round the track.  If you did the same, then all those nice graphics for the underside of the ship are wasted.  On the other hand, if you don't 'move the Earth', you won't be able to home in on it.

I see four rocket engines and once started, they kept on firing for me.  But in the Apollo missions they did short 'burns' and let the craft take up a new position.  If I call the engines (clockwise from top left) 1, 2, 3, and 4; then I'm imagining that 1+4 will make the craft yaw to the right, and 2+3 will cancel this.  1+2 to pitch down and 3+4 to cancel that.  So 1+2+3+4 would make the craft go forwards.  How will it slow down/stop ?

If that's the mission I would give the player control of the four engines and translate 'burns' into movements of the background (left-right, up-down, closer).  I don't see why you need quaternion rotation at all.

As you can see, I'm still not understanding the question yet.  To come back to your original question, you can convert a vector into a new one that is relative to a moving point just by addition.

eg.  If a train is travelling at 60 relative to the track, and a passenger walks forward along the length of the train at 3 relative to the train, then the motion of the passenger relative to the track is 63.

In general, if a point, P,  moves with vector u relative to a point A; and A moves at vector v relative to point B; then P moves at u+v relative to B

At the moment, I see space fixed (including the Earth) and the ship moves relative to this.  I'm assuming you want the ship to be the fixed, and space to move, so that we see the journey from the perspective of the pilot.

Over to you.

Bob

Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei

Offline

#23 2014-06-22 02:36:48

Member
Registered: 2014-06-21
Posts: 12

Re: Translate local vector to world vector

thank you for the compliment.

well, its very much in development, the intention is to make it mmo and give the player missions to gain levels and money to modify his or her ship to become better at blowing up other ships. create alliances to work together, etc. so its not as much a simulator as it is a game, it just fits into the category space sim.

the engines are just visuals, they dont do anything but look pretty, i'm using a physics engine (cannon.js), when rotating i give the ship an angular velocity, and indeed, once an object is in motion it stays in motion unless acted upon by another force, the physics engine does this as well, i gave it friction to allow for more control (i still have to make the visuals for slowing down the ship, both velocity and angular velocity. i'm quite satisfied about the rotation and the control over it. the problem is the velocity vector of the ship, seeing as im using two angles where i should be using three, the direction is off. for simplicity's sake, lets say the ship should always be moving forward.

let me try it this way because i just cant seem to explain the problem properly, and i apologize. it feels like trying to explain something in a foreign language.
to calculate the x, and y coordinates on a circle you have only one angle:
X = radius * cos(angle)
Y = radius * sin(angle)

to calculate the point on a sphere you need at least 2 angles:
X = radius* cos(beta) * cos(alpha);
Y = radius* cos(beta) * sin(alpha);
Z = radius* sin(beta);

now i need a way to do the same, but with all 3 angles (representing the rotation of the ship). i have a feeling the answer is staring me right in the face, but i don't understand sine cosine and tangent well enough to figure it out, though im learning fast.

Offline

#24 2014-06-23 00:04:41

bob bundy
Registered: 2010-06-20
Posts: 8,108

Re: Translate local vector to world vector

I'm still having problems understanding exactly what is needed.

What are the three angles?  How are they measured?  Can you supply a diagram ?

Is the ship moving forward properly apart from direction?

Bob

Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei

Offline

#25 2014-06-23 05:24:11

Member
Registered: 2014-06-21
Posts: 12

Re: Translate local vector to world vector

well this is exactly where i run into trouble. i cant explain what i dont understand. anyways, here's what's happening in the code:
i set a euler (x, y and z rotation of the ship, relative to the world, in radians) by converting quaternions.
now i need to use those angles plus a velocity to calculate the end point of the velocity vector.

i've made some minor modifications to the code, the axis you're seeing should always be in front of the ship.

if this still doesnt clear it up, i give up, cant explain it, thanks for trying tho.

Offline