Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Okay, I am a programmer, and I am working on some procedural generation, yada yada. I have a cube, which I will refer to as the "object". This cube's rotation is depicted via a grouping of two variables:

Vector3 direction; <-- THis variable is a vector of size 3, and named direction

float tilt; <-- This variable is a vector, of size 1, and named tilt

Direction specifies what way our object points. Tilt specifies the local rotation AROUND that direction. I will elaborate on this.

Direction specifies what way our object points, by assuming our cube is at the position (0,0,0), and then depicting a position. The object points to that position, from (0,0,0). For instance, if Direction were (0,1,1), the position would be one away from the object on both the Y and Z axis. In order for the object to point towards this position, the object would be rotated by 45 degrees around its X axis.

One further variable, tilt, is needed to specify the object's local rotation when pointing to its direction. In other words, imagine a 3D pyramid, pointing from (0,0,0) to (0, 1, 0). (we assume that the Y axis is up). The pyramid, can be rotated however it likes along its Y axis, and still be pointing to (0, 1, 0). Tilt specifies how it is rotated along its Y axis. Except, the Y axis is rotated, so if the pyramid were pointing to (0, 1, 0.5) (imagine a leaning pyramid), tilt would pretend that the pyramid is pointing straight up, and rotate the pyramid around that relative up.

Long story short, I want to know how to modify Direction, so as to rotate the object around a particular axis. For instance, if I want to rotate the object around the Y axis, how do I modify the X and Z axes to have the object rotated by a certain amount around the Y axis. I would like this to be as simple as possible -- The operation will be done many times in a row by the computer, and I do not want this math slowing my processing down.

share|improve this question
All three sentences in the second paragraph require some clarification. By the first, I presume you mean the same as "direction represents an axis"? In the second, what does "the rotation would be 45 degrees rotated around the x axis" mean, and how is this related to the vector $(0,1,1)$? In the third, what does "locally" mean, and which axis is "that axis" -- the $x$ axis? I suspect it might take several attempts to find out what you mean; don't worry if you're unsure about the terminology; just write more and it will hopefully become clearer and then someone else can clean up the question. –  joriki Jan 15 '12 at 8:42
Okay, so, basically... My direction is represented by a vector3. This vector3 is an offset from the point's center. In other words, imagine a line, going from (0,0,0), to (0,1,1). The direction that line points is the direction that my vector3 represents. Now, imagine that direction were an axis, like any other. The tilt specifies how many degrees to rotate around the axis formed by this direction. I say locally, because this imaginary axis basically acts as a local z axis. As you rotate object's, the direction of the "up" of the object changes. (Continued in next comment) –  Georges Oates Larsen Jan 23 '12 at 0:13
(Continuation) Rotating around the local z axis rotates the object around it's relative up –  Georges Oates Larsen Jan 23 '12 at 0:13
I think I understand most of what you're saying in that comment, but I can't put it together with what you wrote in the question and it doesn't really answer the questions in my comment. The $x$ axis no longer occurs in your comment -- how does the statement "The tilt specifies how many degrees to rotate around the axis formed by this direction" fit with the statement "the rotation would be 45 degrees rotated around the x axis. Then, the tilt could locally rotate my "direction" around that axis."? Why does one of these talk about the $x$ axis and the other one doesn't? –  joriki Jan 23 '12 at 0:28
I am just going to re-explain from the beginning, I will rewrite the question –  Georges Oates Larsen Jan 23 '12 at 1:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.