计算区域中所有点之间的距离 [英] Calculating distance of all the points in a region with each other
问题描述
我有一个大约144点的区域.我要实现的是测量一个点与所有其他点的距离并将其存储在数组中.我想为所有观点做到这一点.如果可能的话,我想以无重复的方式存储此数据.而且我应该能够进行类似的查询-所有点之间的所有距离都无需重复,第56点的所有距离之和等等.
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屋!