带有随机旋转点的旋转矩阵

问题描述

我需要一个旋转矩阵,它围绕一个 abritrary 点(在下面提到的代码中称为中心)旋转一条线。我写了一个 scrict 但某处是一个错误。 你能帮助我吗? 我将中心坐标(替换原点的随机中心)放在旋转矩阵的第 4 列中。绘制结果后,线绕轴旋转,穿过原点,再往前走。

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

f = lambda m,n: n+2*m
A = np.fromfunction(f,(10,3),dtype=int)

def get_rotation_matrix(center,x_rot: float,y_rot: float,z_rot: float,reverse=False):
    import numpy as np
    import math

    cx,sx = math.cos(x_rot),math.sin(x_rot)
    cy,sy = math.cos(y_rot),math.sin(y_rot)
    cz,sz = math.cos(z_rot),math.sin(z_rot)
    
    Rx = np.array(
        [[1,0],[0,cx,-sx,sx,1]]
        )
    Ry = np.array(
        [[cy,-sy,1,[sy,cy,1]]
        )
    Rz = np.array(
        [[cz,-sz,[sz,cz,1]]
        )
    T = np.array(
        [[1,center[0]],center[1]],center[2]],1]]
        )
    ret = T @ Rx @ Ry @ Rz
    print(ret)
    At = np.c_[A,np.ones(len(A))]
    k = np.dot(At,ret)
    print(k.T)
    
    return k #np.linalg.inv(ret) if reverse else ret 


theta_x = 5
theta_y = 0
theta_z = 0

k = get_rotation_matrix([0,10],theta_x/57.4,theta_y/57.4,theta_z/57.4)

fig = plt.figure(figsize=(12,12))
ax = fig.add_subplot(111,projection='3d')
ax.plot(k[:,k[:,1],2])
ax.plot(A[:,A[:,2])
plt.show()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...