我试图用欧拉矩阵旋转一个滚动体(或圆柱体)。为此,我使用以下函数。在
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旋转矩阵为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)
我得到了下面的图。
但是当我试图用欧拉矩阵旋转物体时,我得到了意想不到的结果。在
这里的旋转是45
度,这是正确的,但对象的形状不合适。在
你就快到了。几件事:
实际上,您使用的是cylindrical coordinates而不是球形的。我没有检查numpy是否有一个
cyl2cat
,但这也不是很难自己写的:对于旋转,我不太明白你为什么要分两步走。可以使用numpy的^{} 来旋转网格:
^{pr2}$并重塑旋转坐标:
组合起来:
现在
roll
执行您想要的操作:等等:
注意,轴的纵横比是不一样的,这就是为什么圆柱体出现椭圆曲率的原因。在
Axes3D
中获得相等的轴不是简单的,但是可以通过绘制一个立方体边界框(几乎是从this复制/粘贴)来实现的只需在
ax.plot_surface(...
之后添加此元素,圆柱体将显示为圆形曲率。在相关问题 更多 >
编程相关推荐