title: how to apply a affine transformation to a single dot in PIL?
body: <p>In PIL I have rotated a rectangle by an angle and pasted it back to the background image.
  I'd like to know what will be the new coordinates of a specific corner.</p>
  <p>function(old_coord) =&gt; new coordinates</p>
  <p>I have read in the documentation it mentioned the center of rotation by default is the center of the image.</p>
  <p>Here is my code:</p>
  <pre><code>import PIL
  from PIL import Image, ImageDraw
  import os
  
  background = Image.open('background.jpg')
  rectangle = Image.open(&quot;rectangle.png&quot;)
  my_angle = 30
  
  rectangle_rotate = Image.Image.rotate(rectangle, angle=my_angle, resample=Image.BICUBIC, expand=True)
  
  # box: 2-tuple giving the upper left corner
  px = int(background.size[0] / 2)
  py = int(background.size[1] / 2)
  background.paste(im=rectangle_rotate,
                       box=(px, py),
                       mask=rectangle_rotate)
  # The new position I'm getting is wrong, how come?????
  pos_xNew = px * math.cos(math.radians(my_angle)) + py * math.sin(math.radians(my_angle))
  pos_yNew = -px * math.sin(math.radians(my_angle)) + py * math.cos(math.radians(my_angle))
  print('pos_xNew:', pos_xNew)
  print('pos_yNew:', pos_yNew)
  draw_img_pts = ImageDraw.Draw(background)
  r = 10
  # Drawing a simple small circle circle for visualization
  draw_img_pts.ellipse((pos_xNew - r, pos_yNew - r, pos_xNew + r, pos_yNew + r), fill='red')
  
  background.save('example_with_roatation.png')
  </code></pre>
  <p>how can I find the new coordinates value? I keep getting <strong>wrong value</strong>.</p>
  <p>Background image (input):
  <a href="https://i.stack.imgur.com/NDazw.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NDazw.jpg" alt="background" /></a></p>
  <p>Rectangle image (input):</p>
  <p><a href="https://i.stack.imgur.com/BjwAj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BjwAj.png" alt="rectangle" /></a></p>
  <p>The Output I got with zero rotation as expected:</p>
  <p><a href="https://i.stack.imgur.com/HsvVh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HsvVh.png" alt="zero rotation" /></a></p>
  <p>Output I got after 30 degree rotation:</p>
  <p><a href="https://i.stack.imgur.com/Cqu0R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Cqu0R.png" alt="30 degree rotation" /></a></p>