问题标签 [distance]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
7 回答
16153 浏览

language-agnostic - 如何计算球体上点到线段的距离?

我在地球上有一条线段(大圆部分)。线段由其端点的坐标定义。显然,两点定义了两条线段,所以假设我对较短的线段感兴趣。

我得到了第三个点,我正在寻找线和点之间的(最短)距离。

所有坐标均以经度\纬度 (WGS 84) 给出。

如何计算距离?

任何合理的编程语言的解决方案都可以。

0 投票
2 回答
373 浏览

algorithm - Naming this algorithm: Comparing and interpolating points?

my question might be a little strange. I've "developed" an algorithm and don't know if there's a similar algorithm already out there.

The situation: I've got a track defined by track points (2D). The track points represent turns for instance. Between the track points there are only straight lines. Now I'm given a set of coordinates in this 2D space. I calculate the distance from the first track point to the new coordinates and the distance for the interval for the first two track points. If the distance to the measured coordinates is shorter than the distance from the first to the second track point, I'm assuming that this point lies in between this interval. I then do a linear interpolation on that. If it's bigger, I'll check with the next interval.

So it's basically taking interval distances and trying to fit them in there. I'm trying to track an object moving approximately along this track.

Does this sound familiar to somebody? Can somebody come up with a suggestion for a similiar existing algorithm?

EDIT: From what I've stated so far, I want to clarify that a position is not multiply associated to track points. Consider the fine ASCII drawing Jonathan made:

The X position is found to be within Segment 1 and 2 (S12). Now the next position is Y, which is not to be considered close enough to be on S12. I'll move on to S23, and check if it's in.

If it's in, I won't be checking S12 for any other value, because I found one in the next segment already. The algorithm "doesn't look back".

But if it doesn't find the right segment from there on, because it happenend to be to far away from the first segment, but still further away from any other segment anyhow, I will drop the value and the next position will be looked for back in S12, again.

The loop still remains a problem. Consider I get Y for S23 and then skip two or three positions (as they are too far off), I might be losing track. I could determine one position in S34 where it would be already in S56.

Maybe I can come up with some average speed to vage tell in what segment it should be.

It seems the bigger the segments are, the bigger the chance to make a right decision.

0 投票
6 回答
4393 浏览

data-structures - 哪种数据结构适合查询“距点 p 距离 d 内的所有点”

我有一个 3D 点云,我想有效地查询距任意点 p 距离 d 内的所有点(这不一定是存储的点云的一部分)

查询看起来像

什么加速结构适合这个?范围树似乎只适用于查询矩形体积,而不是球体体积(当然我可以查询球体的边界框,然后整理出所有距离大于 d 的顶点 - 但也许有更好的方法这个??)

谢谢!

根据 Novelocrats 的建议,我尝试定义结构所需的功能:

通常,在 n 次查询之后,这些点会发生位移,并且会进行一些(不是很多!)插入和删除。与所有点的边界框相比,偏移向量非常小

0 投票
2 回答
5109 浏览

php - K-means 聚类:怎么了?(PHP)

我一直在寻找一种方法来计算足球经理游戏中的动态市场价值。我在这里问了这个问题,并从 Alceu Costa 那里得到了很好的回答。

我试图编写这个算法(90 个元素,5 个集群),但它不能正常工作:

  1. 在第一次迭代中,大部分元素会更改其集群。
  2. 从第二次迭代开始,所有元素都改变了它们的集群。
  3. 由于该算法通常在收敛之前有效(没有元素更改其集群),因此在我的情况下它不会完成。
  4. 所以我手动将结束设置为第 15 次迭代。你可以看到它无限运行。

你可以在这里看到我的算法的输出。它出什么问题了?你能告诉我为什么它不能正常工作吗?

我希望你能帮助我。非常感谢您!

这是代码:

0 投票
3 回答
2054 浏览

database - 地图:计算两点之间的距离是否会影响高度?

在计算 2 点之间的距离时,Postgres 的 Spatial 插件或任何 Spatial 包是否会考虑高度?

我知道空间包因素会影响地球的近似曲率,但如果一个位置位于山顶,而另一个位置靠近大海 - 如果差异,这两个点之间的计算差异似乎会有很大差异海拔高度没有考虑在内。

还要记住,如果我有 2 个点位于相同的海洋高度,但 2 个点之间存在一座山 - 距离包应该考虑到这一点。

0 投票
1 回答
4230 浏览

google-maps - Google Maps API - 2点之间的“道路”距离

我有一个网站,根据存储在数据库中的纬度和经度坐标,为每个项目显示“附近位置”。

问题是这个计算的距离是航线距离,与实际行驶距离相差很大。

谷歌地图现在只有一个用于行车路线的 JavaScript API,我需要它作为一个网络服务 API 来直接从服务器进行调用。

有没有可能做到这一点?

0 投票
4 回答
2029 浏览

regex - 公制距离的正则表达式

我想要一个RegEx匹配公制中的距离值。此正则表达式应匹配12m, 100cm,1km忽略空格

0 投票
2 回答
406 浏览

mysql - 确定 n 维中点之间的距离

我正在构建一个 mySQL 表,列出 n 维中的点,每个维度都被索引。给定n维系统中的任何点,我希望能够按照它们与所选点的距离顺序输出所有其他点。

一个简单的解决方案是使用勾股定理计算到每个点的距离... sqrt(x^2+y^2)=z。我一直在寻找更有效的方法。只需要一个大概的顺序,所以我很开放。

谢谢。

-diddle

0 投票
2 回答
1547 浏览

position - 如何找到给定纬度/经度以东/西 x 公里的纬度/经度?

我有两个给定的纬度和经度点。例如,假设我在坐标 (lat1, lon1) 和 (lat2, lon2) 处有两个位置(point_1 和 point_2)。我想计算第三个点,它与 point_2 的纬度相同,但在 point_2 以东或以西 x 公里处。所以第三个点将与 point_2 具有相同的纬度,但经度不同,具体取决于距离 x(以公里为单位),换句话说,point_3 将是 (lat2, lon?)。我用 IDL 写这个,但任何其他语言或公式都会受到欢迎。

谢谢

0 投票
1 回答
5110 浏览

sql-server-2005 - 使用纬度和经度的两个位置之间的距离与谷歌所说的相差甚远

我花了几天时间试图解决这个问题,但似乎无法确定问题所在。我有一个 SQL 2005 数据库,将纬度和经度存储为 Decimal(18,8),所有这些都是通过查询 Google 获得的。

对于这两个地点:从:10715 Downsville Pike Ste 100 MD 21740 到:444 East College Ave Ste 120 State College PA, 16801

考虑到距离将是“乌鸦飞”,我的结果还有很长的路要走。在此示例中,我的结果显示为 21.32 英里,但 Google 地图显示为 144 英里。

我认为最令人沮丧的是我发现了这个网站:http: //jan.ucc.nau.edu/~cvm/latlongdist.html并得出了与我几乎完全相同的结果。

这是我的功能和查询:

函数: 计算距离

纬度加距离

经度加距离

询问: