【发布时间】:2018-05-24 01:57:25
【问题描述】:
我正在尝试使用欧拉矩阵旋转卷(或圆柱)。为此,我使用以下函数。
def roll( R, zi, zf, Euler):
# R is the radius of the cylinder
# t is the angle which is running from 0 to 2*pi
# zi is the lower z co-ordinate of cylinder
# zf is the upper z co-ordinate of cylinder
t = np.arange( 0, 2* np.pi + 0.1, 0.1)
z = np.array([zi, zf])
t, z = np.meshgrid(t, z)
p, q = t.shape
r = R* np.ones([p,q], float)
# polar co-ordinates to Cartesian co-ordinate
x, y, z = pol2cart(r,t,z)
# Euler rotation
rot0 = np.array([x[0,:], y[0,:], z[0,:]])
rot1 = np.array([x[1,:], y[1,:], z[1,:]])
# mult is the matrix multiplication
mat0 = mult( Euler, rot0)
mat1 = mult( Euler, rot1)
#
x[0,:] = mat0[0,:]
y[0,:] = mat0[1,:]
z[0,:] = mat0[2,:]
#
x[1,:] = mat1[0,:]
y[1,:] = mat1[1,:]
z[1,:] = mat1[2,:]
#
return x, y, z
当欧拉旋转矩阵为Euler = np.array([[1,0,0],[0,1,0],[0,0,1]]) 且函数的输入为x, y, z = roll(1, -2, 2, np.array([[1,0,0],[0,1,0],[0,0,1]]) ) 时,该函数运行良好。使用ax.plot_surface(x,y,z) 得到下图。
但是当我尝试通过欧拉矩阵Euler = np.array([[1,0,0],[0,1/np.sqrt(2),-1/np.sqrt(2)],[0,1/np.sqrt(2),1/np.sqrt(2)]]) 旋转对象时,我得到了意想不到的结果。
这里的旋转是45度,这是正确的,但对象的形状不正确。
【问题讨论】:
-
通常,np.dot 是矩阵乘法。你为什么用mult,你是从哪个模块得到的?
-
我不知道。所以,我编写了自己的矩阵乘法函数@B.M.
-
什么是 mult ???
-
我为矩阵乘法定义了 mult。如上所述,np.dot 可以用来代替 mult。
标签: python numpy matplotlib rotation euler-angles