0

I have a line. I know the endpoint of that line and an angle which tells by how many degrees it's tilted. I want to draw an image in such a way so that the bottom center point of the image would touch the endpoint of the line like so:

enter image description here

Sadly, I get the wanted result only if line isn't rotated, like above. If it's rotated by, for example, 90 degrees I get this:

enter image description here

This is the code that draws the image (line is already drawn by that point).

public void drawCreature(Graphics2D g) {
    int centered = creature.getX() - creature.getImage().getWidth()/2;
    BufferedImage image = creature.getImage();
    BufferedImage rotatedImage = new BufferedImage(image.getWidth(), image.getHeight(), 
                                                   BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = (Graphics2D)rotatedImage.getGraphics();
    g2d.rotate(Math.toRadians(creature.getAngle()), rotatedImage.getWidth()/2,
               rotatedImage.getHeight()/2);
    g2d.drawImage(creature.getImage(), 0, 0, null);
    g.drawImage(rotatedImage, centered, creature.getY(), null);
  }

Any help would be appreciated.

user1242967
  • 1,220
  • 3
  • 18
  • 30
  • You `image` is the circle with stick? You're saying that the images breaks after you rotate? – user1803551 Apr 22 '14 at 22:04
  • My image is just a circle. The "stick" is the line. They are separate beings. I want to write a function so that I could draw that circle(creature) in such way that it always would touch that line in a way that it's touching in the first picture. As you see, in the second picture creature is too low, it should be higher by the half of its height. If it's still hard to understand, I am making turtle graphics clone and that circle is my turtle. You can find some pictures of that program online to get a better idea what I am after. Perhaps I should've provided them myself. – user1242967 Apr 22 '14 at 22:18
  • 1
    Can you give an [MCVE](http://stackoverflow.com/help/mcve)? I want to see how you draw and to where. – user1803551 Apr 22 '14 at 22:50
  • One way to get image(s) for an MCVE is to hot-link to the images seen in [this answer](http://stackoverflow.com/a/19209651/418556). – Andrew Thompson Apr 23 '14 at 00:25

0 Answers0