在Java中,如何找出仿射变换后的矩形是否包含某个点? [英] How to find out whether an affine transformed rectangle contains a certain point, in 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?
谢谢.
推荐答案
此示例显示contains()
在转换后的Shape
上可以正常工作. 示例使用Polygon
,但是Rectangle
还实现了Shape
.
This example shows that contains()
works as expected on a transformed Shape
. The example uses Polygon
, but Rectangle
also implements Shape
.
如果相反,图形上下文本身已转换,则必须创建一个反函数以捕获对转换所做的更改",如
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.
这篇关于在Java中,如何找出仿射变换后的矩形是否包含某个点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!