If you want to rotate a point by an angle around a specific axis, you will most likely think about Quaternions. But what if I told you there is another way? Rodrigues' formula is as simple as it can be. I never benchmarked it, and chances are, for our needs, it's slower than over-optimized quaternions. But I find it pretty interesting, and hey, it's always nice to have alternatives =]
There is not much more to say about it, so I'll just go ahead and provide a python snippet
import numpy as np
def rodrigues_formula(point: list, angle: float, vector: list):
return point*np.cos(angle) + \
np.cross(vector, point) * np.sin(angle) + \
vector * np.dot(vector, point) * (1-np.cos(angle))
And to use it:
# create an input locator, randomly placed
input_point = cmds.spaceLocator(n='input_point')[0]
v = np.random.rand(3)
cmds.setAttr(f'{input_point}.t', *v)
angle = np.pi/4. # let's do 45 deg because why not
k = np.array((1, 0, 0)) # rotate around the X axis
result = rodrigues_formula(point=v, angle=angle, vector=k)
# now let's see how it looks
loc = cmds.spaceLocator()[0]
cmds.setAttr(loc + '.t', *result)
Voila, we just rotated our input locator by 45 degrees around the X axis. Just for fun, I did the same operation with a quaternion, and we can see the result is identical
from maya.api.OpenMaya import *
quat = MQuaternion()
quat.setValue(MVector(k), angle)
point = MPoint(v)
rotated = point * quat.asMatrix()
loc = cmds.spaceLocator()[0]
cmds.setAttr(loc + '.t', rotated.x, rotated.y, rotated.z)