• 13
• 15
• 27
• 9
• 9

# vector rotation????

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

## Recommended Posts

I'm trying to rotate a position vector by an orientation vector, I'm pretty sure I have to do some vector multiplication somewhere in this process but can someone explain the process of rotating the vector by the orientation??

##### Share on other sites
What do you mean "orientation vector" ? There's no such thing as far as I know: the usual way of specifying the orientation of an object is with a quaternion or matrix. Personally I prefer and use quaternions though you can use matrices.

If you have a vector + angle you can generate a quaternion which does the rotation though the angle about the vector axis, like so

(q0, q1, q2, q3) = (cos (t), x sin(t), y sin(t), z sin(t))

where (x, y, z) is a unit vector along the axis and t is the angle. You can then use this to rotate vectors around the axis.

##### Share on other sites
Quote:
 Original post by Anonymous PosterWhat do you mean "orientation vector" ? There's no such thing as far as I know: the usual way of specifying the orientation of an object is with a quaternion or matrix. Personally I prefer and use quaternions though you can use matrices.If you have a vector + angle you can generate a quaternion which does the rotation though the angle about the vector axis, like so(q0, q1, q2, q3) = (cos (t), x sin(t), y sin(t), z sin(t))where (x, y, z) is a unit vector along the axis and t is the angle. You can then use this to rotate vectors around the axis.

Minor fix: should be t/2 in place of t.

(i'm not AP)

##### Share on other sites
Say omega is your rotation vector (ox, oy, oz)
                               0 -oz oyyou need the matrix [omega] =  oz 0 -ox                              -oy ox 0

to rotate a vector you need to apply this matrix to the vector

##### Share on other sites
I don't think the skew symetric matrix can be used this way _Vlad. As far as I know its just a maths trick for rearanging equations rather than having a geometrical meaning like this. Just try plugging a simple vetor in like (0,0,1) and have a look at the matrix that comes out. Clearly not an orientation matrix, for a start the z axis comes out all zeros! As AP says, I don't think orientation can be represented by just a vector in 3D space.

##### Share on other sites
All this skew symmetric matrix does is perform a cross product with any vector it's multiplied by. It's useful if you want to compute the velocity at a radius r based on the angular velocity w, i.e. w x r = v, but it doesn't rotate the vector.

Normally a rotation around a vector is represented by a normalized vector n and the angle of rotation t -- i.e. the amount of rotation around that axis. For a non-normalized vector, I suppose you could treat the length as the angle of rotation. Anyway, assuming you have n and t, the formula (called the Rodrigues formula) is

Rv = cos(t)v + [1 - cos(t)](v*n)n + sin(t)(n x v)

where '*' is dot product and 'x' is cross product.

Alternatively, you can use a quaternion, as described in a previous response, which bakes a lot of these calculations in.

If you have a number of vectors to rotate, you can convert the rotation to a matrix, which will be much cheaper in the long run. That looks like (assuming you're using column vectors):

| (kx^2 + c) (kxy - sz) (kxz + sy) |
| (kxy + sz) (ky^2 + c) (kyz - sx) |
| (kxz - sy) (kyz + sx) (kz^2 + c) |

where n = (x,y,z), c = cos(t), s = sin(t), k = 1-cos(t)

Edit: tweaked matrix

##### Share on other sites
Well, let me give an example of what I have and how I'm trying to abbly it. I have a 3d object which has a position and an angle. I'm able to rotate this object just by incrementing/decrementing its angle (and throwing that angle into glRotate for a specific axis). This object also has a vector that represents its orientation. The reason for this is because I wanted to object to move forward relative to the direction it was facing. To move my object according to its orientation I do this:

P1->orientation.xpos = sin(P1->angle/180*3.1415);
P1->orientation.zpos = cos(P1->angle/180*3.1415);

P1->position.xpos += P1->orientation.xpos * frameTime;
P1->position.zpos += P1->orientation.zpos * frameTime;

This accomplishes what I want it to do in terms of moving the object according to the direction its facing. What I was hoping to accomplish was using this technique to recompute the axis aligned bounding box of the object by rotating the max and min vectors of the box by the angle in which the object rotated. I know there is a really easy way to do this but its not coming to me. Where do I start???

##### Share on other sites
From your last post it sounds like you have:

A 3D position
A y-rotation angle
A forward vector

I'm assuming it's a rotation about the y axis as only x and z change when the angle changes. The vector you then get I would describe as the forward vector, i.e. the direction it's facing you mention.

The 3D matrix that gives this rotation is:

{ cos(t),      0,-sin(t)},{      0,      1,      0},{ sin(t),      0, cos(t)},

Where 't' is shorthand for your P1->angle/180*3.1415. The matrix elements are the same as your orientation/forward vector so you can just drop them in along with the '1' and zeros.

##### Share on other sites
does this equation apply to the max and min vectors of the bounding vectors as well in terms of rotating them??

##### Share on other sites
Quote:
 Original post by jon723does this equation apply to the max and min vectors of the bounding vectors as well in terms of rotating them??

Yes. You can transform the vertices, edges, normals etc. using this matrix, as well as the corners of the bounding box. That's assuming you want to rotate it. If it's an axis aigned bounding box you DON'T rotate it, instead you have to recalculate it using the transformed vertices.