How can i estiamte the local distance between two boundaries at each point ??

I attched image and .mat file of boundaries. We want to measure the distnace between red and green boundary at each point which is shown in image_1. We are calulated distrance using pdist2() function, but it gives distance from first point on boundary_1 to all points of boundary_2 and so on. But It should calculate the distance between one points on boundary_1 (red colour boundary in image_1) and nearest point on another boundary(green colour boundary in image_1).

1 Commento

Thank you for your answer chunru. How can i draw the lines between boundary one and boundary 2 so i can identify which points are taken for min distance.

Accedi per commentare.

 Risposta accettata

load(websave("bw1.mat", "https://www.mathworks.com/matlabcentral/answers/uploaded_files/1153258/bw1.mat"))
load(websave("bw2.mat", "https://www.mathworks.com/matlabcentral/answers/uploaded_files/1153263/bw2.mat"))
d = pdist2(M, N);
plot(M(:,1), M(:, 2), 'r-', N(:,1), N(:,2), 'g');
set(gca, 'YDir', 'reverse');
axis equal
hold on
for i=1:10:size(d, 1) % change 10 to 1 for every points
[~, imin] = min(d(i, :)); % closest distant to boundary 2
plot([M(i,1) N(imin,1)], [M(i,2) N(imin,2)], 'b-')
end
% whos

8 Commenti

Thank you for your answer. How can i draw the lines between boundary one and boundary 2 so i can identify which points are taken for min distance.
Might be fun/interesting to show a histogram of distances, and area of the annular region using polyarea.
I got your point churnu. In image_m (which i attched), with help of this code, I can not measure the distance d which is shown in image_m. Can you provide your some solution so i can calculate the distance d for all extruded part (which is the extruded part of green boundary in image_m).
In that case, you need to swap the reg and green lines.
load(websave("bw1.mat", "https://www.mathworks.com/matlabcentral/answers/uploaded_files/1153258/bw1.mat"))
load(websave("bw2.mat", "https://www.mathworks.com/matlabcentral/answers/uploaded_files/1153263/bw2.mat"))
d = pdist2(M, N);
plot(M(:,1), M(:, 2), 'r-', N(:,1), N(:,2), 'g');
set(gca, 'YDir', 'reverse');
axis equal
hold on
for i=1:10:size(d, 2) % change 10 to 1 for every points
[~, imin] = min(d(:, i)); % closest distant to boundary 2
plot([M(imin,1) N(i,1)], [M(imin,2) N(i,2)], 'b-')
end
axis([200 400 400 500]) % zoom in
I agreed with your point churnu, but there are number of lines. You can see in image(attached in this comment), i need only distance d which is shown in image. This distance can not reconize. Can you give some suggestion on that and how to calculate the angle alpha which is shown in angle.png imag.
Then you have to specify which point to be examined. And then just show the distance for the specified point.
But in my case there are no of extruded parts and i want to automated them to calculate the length of the extruded part. Can you eloborate on this.

Accedi per commentare.

Più risposte (0)

Prodotti

Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by