title: Rotation of object using Euler Matrix in python
body: <p>I am trying to rotate a roll ( or cylinder) using Euler matrix. For that purpose I use the following function.</p>
  
  <pre><code>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
  </code></pre>
  
  <p>the function works well when Euler rotation matrix is <code>Euler = np.array([[1,0,0],[0,1,0],[0,0,1]])</code> and the inputs for function are <code>x, y, z = roll(1, -2, 2, np.array([[1,0,0],[0,1,0],[0,0,1]]) )</code>. Using <code>ax.plot_surface(x,y,z)</code> I got the  following figure.
  <a href="https://i.stack.imgur.com/EZYgv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EZYgv.png" alt="enter image description here"></a></p>
  
  <p>But when I try to rotate the object by Euler matrix <code>Euler = np.array([[1,0,0],[0,1/np.sqrt(2),-1/np.sqrt(2)],[0,1/np.sqrt(2),1/np.sqrt(2)]])</code> i got the unexpected result.</p>
  
  <p><a href="https://i.stack.imgur.com/46YWS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/46YWS.png" alt="enter image description here"></a></p>
  
  <p>Here the rotation is <code>45</code> degree which is correct but the shape of object is not proper.</p>