Rotation of Two Attached Images

I am already able to rotate an image relative to mouse position, but now I need to draw an image on that one that will stay in a fixed position on it and rotate with it.

Take this example:

The circle is the original image rotating. The rectangle is what is being rotated. So I need this…

http://dl.dropbox.com/u/34206572/Misc/ex_a.png

To become this…

http://dl.dropbox.com/u/34206572/Misc/ex_b.png

I would REALLY prefer NOT using Image.getGraphics because the attached image will probably overlay past the original’s boundaries in a lot of cases.

Can anyone explain how to accomplish this?

you are not terribly clear about how things are done in your code,
but in this case if you draw ONTO the image you are rotating
Image.getGraphics and whatnot, it would work

of course not sure if thats ok

you can also make a big transparent image with the black rectangle on it at the starting point, the image being the same size as the circle

other options require more math of course =D

What sort of clarification do you need?

Image.getGraphics will not show anything drawn outside of the image boundaries. As I stated in the OP, often times the overlaying image will overlap those boundaries, thus making it not a good solution.

I did, for whatever reason, put that as BufferedImage.getSubImage which isn’t really relevant nor what I mean… oops :stuck_out_tongue:

I’ll take the math please!

This actually isn’t a bad idea… I might play around with that.

Larger transparent image on which both are drawn, then IT will be rotated.

Let me see. Maybe what he wants is the rect always be drawn to a fixed position relative to the circle. So the rect will follow the circle (the circle always sees the rect in same way). In that way, you need to share same coordinate of rotation’s origin. Correct me.


AffineTransform old = g2d.getTransform(); //get the old transform

g2d.setTransform(new AffineTransform(old)); //create new transform that is copy of old

g2d.rotate(theta,circleCenterX,circleCenterY); //rotate about the circle's center

g2d.fillOval(circleX,circleY,circleWidth,circleHeight);
g2d.fillRect(rectX,rectY,rectWidth,rectHeight);

g2d.setTransform(old); //reset back to old