Locate two neighboring nodes in space so as to divide the matrix into two

3 ビュー (過去 30 日間)
Alberto Acri
Alberto Acri 2024 年 2 月 24 日
コメント済み: Matt J 2024 年 2 月 24 日
I have the coordinates of nodes arranged in space in the shape of 8.
Is there a way to locate the nearest points as marked in the two figures (circled in red)? note: the figures are an example
I need to locate the two nodes to "separate" the coordinates of the nodes in matrix A and matrix B.
plane_new = importdata("plane_new_2_30_jj2.mat");
% OR
plane_new = importdata("plane_new_3_31_jj2.mat");
figure
plot3(plane_new(:,1),plane_new(:,2),plane_new(:,3),'k.','Markersize',20);
axis equal
grid off
  3 件のコメント
Matt J
Matt J 2024 年 2 月 24 日
編集済み: Matt J 2024 年 2 月 24 日
I'm also not sure why you are giving us example data in 3D form. This is planar data, so you could be mapping this to 2D (as you did here) and working entirely in the 2D domain.
Alberto Acri
Alberto Acri 2024 年 2 月 24 日
Hi Matt.
It's not clear how you choose the pair of separating points in the second case. WHy couldn't they be as marked in yellow below? Why couldn't they be any pair of points on the parallel edges of the neck?
Yes, it can also be as you say. I specified in the question that the figures are 'examples'.
I'm also not sure why you are giving us example data in 3D form. This is planar data, so you could be mapping this to 2D (as you did here) and working entirely in the 2D domain.
I hadn't thought about it that I could work in 2D. I will let you know if I reach a solution. Thanks for the advice!

サインインしてコメントする。

採用された回答

Matt J
Matt J 2024 年 2 月 24 日
編集済み: Matt J 2024 年 2 月 24 日
load xydata xy %Original 3D data mapped to 2D
xy=xy(tspsearch(xy,5),:); %tspsearch is on the file exchange
P=polyshape(xy,'Simplify',0);
pc=regions(rmslivers(subtract( convhull(P) , P),1/100));
[~,is]=maxk(area(pc),2); pc=pc(is);
neck=getNearest(pc(1),pc(2)); %The two points
plot(P); axis equal
hold on
scatter(neck(:,1), neck(:,2),'or','filled')
hold off
function V=getNearest(p1,p2)
ID=nearestvertex(p1,p2.Vertices);
Dist=vecnorm(p1.Vertices(ID,:)-p2.Vertices,2,2);
[~,j]=min(Dist);
V=[p1.Vertices(ID(j),:);p2.Vertices(j,:)];
end
  2 件のコメント
Walter Roberson
Walter Roberson 2024 年 2 月 24 日
regionprops() MinFeretProperties is another potential way to find the distances.
Matt J
Matt J 2024 年 2 月 24 日
If you could form an image out of the xy data, then yes.

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by