Archived

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

david_crossland

newbie maths questions

Recommended Posts

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
hey..sorry i hav''nt got back to you, ive been busy so havnt had much time to formulate a proper reply. I did a quick test of the equations u gave me, i plugged them into some opengl and incremented both angles over time to see how it behaved. There seems to be a problem (bear in mind that i did this a few days ago on a different comp so i havnt got exact results). There seems to be a problem when sangle a=90 and b is incremented, it jumps.....

i know that prob makes little sense, but the equations i found

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

do seem to work for all angles, i really appreciated the help though (though i still wonder how these were derived).

im surprised as to how long i had to search to find these, i knew trig was used to break down 2-d vector problems but there seems to be little on 3-d (when using angles)

ah well thx loads
D

Share this post


Link to post
Share on other sites
hey..sorry i hav''nt got back to you, ive been busy so havnt had much time to formulate a proper reply. I did a quick test of the equations u gave me, i plugged them into some opengl and incremented both angles over time to see how it behaved. There seems to be a problem (bear in mind that i did this a few days ago on a different comp so i havnt got exact results). There seems to be a problem when sangle a=90 and b is incremented, it jumps.....

i know that prob makes little sense, but the equations i found

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

do seem to work for all angles, i really appreciated the help though (though i still wonder how these were derived).

im surprised as to how long i had to search to find these, i knew trig was used to break down 2-d vector problems but there seems to be little on 3-d (when using angles)

ah well thx loads
D

Share this post


Link to post
Share on other sites