Simple trig problem but always comes up with error

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?

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:


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.


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 = magcos(PHI);
vtemp = mag
vx = vtempcos(THETA);
vz = vtemp

vy = magcos(PHI);
vx = mag
vz = mag

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.


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…

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

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


nz=square root of (5050-nxnx-ny*ny)

BTW if you know what the angle between the vector and the z axis is then
nz=50*cos(the angle)


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