Ok, I'm trying to rotate the rectangle that is on top of the image. I have a Scrollable class that displays an image. I can draw Rectangles on top of the image. My problem is to rotate the rectangles while rotating the image. The rectangle is lost and placed in the wrong location.
I already tried to sue Graphics2D, AffineTransform, createTransformedShape (), but no luck.
Now I am trying to rotate the Rectangle manually. I am trying to get a Rectangle Point (x, y) using the following formula:
double rectX = (Math.cos(Math.toRadians(90)) * (x - anchorX) - Math.sin(Math.toRadians(90)) * (y - anchorY)) + anchorY;
double rectY = (Math.sin(Math.toRadians(90)) * (x - anchorX) - Math.cos(Math.toRadians(90)) * (y - anchorY)) + anchorY;
How to find anchorX and anchorY values using Java? I tried immersing the image height by 2, but does not work for all rotation angles. Should I get the width and height of a JPanel or something else? Is there a formula that Java uses to find anchor points?
source
share