I am trying to rotate a roll ( or cylinder) using Euler matrix. For that purpose I use the following function.
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
the function works well when Euler rotation matrix is Euler = np.array([[1,0,0],[0,1,0],[0,0,1]])
and the inputs for function are x, y, z = roll(1, -2, 2, np.array([[1,0,0],[0,1,0],[0,0,1]]) )
. Using ax.plot_surface(x,y,z)
I got the following figure.
But when I try to rotate the object by Euler matrix Euler = np.array([[1,0,0],[0,1/np.sqrt(2),-1/np.sqrt(2)],[0,1/np.sqrt(2),1/np.sqrt(2)]])
i got the unexpected result.
Here the rotation is 45
degree which is correct but the shape of object is not proper.