我的矩形有4个侧面,我应该根据触摸哪一侧执行某些操作,该如何检查?

发布于 2025-01-26 03:37:27 字数 262 浏览 1 评论 0原文

与:

getrectangle().intersects(circle.getBounds2D())

我可以看到我的矩形是否被我的圆圈触摸。这也有效。

但是现在我必须设置,如果它触及矩形的左侧或右侧(无论何处),我必须打印一个system.out.println。

而且,如果它接触矩形的矩形的上部或下侧,我必须输出另一个system.out.println。现在我该怎么做?

还如何检查它击中的哪一侧?

With:

getrectangle().intersects(circle.getBounds2D())

I can see if my rectangle was touched by my circle. That works also.

But now I have to set, that if it touches the left or right side (no matter where there) of the rectangle, I have to print a System.out.println.

And if it touches the upper or lower side of the rectangle (no matter where there) of the rectangle, I have to output another System.out.println. Now how do I do this?

ALso how do I check which side it hit?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉殇 2025-02-02 03:37:27

这是您可以做到这一点的方式,

以圆方向的角度(弧度),然后使用Math.asin和Math.acos将其转换为X和Y值。您需要将一个划分为y = ax + b; 类似于上面,弄清楚侧面正在使用角点和数学。

然后,您需要将矩形的边缘转换为线条(

现在您有两行,而您要做的就是解决方程式时的等式

Here's the way you can do this

Take the angle (in radians) of the circle's direction, and convert it to x and y values using Math.asin and Math.acos. You need to divide one by the other to get into y=ax + b; Then you need to convert your rectangle's edges into lines (similar to above, figure out the angle the sides are on using the corner points and Math.sin and Math.cos)

... Sounds easy, right???

Now you have two lines and all you have to do is solve the equation for when they are equal

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文