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

夙愿已清 提交于 2019-12-24 02:23:42

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/3340402/how-to-find-out-whether-an-affine-transformed-rectangle-contains-a-certain-point

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!