在Java中如何确定仿射变换的矩形是否包含某个点?
我正在尝试制作一个交互式 GUI,但每当单击+拖动该矩形时,我都需要移动某个对象。基本上我想知道一个经过仿射变换的矩形是否包含一个特定的点(x,y)。有办法做到这一点吗?我尝试过使用 contains()
方法,但它不适用于已进行仿射变换的矩形。我检查了 Java 教程,但用户交互式 GUI 不使用仿射变换。有人可以向我指出一个教程,该教程允许用户仿射变换某个形状以及仅在单击+拖动形状本身时移动该形状。如果没有,我该如何解决这个问题?
谢谢。
I'm trying to make an interactive GUI but I need to move a certain object whenever that rectangle is clicked + dragged. Basically I wanna know whether a rectangle, that has been affine transformed, contains a specific point (x, y). Is there a way to do this? I have tried using contains()
method but it doesn't work for a rectangle that has been affine transformed. I checked the Java tutorials but the user interactive GUIs don't use affine transformation. Can someone point me to a tutorial that allows the user to affine transform a certain shape as well as move the shape ONLY when the shape itself is clicked + dragged. If not, how can I approach this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此示例显示
contains()
在转换后的Shape
上按预期工作。 示例使用Polygon
,但是< code>Rectangle 还实现了Shape
。相反,如果图形上下文本身被转换,则必须创建一个逆函数“以捕获对转换所做的更改”,如 所示示例。
This example shows that
contains()
works as expected on a transformedShape
. The example usesPolygon
, butRectangle
also implementsShape
.If instead the graphics context itself is transformed, you'll have to create an inverse "to capture the changes you make to the transform", as shown this example.