# Specifying Direction Vectors

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

## Recommended Posts

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.

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
Thanks, a google of "Spherical Coordinates" gave me all the info I'd ever want.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 12
• 10
• 11
• 13
• ### Forum Statistics

• Total Topics
634095
• Total Posts
3015477
×