Just do some vecor math. Given the images and the touch position:
const coords = [[92, 81], [82, 47], [81, 03]];
const touchX = 57, touchY = 84;
Just go over them and calculate the distance vecors length:
let closest = [null, null];
let distance = Infinity;
for(const [x, y] of coords){
let d = Math.sqrt((touchX - x) ** 2 + (touchY - y) ** 2);
if(d < distance){
closest = [x, y];
distance = d;
}
}
Vectors
Calculating the length
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…