java - 在java中旋转矩形对象

标签 java rotation

是否可以将 Rectangle 对象绕其轴旋转一定角度?它像 Rectangle rect = new Rectangle(x,y,w,h,r) 一样简单吗?

如果无法旋转对象,有什么方法可以得到类似的结果?

编辑:为清楚起见,这是我的困境,我有旋转的图像,但当它们与其他图像碰撞时,碰撞仅在 90 度和 180 度旋转时起作用,因为它们的碰撞框 Rectangle 对象不旋转。

最佳答案

Edit: for clarity here is my dilemma, I have images that rotate but when they colide with other images the collisions only work at 90 and 180 degree rotations because their hit box Rectangle objects don't rotate.

您可以使用 AffineTransform 方法旋转一个 Shape 派生对象,例如 Rectangle2D,createTransformedShape(...) .

Rectangle2D myRect = new Rectangle2D.Double(100, 100, 200, 200);
AffineTransform at = AffineTransform.getRotateInstance(Math.PI / 4, 150, 150);
Shape rotatedRect = at.createTransformedShape(myRect);

注意:代码未经编译或测试。

关于java - 在java中旋转矩形对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18860700/

相关文章:

java - 如何处理可能出现的非终结符?

C# 从右角开始旋转 DrawString

iphone - UIImage iPhone 旋转 37.8 度

cocoa-touch - "refresh"设备旋转 View

java - Spring - 当结果小于页面大小时没有数据 -

Java小程序无法通过浏览器访问mysql

ios - 如何调整按钮的大小? swift

android - Activity 在旋转 Android 时重新启动

java - 无法从对象生成 avro 通用记录

java - 截断双数