开发者

How to find out whether an affine transformed rectangle contains a certain point, in Java?

开发者 https://www.devze.com 2023-01-09 04:24 出处:网络
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, c

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 n开发者_JS百科ot, how can I approach this?

Thanks.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消