计算区域内所有点之间的距离 [英] Calculating distance of all the points in a region with each other

查看:38
本文介绍了计算区域内所有点之间的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大约有 144 个点的区域.我想要实现的是测量一个点与所有其他点的距离并将其存储在一个数组中.我想对所有的点都这样做.如果可能,我想以不重复的方式存储这些数据.而且我应该能够进行类似的查询 - 所有点之间的所有距离而不重复,点 no56 的所有距离的总和等.

I have a region with about 144 points. What i want to achieve is to measure the distance of a point with all others and store it in an array. I want to do this for all the points. If possible i would like to store this data in such a manner that there in no repetition. And i should be able to make queries like- All the distances between all the points without repetition, sum of all the distances for point no56 etc.

我有一个 3*144 的数组,其中有两列存储点的坐标.

I have a 3*144 array with two columns storing the coordinates of the points.

推荐答案

一个可能的解决方案(不过我不是很清楚你所说的不重复是什么意思):

A possible solution (I am not really clear with what you mean by no repetition, though):

 X are your points with coordinates x = X(:,1), y = X(:,2)


 dist = sqrt(bsxfun(@minus,X(:,1),X(:,1)').^2 + bsxfun(@minus,X(:,2),X(:,2)').^2)

所以

dist(i,j) is the euclidean distance between i and j

当然矩阵是对称的.您可以轻松降低所涉及的复杂性.

of course the matrix is symmetric. You can easily reduce the complexity involved.

这篇关于计算区域内所有点之间的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆