gpt4 book ai didi

java - 触摸位置周围的半径

转载 作者:搜寻专家 更新时间:2023-11-01 08:43:42 25 4
gpt4 key购买 nike

我有一个位于 View 中的 X 和 Y 坐标的 ArrayList。现在我想检查用户是否触摸了 View ,一些存储的 X 和 Y 坐标是否在触摸点周围的某个半径(如 20 像素)内。我将如何实现?

最好的问候

最佳答案

使用毕达哥拉斯公式。

if(Math.sqrt(Math.pow(stored_x - touched_x, 2) + Math.pow(stored_y - touched_y, 2)) <= 20){
//do thing
}

关于java - 触摸位置周围的半径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30401940/

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