title: Position an image inside a rotating image
body: <p>I have two images, one for a zombie and one for a blade that the zombie will have a 10 % chance to spawn with. I want to position the blade so that it will overlap the zombies right hand. I would be able to do this if the zombie was the same height as width but because it is 62x55 it makes everything much more complex. The code that positions the blade and the zombies right now looks like this:</p>
  
  <pre><code>at = new AffineTransform();
  angle = Math.atan2(player.getY() - zombie.getY(), player.getX() - zombie.getX()) + (Math.PI / 2);
  at.setToTranslation(zombie.getX(), zombie.getY());
  at.rotate(angle, zombie.getWidth() / 2, zombie.getHeight() / 2);
  g2d.drawImage(zombie.getBrImage(),at,this);
  ImageIcon ii = new ImageIcon("Blade.png");
  Image image = ii.getImage();
  int x = (int) Math.round(zombie.getX() + 47 * Math.sqrt(2) * Math.cos(angle - Math.PI / 4));
  int y = (int) Math.round(zombie.getY() + 47 * Math.sqrt(2) * Math.sin(angle - Math.PI / 4));
  at.setToTranslation(x, y);
  at.rotate(angle, zombie.getWidth() / 2, zombie.getHeight() / 2);
  g2d.drawImage(image, at, this);
  </code></pre>
  
  <p>This will produce the following result:</p>
  
  <p><img src="https://i.imgur.com/UxVtHKK.png" alt="currentbladepos"></p>
  
  <p>As you can see the blade is positioned at a higher y (lower y if you count 0 as the top of the screen) than is should, because the zombie will rotate so that it always faces the player I can't just change the number 47 for y because then the blade wont rotate properly.</p>
  
  <p>So how would I make the blade always be positioned properly so that it would always produce the following result no matter what angle the zombie is facing?</p>
  
  <p><img src="https://i.imgur.com/QSZEIP6.png" alt="bladepos">                             </p>