Home Website Youtube GitHub

rotateAlongAxis?

In mgear.core.vector, there is a rotateAlongAxis function.
Based on what is used in shifter, it appears to be used as the normal function of transform.getTransformLookingAt.
I had some idea of the use, but I didn’t know the principles.
What should I look for to find out about this?

Hi @1114 I just noticed this unanswered thread. Did you ever figure it out?

In general, it works basically like this:

  1. You start with a vector. (Blue arrow in my illustration.)
  2. You want to rotate it. But you can only rotate it in a circle, around an axis that you specify. (Another vector.)
  3. You define the angle in radians, for how much you want it to rotate around that circle.

To use the function, you have to pass it vectors. You can create those by using different functions like PyNode.getTranslation() as an example. But here is another example using OpenMaya objects.

I also define a function, so I can specify the rotation in degrees instead of radians.

I take a vector (1,0,0) pointing in X and rotate it around a y-facing-up vector (0,1,0). I rotate it 90 degrees. And now the result is (0,0,1), pointing in Z. The result will be rounded in weird ways sometimes. So you could use the Python round() function.

import math
import maya.OpenMaya as OpenMaya

def radians_from_degrees(deg):
    return deg * math.pi / 180.00

vector1 = OpenMaya.MVector(1, 0, 0)
vector2 = OpenMaya.MVector(0, 1, 0)
result = mgear.core.vector.rotateAlongAxis(vector1, vector2, radians_from_degrees(90))
print(round(result.x), round(result.y), round(result.z))

# result is (0,0,1)
4 Likes