gpt4 book ai didi

java - 有没有办法将 Oval 对象与 intersects() 函数一起使用?

转载 作者:行者123 更新时间:2023-11-30 05:38:41 25 4
gpt4 key购买 nike

首先,我知道已经回答了非常类似的问题,但我还没有看到特别提出这个问题。

我有一个椭圆形和一个矩形,我想检测它们是否相交。我知道你可以用两个矩形来做到这一点,如下所示:

if (new Rectangle(x1, y1, w1, h1).intersects(new Rectangle(x2, y2, w2, h2))) {

//code here for when collision occurs.

}

是否可以用这样的椭圆形来做到这一点?

if (new Oval(x1, y1, w1, h1).intersects(new Rectangle(x2, y2, w2, h2))) {

//code here for when collision occurs.

}

提前致谢!

最佳答案

当我搜索 Oval 类时,我没有看到 Oval 类,因此我将使用 Ellipse 作为示例。如果您查看文档 here您将看到 Shape 类的文档。

此类由 RectangleEllipse 扩展,并且还包含一个 intersect(Shape, Shape) 方法,因此您将能够对这两个对象使用 intersect。

如果您的 Oval 类和 Rectangle 类都从您的场景中的 intersect(Shape, Shape) 继承自,它也适用于您的场景。

关于java - 有没有办法将 Oval 对象与 intersects() 函数一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56138290/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com