作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的数组中有一些带有坐标的对象。
var players = [
{x:100, y:100, pid:1},
{x:-100, y:200, pid:2},
{x:600, y:1200, pid:3}
]
var mousepos = {x:50, y:0}
var 已选择 = null
我想计算这些对象中哪个与 mousepos 的坐标最接近以选择它 pidselected = 最接近 mousepos 的坐标的 pid
是否有人可以给我简单的代码?
最佳答案
老兄,这就是答案。使用距离公式计算点之间的距离。距离最小的点是最近的点。
公式:- Sqrt((x2-x1)2 + (y2-y 1)2)
关于javascript - 计算对象中的哪个坐标最接近所选坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58238555/
我正在尝试用 Swift 编写这段 JavaScript 代码:k_combinations 到目前为止,我在 Swift 中有这个: import Foundation import Cocoa e
我是一名优秀的程序员,十分优秀!