加工圆半径内

Within a circles radius in processing

有没有办法检测坐标是否加工中的圆半径内?

例如,在我的程序中,如果玩家 2 的精灵与 "captures" 玩家 1 的精灵重叠,那么我希望游戏结束(所以如果玩家 1 的精灵在玩家 2 的碰撞框圈内)。 *注意:我的 player 1 sprite 相当小,定义其位置的坐标应该足以进行重叠检测

谢谢!

虽然我对processing不熟悉,但这是一个数学问题,可以用毕达哥拉斯来解决:

float cx; //center x of circle
float cy; //center y of circle
float cr; //radius of circle

float x; //tested x coordinate
float y; //tested y coordinate

(sqrt(pow(x-cx, 2) + pow(y-cy, 2)) < cr) // must evaluate to true for a hit-test

您可以只使用 dist() 函数。

获取点到圆心的距离。如果该距离小于圆的半径,则该点在圆内。

我建议您举出一些例子来了解为什么这是有道理的。

the reference 中提供了更多信息。