1

我试图围绕一个点旋转一个矩形并动态设置它的长度。这是我到目前为止所拥有的:

Rectangle2D myRect = new Rectangle2D.Double(point.x - GameValues.ROPE_WIDTH, point.y, point.x + GameValues.ROPE_WIDTH, point.y + ropeLength);
    AffineTransform at = AffineTransform.getRotateInstance(
            Math.toRadians(rotation - 180), point.x, point.y);
    rope = at.createTransformedShape(myRect);

当我绘制形状时,它的行为不像预期的那样,矩形宽度随着我移动点而改变。我该如何正确地做到这一点?

4

1 回答 1

1

您误解了 Rectangle2D 的定义方式。对于 Rectangle2D,我建议设置一个与点(直接)无关的长度,然后使用仿射变换对其进行缩放。

问题是 Rectangle2D 没有像您想象的那样在 (x1, y1) 和 (x2, y2) 之间定义;它是 (x1, y1) 和 (Δx, Δy) 或偏移量。

更改您的代码以使用它:

Rectangle2D myRect = new Rectangle2D.Double(point.x, point.y, GameValues.ROPE_WIDTH, ropeLength);

或者它的一些排列,你应该清楚。

于 2015-04-18T17:33:10.347 回答