Specifying Direction Vectors

Started by
2 comments, last by Xashikolauk 18 years, 10 months ago
Here's what I'm trying to do: Given a user-specified 2-tuple of radian measures(which we will call A), I want to be able to locate a normalized 3d vector which is rotated from the starting position (1,0,0) to the left by A[0] radians, and then ascended upwards by A[1] radians. Basically, the user inputs something such as "(85 degrees, 42 degrees)"; I then want to find the normalized vector which points 85 degrees counter-clockwise from the positive x-axis, and is then acclinated 42 degrees upward from the x-z plane. This would allow them to specify any direction in a format that is easily human understandable. The first step is easy enough, just multiply the vector (1,0,0) by the standard y-axis rotational matrix for A[0]. I'm having trouble doing the acclination though. My best-guess is that I need to rotate it around a perpendicular line; however, I don't know how to find that line nor how to construct a rotational matrix for it. If anyone could point me in the right direction, or describe a simpler method, it would be a big help.
Advertisement
Well, the line you want to rotate around is 0,0,1 at the start, so after rotating 1,0,0 by 85 degrees, you should also rotate this axis by the same amount.

Your matrix will do this for you. Calculate the rotation matrix you need for the rotation of your direction around 0,0,1. Multiply it by the rotation you need around 0,1,0. This gives a final matrix, which is what you want. Be careful, as if you multiply them the wrong way round, it will rotate up first, and then around, instead.
In addition to Squirm's solution, you might also consider spherical coordinates (which is pretty much equivalent). Off the top of my head:

x = cos(A[0])*cos(A[1]);
z = sin(A[0])*cos(A[1]);
y = sin(A[1]);

You might have to flip the sign of z to get the direction of rotation that you want.
Thanks, a google of "Spherical Coordinates" gave me all the info I'd ever want.

This topic is closed to new replies.

Advertisement