Rotate 3D vector around axis

When dealing with rotations, it’s probably best to use quaternions, so you could use Quat.setFromAxisAngle:

from panda3d.core import *

axis = Vec3(-5.4, 7.3, 1.8)
# the axis vector must be unit length
axis.normalize()
# the angle is given in degrees
angle = 34.5
quat = Quat()
quat.setFromAxisAngle(angle, axis)
vec = Vec3(2.6, -3.1, 4.9)
rotated_vec = quat.xform(vec)
2 Likes