#### Archived

This topic is now archived and is closed to further replies.

# newbie maths questions

This topic is 5845 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hi, im trying to find some math that can break down a force(vector) into its (x, y, z) componants from knowing the angle between x/y (a) and x/z (b). plse help many thx D

##### Share on other sites
here:

fy/fx=tg(a) => fy=fx*tg(a)
fz/fx=tg(b) => fz=fx*tg(b)

so we have so far F=(fx,fx*tg(a),fx*tg(b))
but we also know that f^2=fx^2x+(fx*tg(a))^2+(fx*tg(b))^2 => fx=f/sqrt(1+tg^2(a)+tg^2(b))

so, just replace the fx values back into F=(fx,fx*tg(a),fx*tg(b)), and you''ll have the force vector

##### Share on other sites
sorry but i dont understand what u have written here. Im not great at maths or physics but im trying to model an engine.

I know that an engine produces a force which travels in a particular direction ie a vector, as the engine can point in any direction in 3d space i will need to know how that force is distributed along each axis (x, y, z).

I want to control the positioning of the engine using the two angles A and B where A is some angle between the x and y axis and B is some angle between the x and z axis.

Ive been treating (x, y, z) as some point along the circumference of a sphere whose radius is the the force. Ive been trying to hunt down trigonometric equations that can deal with 3d.

My approach has been based on the knowledge that using 2d trig i can find the (x, y) lengths of a triangle formed by the points (0,0), (x, 0), (0, y) and compute either x or y by knowing only the hyp and the angle. i just want something similar to this that works for three axis as opposed to 2.

The engine is being implemented as a class in c++ and im using opengl to show me what is happening.

I hope this better explains my problem.

may thx
D

[edited by - david_crossland on June 10, 2002 3:48:25 PM]

##### Share on other sites
you want code?

here :

  tyepedef struct{  float x[3];}vector3f;vector3f buildvec(float length,float a,float b){  vector3f v;  float fx=sqrt(1.0+sqr(tan(a))+sqr(tan(b)));  v.x[0]=fx;  v.x[1]=fx*tan(a);  v.x[2]=fx*tan(b);  return v;}

[edited by - danz on June 10, 2002 3:53:47 PM]

##### Share on other sites
thx for yr effort here im gratefull, but the equations dont seem to work. the problem is that as a or b approaches 90deg then tan(a) or tan(b) approaches infinity.

thx anyway
D

##### Share on other sites
this is how the tan(x) function works, it strives to infinity every pi/2+pi*k radians

##### Share on other sites
i think i understand what u r saying but the problem remains...please excuse my stupidity if im just not seeing the obvious..

if we use fx=sqrt(1.0+sqr(tan(a))+sqr(tan(b))) then when a=90 and b=0 then fx is infinate...

i did find this which suits my need i think....im still experimenting with it...

x=force*sin(azi)*cos(decl);
y=force*sin(azi)*sin(decl);
z=force*cos(azi);

many thx for yr help

##### Share on other sites
Well I don''t know what the hell danz''s function is supposed to do. I think he made some assumptions about your problem that are not correct, and so his answer doesn''t really make sense geometrically.

I''ll try to give you something that will work. Lets first clarify your definitions. You cannot merely say that "a" is the angle between the x and y axes. It must be measured relative to something, so lets say a is measured from the positive x axis, within the xy plane. Also, since your force vector is a full 3D vector, I''m going to say that a is the angle of the force vector as projected into the xy plane.

We''ll clarify b in the same way. Lets say b is measured from the positive x axis, and lies within the xz plane. b is the angle of the projection of force into the xz plane.

I think my clarification is probably close to what you really want. This problem setup is not really the best (because finding x, y, z is more complex than it could be), but it is something we can work with. The final answer is fairly simple, but involves an atan2() calculation.

I provide below a DERIVATION of the equations, then a SOLUTION to your problem. I''ll caveat this by saying I haven''t actually tested my derivation or calcs. But they should be correct unless I made a careless algebra error.

-----------------------------------------------
DERIVATION
-----------------------------------------------

If length is the magnitude of force, then we can say the following:

(Eq. 1) x = length*cos(c)*cos(a);
(Eq. 2) y = length*cos(c)*sin(a);
(Eq. 3) z = length*sin(c);

Here, I''ve introduced a new angle, c, which is the angle between the force vector and the xy plane, measured from the xy plane. If we knew c, then we could immediately calculate (x,y,z). But we don''t know c. Note that c is not the same as b! How do we find c? By using what we know about b and the xz plane:

(Eq. 4) x = length*cos(d)*cos(b);
(Eq. 5) z = length*cos(d)*sin(b);
(Eq. 6) y = length*sin(d);

Whoa, yet another angle, d! This is the angle between the force vector and the xz plane, measured from the xz plane. Now we have 5 unknowns: (x,y,z), c, and d. But we also have 5 equations, so we can solve them for c, d, and (x,y,z). Its quite easy to do. We take the two equations (1 and 4) for x and set them equal:

x = length*cos(c)*cos(a) = length*cos(d)*cos(b)

Divide out "length" to get:

(Eq. 7) cos(c)*cos(a) = cos(d)*cos(b)

We know a and, thus cos(a) and cos(b). We can convert this into an equation we can solve for either c or d. To do this, equate the two z equations (equation 3 and 6):

z = length*sin(c) = length*cos(d)*sin(b)

Or, simplified:

(Eq. 8) sin(c) = cos(d)*sin(b)

Solve equation 8 for cos(d):

cos(d) = sin(c)/sin(b)

and plug that into equation 7 to get:

(Eq. 9) cos(c)*cos(a) = sin(c)*cos(b)/sin(b)

Divide by cos(c) and multiply by sin(b)/cos(b) to get:

(Eq. 10) tan(c) = sin(b)*cos(a)/cos(b);

Since you know b and a, you can calculate tan(b) and cos(a), and thus you can calculate tan(c). You could just to c = atan(tan(b)*cos(a)), but that''s not advisable. You have to be careful calculating tan(c). Its best to use atan2() instead of atan(). I''ll just mention that cos(a) is a scaling factor that can go in the numerator or denominator. Lets pick numerator (to avoid a divide), so:

(Eq. 11) c = atan2(sin(b)*cos(a), cos(b));

Actually, the following equation gives the same result:

(Eq. 12) c = atan2(sin(b), cos(b)/cos(a));

So, how do you use all of this?

-----------------------------------------------
SOLUTION
-----------------------------------------------

STEP 1: Calculate the angle c itself using either equation 11 or 12.
STEP 2: Calculate (x,y,z) using equations 1, 2, and 3.
STEP 3: You''re done!

That should work for any values of a and b, without concern or problem when they are 90 degrees.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

##### Share on other sites
many thx for this, im just going to injest it for a while, try to understand whats going on.

##### Share on other sites
Quoting grhodes_at_work:

"This problem setup is not really the best (because finding x, y, z is more complex than it could be), . . ."

I have to agree with him and wonder how you are getting a magnitude for a force, but not getting a vector. You might want to re-evaluate how this force value is being generated.

• 34
• 12
• 10
• 9
• 9
• ### Forum Statistics

• Total Topics
631354
• Total Posts
2999505
×