public class RectFun {
public static void main(
String[] args) {
RectangularShape rectangularShape
rectangularShape = new Rectangle2D.Double(10,20,30,50)
Rectangle2D rectangle = rotateRect(rectangularShape,30)
println(rectangle)
}
static Rectangle2D rotateRect (RectangularShape rect, int angle, Point2D pivot = null )
{
if (pivot == null)
{
pivot = new Point2D.Double(rect.x + (int) Math.round(rect.width / 2d), rect.y + (int) Math.round(rect.height / 2d))
}
double rad = angle * Math.PI / 180;
double diffX = rect.x - pivot.x
double diffY = rect.y - pivot.y
int x = (int) Math.round(rect.x - diffX + (diffX * Math.cos(rad)) + (diffY * Math.sin(rad)))
int y = (int) Math.round(rect.y - diffY + (diffY * Math.cos(rad)) - (diffX * Math.sin(rad)))
return new Rectangle2D.Double(x, y, rect.width, rect.height)
}
}