Vectors

Author
Discussion

RizzoTheRat

Original Poster:

26,012 posts

199 months

Sunday 25th February 2018
quotequote all
I have a vector in 3 dimensions (acceleration), and another unit vector (direction a vehicle is facing). How can I calculate if the first vector is positive or negative in the direction of the second vector? In 2D I'd be looking at the angles between them, but can't get my head round it in 3D

Edited by RizzoTheRat on Sunday 25th February 17:26

Einion Yrth

19,575 posts

251 months

Sunday 25th February 2018
quotequote all
Normalise the vectors (optional) and take the dot product, if the result is negative then they're pointing in opposing directions.

RizzoTheRat

Original Poster:

26,012 posts

199 months

Monday 26th February 2018
quotequote all
That did the job, thanks.

So is the dot product of the acceleration vector and another unit vector going to tell the the acceleration in the direction of the unit vector?

Einion Yrth

19,575 posts

251 months

Monday 26th February 2018
quotequote all
RizzoTheRat said:
That did the job, thanks.

So is the dot product of the acceleration vector and another unit vector going to tell the the acceleration in the direction of the unit vector?
The dot product of two normalised vectors will yield the cosine of the angle between them. I'm not quite sure what you are asking, happy to help, but I need to comprehend the question smile.

FarmyardPants

4,173 posts

225 months

Monday 26th February 2018
quotequote all
RizzoTheRat said:
That did the job, thanks.

So is the dot product of the acceleration vector and another unit vector going to tell the the acceleration in the direction of the unit vector?
Yes

FarmyardPants

4,173 posts

225 months

Tuesday 27th February 2018
quotequote all
FarmyardPants said:
Yes
Although if you're doing a simlulation it is more common to add up the forces and use the equivalent force to derive the acceleration.

RizzoTheRat

Original Poster:

26,012 posts

199 months

Tuesday 27th February 2018
quotequote all
Einion Yrth said:
The dot product of two normalised vectors will yield the cosine of the angle between them. I'm not quite sure what you are asking, happy to help, but I need to comprehend the question smile.
Programming some autopilot functionality in a space simulation game (Kerbal Space Programme). I'm finding it rather interesting as the the game uses real world physics for almost everything, but my engineering degree was a long time ago biggrin

It works in a vector co-ordinate system centred on the middle of the planet, with the axes through the pole, 0 and 90 degrees longitude, so if I want to calculate the acceleration towards the ground it seems I can take the dot product of the normalised gravity vector and the acceleration vector. Not sure how I'm going to work out a horizontal vector yet though, the scalars easy enough as I know the total vector and the vertical component, but not got my head around directions in this thing yet.


Einion Yrth

19,575 posts

251 months

Tuesday 27th February 2018
quotequote all
RizzoTheRat said:
Not sure how I'm going to work out a horizontal vector yet though,
Cross product of the two unit axes, will generate a vector normal to them both, which should be horizontal.
ETA
Of course it will only be horizontal at the intersection of the axes with Kerbin's surface, so not a complete solution.

Edited by Einion Yrth on Tuesday 27th February 12:05

RizzoTheRat

Original Poster:

26,012 posts

199 months

Wednesday 28th February 2018
quotequote all
FarmyardPants said:
Although if you're doing a simlulation it is more common to add up the forces and use the equivalent force to derive the acceleration.
Yeah, I'm trying to keep everything in vector form as much as I can, but separating some stuff in to components helps me understand what's going on, especially as I can read off vertical distance/velocity and horizontal velocity from the interface to check.

Einion Yrth said:
Cross product of the two unit axes, will generate a vector normal to them both, which should be horizontal.
ETA
Of course it will only be horizontal at the intersection of the axes with Kerbin's surface, so not a complete solution.

Edited by Einion Yrth on Tuesday 27th February 12:05
Not sure I quite understand that. If I have a velocity vector in 3D (lets say 100m/s North East 10 degrees below the horizon, but in a co-ordinate system which is not North/East/Up), and a unit vector in the Up direction, I can easily work out the upward component from the dot product, but would like tyo work out the direction North East.
If the Cross product is 90 degrees to both vectors won't that be South East or North West?


FarmyardPants

4,173 posts

225 months

Wednesday 28th February 2018
quotequote all
If you're flying 100m/s NE and 10 degrees relative to the NE plane, then your NE component is simply 100*cos(10deg). Your "up" (or "down") component relative to the plane is 100*sin(10deg).

Another way to do this is to make a transformation matrix that rotates one coordinate system (e.g. the identity where {0,1,0} is north/up, for example) to the other (the ship's, where {0,1,0} is "up" from the pilots point of view and {0,0,1} perhaps is the direction of travel.

Then you can multiply a vector by this matrix and get a vector in the other coord system and just read off x,y and z components. Edit: or multiply by the inverse of said matrix to go the other way.

It's easy enough to model gravitation as point sources but once you start to consider the orientation of (say) a spaceship orbiting the Earth with the Earth's surface "below" him it can get rather complicated. Especially when the ship starts making manoeuvres and you have to work out the order of rotations etc.

Edit: to work out the new velocity vector if the pilot pulls up on the stick, as it were, you need to notionally rotate the ship along the various axes to be aligned with the world, apply an X (?) axis rotation to the velocity vector (say {0,0,s} where s is the "speed"), and then apply the inverse operations. The vector you end up with gives your new velocity. Fortunately you can multiply all the matrices together to give a single transformation matrix. A library like OpenGL handles a lot of this (the maths anyway) for you smile

Edited by FarmyardPants on Wednesday 28th February 13:05


Edited by FarmyardPants on Wednesday 28th February 13:07

RizzoTheRat

Original Poster:

26,012 posts

199 months

Wednesday 28th February 2018
quotequote all
The horizontal speed is easy enough to find as you describe (although I'd presumably need to use the 100 degrees from UP rather than 10 below the horizon as Up is the only reference direction I have), it's the direction (ie NE) in the coordinates of the vector axes that I'm struggling with, and I think is where you were going with your second paragraph, but I'm still not understanding it.

ETA: Thinking about it I don't know its 100 degrees below the vertical without some extra maths so it's easier to get the speed by Pythagoras, ie:

If I assume I have a velocity vector VEL and a unit vector facing upwards called UP then I know that:

Upward speed is DotProduct(UP,VEL)

Horizontal speed is then going to be sqrt( (magnitude of velocity vector)^2 - (Upward speed)^2)

If I simply subtract the upward vector (UP x Upward Speed) from the original vector that gives me the velocity vector in the horizontal plane doesn't it?



Edited by RizzoTheRat on Wednesday 28th February 14:16


Edited by RizzoTheRat on Wednesday 28th February 14:17

FarmyardPants

4,173 posts

225 months

Wednesday 28th February 2018
quotequote all
RizzoTheRat said:
The horizontal speed is easy enough to find as you describe (although I'd presumably need to use the 100 degrees from UP rather than 10 below the horizon as Up is the only reference direction I have), it's the direction (ie NE) in the coordinates of the vector axes that I'm struggling with, and I think is where you were going with your second paragraph, but I'm still not understanding it.

ETA: Thinking about it I don't know its 100 degrees below the vertical without some extra maths so it's easier to get the speed by Pythagoras, ie:

If I assume I have a velocity vector VEL and a unit vector facing upwards called UP then I know that:

Upward speed is DotProduct(UP,VEL)

Horizontal speed is then going to be sqrt( (magnitude of velocity vector)^2 - (Upward speed)^2)

If I simply subtract the upward vector (UP x Upward Speed) from the original vector that gives me the velocity vector in the horizontal plane doesn't it?



Edited by RizzoTheRat on Wednesday 28th February 14:16


Edited by RizzoTheRat on Wednesday 28th February 14:17
Yes, I think so. That will give you the magnitude of the component that is not "up" (ie sideways/forwards) but of course it won't tell you about the directions of either. As an aside I think the cross product of VEL and UP will yield a vector with the same length (as the "not up" vector) pointing in the direction of "left".