title: Python - Rotation of a meshgrid
body: <p>I would like to work in polar coordinates with a meshgrid.
  First I have to determine theta angle with an origin situated in 
  the middle of the meshgrid, it s not a problem, I have splitted the meshgrid in 4 parts in 
  order to determine the angle as you can see below.</p>
  
  <p>And now I would like to apply a rotation of the landmark of an angle which be chosen , so I try to change the "landmark" with "XAprim" and "YAprim" but working with the 4 parts is not easy..I think it s not the easiest way...</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  
  Lx=1345.
  Ly=1428.
  x0 = Lx/2.
  y0 = Ly/2.
  
  YA, XA = np.mgrid[0:Ly, 0:Lx]
  Theta1 = np.arctan((YA-y0)/(XA-x0))
  Theta2 = np.pi/2*np.ones((YAp.shape[0], YA.shape[1]))
  Theta3 = 3*np.pi/2*np.ones((YA.shape[0], YA.shape[1]))
  
  mask = np.fromfunction(lambda i, j: (i &gt;= y0) * (j &gt; (x0)), (XA.shape[0], XA.shape[1]), dtype=int)
  test = np.invert(mask)
  V1_test1 = np.ma.array(-Theta1, mask=test)
  mask2 = np.fromfunction(lambda i, j: (i &gt;= y0) * (j &lt; (x0)), (XA.shape[0], XA.shape[1]), dtype=int)
  test2 = np.invert(mask2)
  V1_test2 = np.ma.array(-Theta1 - np.pi, mask=test2) #Entaille
  mask3 = np.fromfunction(lambda i, j: (i &lt; y0) * (j &gt; (x0)), (XA.shape[0], XA.shape[1]), dtype=int)
  test3 = np.invert(mask3)
  V1_test3 = np.ma.array(-Theta1, mask=test3)
  mask4 = np.fromfunction(lambda i, j: (i &lt; y0) * (j &lt;(x0)), (XA.shape[0], XA.shape[1]), dtype=int)
  test4 = np.invert(mask4)
  V1_test4 = np.ma.array((-Theta1 + np.pi), mask=test4) #Entaille
  mask5 = np.fromfunction(lambda i, j: (i &gt; y0) * (j==x0), (XA.shape[0], XA.shape[1]), dtype=int)
  test5 = np.invert(mask5)
  Theta2 = np.pi/2*np.ones((YA.shape[0], YA.shape[1]))
  V1_test5 = np.ma.array(Theta2, mask=test5)
  mask6 = np.fromfunction(lambda i, j: (i &lt; y0) * (j==x0), (XA.shape[0], XA.shape[1]), dtype=int)
  test6 = np.invert(mask6)
  Theta3 = -np.pi/2*np.ones((YA.shape[0], YA.shape[1]))
  V1_test6 = np.ma.array(Theta3, mask=test6)
  
  a = np.ma.filled(V1_test1, 0)
  b = np.ma.filled(V1_test2, 0)
  c = np.ma.filled(V1_test3, 0)
  d = np.ma.filled(V1_test4, 0)
  e = np.ma.filled(V1_test5, 0)
  f = np.ma.filled(V1_test6, 0)
  theta = (a + b + c + d + e + f)
  
  plt.imshow(theta,aspect='auto',cmap=plt.cm.hot)
  plt.colorbar()
  plt.show()
  </code></pre>
  
  <p>So I got this meshgrid which is expected :
  <img src="https://i.stack.imgur.com/dNJ8W.png" alt="enter image description here"></p>
  
  <p>And now, I would like to apply a rotation since the origin of the landmark
  As example with a 23 degrees angle, I calculate the new coordinates to do the change, but doing the same as over it because of the 4 parts of the angle...So I would like to know if there are not a more efficient way to deal this problem?</p>
  
  <pre><code>ang_rot = 23*np.pi/180.
  XAprim = XA*np.cos(ang_rot)+YA*np.sin(ang_rot)
  YAprim = -XA*np.sin(ang_rot)+YA*np.cos(ang_rot)
  Theta1 = np.arctan((YAprim-y0)/(XAprim-x0))
  
  plt.imshow(Theta1,aspect='auto',cmap=plt.cm.hot)
  plt.colorbar()
  plt.show()
  </code></pre>