View Full Version : Simple trig problem but always comes up with error

Schlogenburg

09-05-2000, 03:12 PM

I have a vector with magnitude of 50.

I have an angle on the x axis of 45, and angle on y axis of 132.

(don't tell me specifically the answer, give me how you got it)

and I have the coordinate in 3d space(xyz) that I want the vector to go from. So this vector would point out from this coordinate at the given angles and I want the coordinate it ends at.

it should be something like this?

nx=cos()*vectormagnitude

ny=sin()*vectormagnitude

nz=tan()*vectormagnitude

but the way I have it the Y get's all screwed up, way out of what it should be.

In other words, you want to rotate a point in three dimensions. Then you need to solve this:

v'=ZYXv

where v is the start position of your point (your vector with a magnitiude of 50 at xyz), and X, Y & Z are your matricies to rotate a point laong the X, Y and Z axis respectivly.

the eqns you'll get if you expand the matricies out have a few more terms than you'd care to poke a stick at =)

that is, if I understood your point correctly...

if you want the rotation matricies, check out the web or the back of the red book. they rotate homogeneous coords; in practice, you probably don't want to compte the w coordinate.

cheers

john

For a vector with angle PHI to the y-axis and THETA to the x-axis (assuming a left-handed coord system):

mag = magnitude(vector); // in your case 50

vy = mag*cos(PHI);

vtemp = mag*sin(PHI);

vx = vtemp*cos(THETA);

vz = vtemp*sin(THETA);

-or-

vy = mag*cos(PHI);

vx = mag*sin(PHI)*cos(THETA);

vz = mag*sin(PHI)*sin(THETA);

in either case, add those three elements to the coordinates of the point from which you want it to originate and you'll get the final coords.

Uh.. actually the code above assumes (perhaps erroneously) that the angle to the x-axis lies in the x-z plane. That is, I assumed that the projection of your vector onto the x-z plane had an angle of THETA with the x-axis.

Sorry.

I'm interested in the answer to this problem. I think this question is similar to the one I posted a few questions ago. (however, he must have asked it much more elegantly, for I haven't got any replies yet... http://www.opengl.org/discussion_boards/ubb/smile.gif

Schlogenburg

09-06-2000, 06:15 PM

Can you tell me the difference between Theta and Phi, and how to acquire those?

steveo

09-07-2000, 09:45 AM

If 45 is the angle between the vector and the x axis ... ( as distinct from the angle projected onto a plane see prev. post) then

nx=50*cos(45)

ny=50*cos(132)

nz=square root of (50*50-nx*nx-ny*ny)

BTW if you know what the angle between the vector and the z axis is then

nz=50*cos(the angle)

Steve

Don't forget, by the way, that the math.h routines for C/C++ work on radians, not degrees.

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.