I have a problem calculating the corners of a rotated rectangle.
For the calculation I use a rotation matrix but there is somewhere a little mistake in my code.
As you can see the corners have a wrong positions but were rotated correctly.
Code:
[spoiler]
corners[0] = translatePoint(x, y);
corners[1] = translatePoint(x + width, y);
corners[2] = translatePoint(x + width, y + height);
corners[3] = translatePoint(x, y + height);
private Point translatePoint(double x, double y) {
double xNew = (x * Math.cos(getAngleInRadians()) - y * Math.sin(getAngleInRadians()));
double yNew = (x * Math.sin(getAngleInRadians()) + y * Math.cos(getAngleInRadians()));
return new Point(xNew, yNew);
}
[/spoiler]
(x,y) is the left top corner of the unrotated rectangle.
Thank you for your help!