Rotate object using 2 vectors

using two perpendicular vectors, you can get a third axis by calculating the cross product of the first and second axis.

up_vector = vec1.normalized()
right_vector = vec2.normalized()
fwd_vector = up_vector.cross(right_vector)

once you have three cartesian axes vectors you can easily create a 3x3 rotation matrix once you know how a blender matrix is composed

and lastly, once you’ve got a 3x3 rotation matrix, you can transform your object using matrix multiplication
oldmat.to_3x3() @ new_rot.to_3x3()

2 Likes