解决了!创建了两个向量作为 numpy 数组,向量 1 和向量 2,并找到了 open3d 命令来使网格居中并在两个向量之间应用旋转矩阵。认为这很容易受到万向节锁定的影响,但我无法理解四元数,它对于我的使用场景来说已经足够好了。
#this function to create a rotation matrix was taken from https://stackoverflow.com/q/63525482/6010071
def rotation_matrix_from_vectors(vec1, vec2):
a, b = (vec1 / np.linalg.norm(vec1)).reshape(3), (vec2 / np.linalg.norm(vec2)).reshape(3)
v = np.cross(a, b)
c = np.dot(a, b)
s = np.linalg.norm(v)
kmat = np.array([[0, -v[2], v[1]], [v[2], 0, -v[0]], [-v[1], v[0], 0]])
rotation_matrix = np.eye(3) + kmat + kmat.dot(kmat) * ((1 - c) / (s ** 2))
return rotation_matrix
#to move the mesh to 0,0,0 (using open3d library)
mesh.translate(-mesh.get_center())
# to rotate the mesh to variable vector2, i set it to np.array([0,0,1]) = in line with z axis again using open3d library
mesh.rotate(rotation_matrix_from_vectors(vector1,vector2),center=(0,0,0))