Lost in vectors... again !

N_Molson

Addon Developer
Addon Developer
Donator
Joined
Mar 5, 2010
Messages
9,286
Reaction score
3,254
Points
203
Location
Toulouse
Hello, :hello:

I'm trying to express an engine exhaust direction in a normalized way. But I'm not sure of the formula. To be correct, the Z component must take into account both X and Y components.

pitch_angle : the angle the nozzle will make from the center position (yaw and roll).

yr_angle : the angle the nozzle will make from the center position (yaw and roll).

SetThrusterDir (th_main[0], _V(+cos(yr_angle*RAD), +cos(pitch_angle*RAD), sin ???));

Thanks a lot, its quite important for me to be 100% certain of that formula. :tiphat:

---------- Post added 07-11-12 at 12:20 AM ---------- Previous post was 07-10-12 at 07:18 PM ----------

Well, here's what I found... it seems to work, as the sum of all the vector components remains equal to 1.

vector.z = 1 - (cos(pitch_angle*RAD)+cos(yr_angle*RAD))
 

Jarvitä

New member
Joined
Aug 5, 2008
Messages
2,030
Reaction score
3
Points
0
Location
Serface, Earth
Not enough information here.

Assuming the base thrust vector is along the positive z axis,

[MATH]x=r\ sin\,\theta\ cos\,\phi[/MATH][MATH]y=r\ sin\,\theta\ sin\,\phi[/MATH][MATH]z=r\ cos\,\theta[/MATH]
θ being the angle between the z axis and the rz plane (pitch) and φ being the angle between the x axis the the projection of r onto the xy plane (yaw).
 

SiameseCat

Addon Developer
Addon Developer
Joined
Feb 9, 2008
Messages
1,699
Reaction score
1
Points
0
Location
Ontario
You actually want

Code:
vector.z = sqrt(1 - pow(cos(pitch_angle*RAD), 2) + pow(cos(yr_angle*RAD)), 2))

This is because the length of a vector is defined as
[math]\sqrt{x^2 + y^2 + z^2}[/math]
Simply adding up the components is a good approximation when 2 of the values are small, but it isn't precisely correct.
 

N_Molson

Addon Developer
Addon Developer
Donator
Joined
Mar 5, 2010
Messages
9,286
Reaction score
3,254
Points
203
Location
Toulouse
Good to know, thanks !

---------- Post added at 09:25 AM ---------- Previous post was at 02:27 AM ----------

Hmm... When I use "GetThrusterDir" and sum up the 3 components to check, I don't get exactly 1 when the thruster is gimbaled using that formula for the .z component (I modified the parenthesis, there was something wrong) :

sqrt(1 - pow(cos(pitch_angle*RAD), 2) + pow(cos(yr_angle*RAD), 2))

I get close values, but not exactly 1.

While I get a nice round 1 using that one :

1 - (cos(pitch_angle*RAD)+cos(yr_angle*RAD))

:hmm: :hmm: :hmm:
 
Last edited:

Jarvitä

New member
Joined
Aug 5, 2008
Messages
2,030
Reaction score
3
Points
0
Location
Serface, Earth
[/COLOR]Hmm... When I use "GetThrusterDir" and sum up the 3 components to check, I don't get exactly 1 when the thruster is gimbaled using that formula for the .z component (I modified the parenthesis, there was something wrong) :



I get close values, but not exactly 1.

While I get a nice round 1 using that one :



:hmm: :hmm: :hmm:


A normalised vector has length 1. Its components don't necesarrily sum up to 1.
 
Top