function d_z = distance(tip, samp, search_dis)
X = min(samp(:, 1)):search_dis:max(samp(:, 1));
Y = min(samp(:, 2)):search_dis:max(samp(:, 2));
num_cols = length(X);
num_rows = length(Y);
d_z = zeros(num_rows, num_cols)
for i = 1:num_rows
for j = 1: num_cols
x_r = [X(i)-search_dis/2, X(i)+search_dis/2];
y_r = [Y(j)-search_dis/2, Y(j)+search_dis/2];
samp_ind = samp(:, 1)>=x_r(1)&samp(:, 1)<=x_r(2)&samp(:, 2)>=y_r(1)&samp(:, 2)<=y_r(2);
tip_ind = tip(:, 1)>=x_r(1)&tip(:, 1)<=x_r(2)&tip(:, 2)>=y_r(1)&tip(:, 2)<=y_r(2);
[tip_z, I_tip] = min(tip(tip_ind, 3));
[samp_z, I_samp] = max(samp(samp_ind, 3));
d_z(i, j) = tip_z-samp_z;
[d, I] = min(nonzeros(d_z))
Could anyone find a way to find the index of such two points in the origional samp and in the origional tip?
The image of tip and sample is displayed in "samp_image.pdf". The purpose of the algorithm just to find the shortest vertical distance between the tip and the sample. Then return the index of the two points in the tip and sample that construct this shortest vertical distance.
Example of the input:
tip =[2, 3, 2; 1, 0, 2; 3, 2, 4];
samp = [2, 3, 1; 2, 3, 0.2; 0.2, 2, 3];
In tip and sample, each row just corresponds to the coordinate of a points in 3d space.
Then index of a point is just the index of the row, because each row corresponds to a point.
If I found the shortest vertical distance is between [2, 3, 2] and [2, 3, 1];
then I would like the algorithm to return the index of the point in the tip and the index of the point in the sample as [1,1].