Combine Rotation Axis Vectors
Asked Answered
A

4

10

I'm experimenting with using axis-angle vectors for rotations in my hobby game engine. This is a 3-component vector along the axis of rotation with a length of the rotation in radians. I like them because:

  • Unlike quats or rotation matrices, I can actually see the numbers and visualize the rotation in my mind
  • They're a little less memory than quaternions or matrices.
  • I can represent values outside the range of -Pi to Pi (This is important if I store an angular velocity)

However, I have a tight loop that updates the rotation of all of my objects (tens of thousands) based on their angular velocity. Currently, the only way I know to combine two rotation axis vectors is to convert them to quaternions, multiply them, and then convert the result back to an axis/angle. Through profiling, I've identified this as a bottleneck. Does anyone know a more straightforward approach?

Abruzzi answered 30/11, 2010 at 17:42 Comment(2)
Does that mean that 3 values represent sequential rotations about 3 orthogonal axis? Basically, euler angles such that [phi,psi,theta] may represent RX(phi)*RY(psi)*RZ(theta). If that is the case you need to find a way to construct the 3x3 rotation matrix, and pull the axis-angle from it.Oyster
No, I'm not using euler angles. This is axis angle where the length of the vector is the angle.Abruzzi
F
3

Old question, but another example of stack overflow answering questions the OP wasn't asking. OP already listed out his reasoning for not using quaternions to represent velocity. I was in the same boat.

That said, the way you combine two angular velocities, with each represented by a vector, which represents the axis of rotation with its magnitude representing the amount of rotation.

Just add them together. Component-by-component. Hope that helps some other soul out there.

Fuse answered 20/12, 2021 at 22:47 Comment(2)
Your answer helped me! I appreciate the simplicity of your solutionVanquish
Matrix multiplication and quaternions are hard to understand and expensive to compute, so after taking a newtonian physics class, I wondered if I could apply the torque angle-axis vectors thing to my 3D graphics hobby :)Vanquish
M
2

You representation is equivalent to quaternion rotation, provided your rotation vectors are unit length. If you don't want to use some canned quaternion data structure you should simply ensure your rotation vectors are of unit length, and then work out the equivalent quaternion multiplications / reciprocal computation to determine the aggregate rotation. You might be able to reduce the number of multiplications or additions.

If your angle is the only thing that is changing (i.e. the axis of rotation is constant), then you can simply use a linear scaling of the angle, and, if you'd like, mod it to be in the range [0, 2π). So, if you have a rotation rate of α raidans per second, starting from an initial angle of θ0 at time t0, then the final rotation angle at time t is given by:

θ(t) = θ0+α(t-t0) mod 2π

You then just apply that rotation to your collection of vectors.

If none of this improves your performance, you should consider using a canned quaternion library as such things are already optimized for the kinds of application you're disucssing.

Machree answered 30/11, 2010 at 21:54 Comment(2)
1. My vectors are not unit length. Their length is the angle of rotation in radians. 2. I do use a quaternion data structure. 3. In many cases, my angle isn't the only thing changing, but this would be a good optimization check.Abruzzi
"work out the equivalent quaternion multiplications / reciprocal computation to determine the aggregate rotation" Is this the same as converting from axis-angle to quaternion and back again? My current implementation is from the Matrix and Quaternion FAQ (j3d.org/matrix_faq/matrfaq_latest.html)Abruzzi
J
2

You can keep them as angle axis values.

Build a cross-product (anti-symmetric) matrix using the angle axis values (x,y,z) and weight the elements of this matrix by multiplying them by the angle value. Now sum up all of these cross-product matrices (one for each angle axis value) and find the final rotation matrix by using the matrix exponential.

If matrix A represents this cross-product matrix (built from Angle Axis value) then,

exp(A) is equivalent to the rotation matrix R (i.e., equivalent to your quaternion in matrix form).

Therefore,

exp (A1 + A2) = R1 * R2

probably a more expensive calucation in the end...

Jeffersonjeffery answered 21/10, 2013 at 19:32 Comment(0)
H
1

You should use unit quaternions rather than scaled vectors to represent your rotations. It can be shown (not by me) that any representation of rotations using three parameters will run into problems (i.e. is singular) at some point. In your case it occurs where your vector has a length of 0 (i.e. the identity) and at lengths of 2pi, 4pi, etc. In these cases the representation becomes singular. Unit quaternions and rotation matrices do not have this problem.

From your description, it sounds like you are updating your rotation state as a result of numerical integration. In this case you can update your rotation state by converting your rotational rate (\omega) to a quaternion rate (q_dot). If we represent your quaternion as q = [q0 q1 q2 q3] where q0 is the scalar part then:

q_dot = E*\omega

where

    [ -q1 -q2 -q3 ]
E = [  q0 -q3  q2 ]
    [  q3  q0 -q1 ]
    [ -q2  q1  q0 ]

Then your update becomes

q(k+1) = q(k) + q_dot*dt

for simple integration. You could choose a different integrator if you choose.

Horsefly answered 1/12, 2010 at 4:39 Comment(3)
What does it mean for the rotation to become singular, and what kind of problem will this bring?Abruzzi
It may or may not cause a problem. It means that at those locations you effectively loose a degree of freedom. This in turn means that if you wish to transform rates between your representation and another (say quaternions) the transformation matrix (i.e. Jacobian) is singular (cannot be inverted).Horsefly
Why is it a problem if an identity rotation loses a degree of freedom, since it's not rotating anything anyways?Propagandist

© 2022 - 2024 — McMap. All rights reserved.