我有
X = (Yt.*sin(W))-(Xt.*cos(W));
Y = (Yt.*cos(W))+(Xt.*sin(W)); % which give the coordinates X and Y.
X_inv = R.*sin(B_involute);
Y_inv = R.*cos(B_involute); % which give the coordinates X_inv and Y_inv.
我需要找到的最近的两个点X
,Y
并且X_inv
,Y_inv
。
从现在开始非常感谢。
您可以使用以下方式有效地计算成对距离 pdist2
D = pdist2( [X(:) Y(:)], [X_inv(:) Y_inv(:)] );
一旦有了成对的距离,就很容易找到最小距离
[md mi] = min(D(:));
将线性索引转换为对索引
[idx, inv_idx] = ind2sub( size(D), mi );
结果
fprintf(1, 'Closest points are [%d]: (%f,%f) -> [%d]: (%f,%f)\n',...
idx, X(idx), Y(idx), inv_idx, X_inv(inv_idx), Y_inv(inv_idx) );
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句