# Vector rotation calculation

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

## Recommended Posts

Hello everyone,

I need to calculate to be able to calculate a rotation vector from a set of rotation around 3 axes (x,y,z) with z

being up, x being right, y out.

I first came up with this pseudo code:

But when I multiplied these rotation vectors with a point, I, of course, always ended up with (0,0,0).

So I quickly replaced the 0's in the first snipped to 1.0 to preserve the values calculated in the other vectors.
Now this worked for all the individual axes, but when combining them, it'll produce invalid results.

Can someone look at my pseudo-code and tell me what I'm doing wrong?

##### Share on other sites
Your math is wrong in so many ways.. To rotate a point around an axis, you cannot just pointwise multiply it by another vector. It does not produce a point rotated by anything.

There does not exist such a mathematical term as "a rotation vector from a set of rotation around 3 axes (x,y,z) with z".

To represent a rotation operation in 3D space, you want to be looking for:

• axis-angle representation of rotation. This is a normalized vector (x,y,z) representing the axis of rotation, and a scalar angle r that represents the amount to rotate around that axis.
• Euler angle representation of rotation. These are the triplets of form (a,b,c).
• 3x3 rotation matrices (if rotating around an axis passing through the origin).
• 3x4 rotation matrices with a translation (if rotating around an axis passing through an arbitrary point).
• Unitary quaternions. (4D extensions of the complex numbers, of form r + xi + yj + zk). These rotate around an axis through the origin.The two first representations are only representations. There does not exist simple formulas to rotate points using those data structures. The three latter representations are effective computational representations. You can use 3x3 matrices, 3x4 matrices and unitary quaternions to rotate points in 3D space. The two first representations are convenient for humans, the three latter are effective for arithmetic.

For example C++ code snippets on how to convert between these different representations, you can try browsing through the MathGeoLib codebase (in my sig).

##### Share on other sites
You kind of have the right idea of trigonometry. But you need a full matrix in the end. Look up 3D rotation matrix and you will get something close to what you have. You have half of the matrices written out, but not the second half, there are 2 more sin and cos calculations that are needed when you multiply your point.

You have achieved something close, but look at this picture on here. Look how computing a' and b' are different. So your rotateX() is wrong in one case. So you have to build a matrix. So for instance b' in the diagram the Y component is actually cosine() where in vector a' the X component is cosine().
http://www.cgafaq.in...tation_Formulas

So to what the other guy said, your math is not actually wrong at all, very close, but incomplete. Go back and take a' and rotate it by the same angle again. The only input you have is a', so how would you compute a'' from just knowing a'? So after applying cosine you multiply cos()*(1,0) the x-axis. You just don't see the 0 yet. The second time you rotate to a'', you are opening cos()*(a'x, a'y) So its actually cos() being the portion of the old vector. Or as I said cos()*(1,0). Something like that.

Better example. You also need the double angle formula for substitution:
http://graphics.cs.c...3Dmath-11-2.pdf

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633709
• Total Posts
3013481
×