所以我们有一个3D点的参考集(让我们称它为R),还有许多其他的3D点集(让我们调用这组数据点集P,以及Pi中的每个数据集)。
任务是返回Pi,以最小化欧氏距离,一些Pi和R中的数据点,我认为是这样的:
但这是相当疯狂的,因为它意味着从本质上看R中的每个点和P中的每个点之间的距离,这可能是数千或数百万。我当然可以做得更好。
我在Matlab里工作,但我不习惯。
有什么更好的算法可以使用?是否有一个完美的数据结构?(例如K-D树?)
发布于 2012-05-08 16:46:16
除非你有如此之多的点,这真的成为一个性能问题,与每一个点相比确实是最简单的解决方案,特别是因为这些操作可以在Matlab中被高度矢量化。
例如:
R = [1 2 3; 1 3 4];
P{1} = [2 3 5;1 1 2;2 1 3];
P{2} = [4 4 4];
nP = length(P);
sumMinDist = zeros(nP,1);
%# make R into n-by-1-by-3 already
Rperm = permute(R,[1 3 2]);
for iP = 1:nP
%# since we want to sum up the minima, we need to take the square root
allDist = sqrt( sum( bsxfun(@minus, Rperm, permute(P{iP},[3 1 2])).^2, 3));
%# sum the minima (you may want to consider
%# taking the mean instead!)
sumMinDist(iP) = sum(min(allDist,[],1));
end
%# now we can identify the closest set
[~,idxOfClosestSet] = min(sumMinDist);https://stackoverflow.com/questions/10502166
复制相似问题