plot some nodes from an .txt file

조회 수: 6 (최근 30일)
Alberto Acri
Alberto Acri 2022년 12월 1일
댓글: Mathieu NOE 2024년 6월 12일
Hi! I would like to hope if there is an easy way to plot only the outermost nodes (the red nodes in the figure).
I am leaving the filename.txt file representing the nodes.

채택된 답변

Mathieu NOE
Mathieu NOE 2022년 12월 1일
hello Alberto
here you are ; use function boundary with shrink factor = 1
data = readmatrix('filename.txt');
x = data(:,1);
y = data(:,2);
% k = boundary(___,s) specifies shrink factor s using any of the previous syntaxes.
% s is a scalar between 0 and 1. Setting s to 0 gives the convex hull,
% and setting s to 1 gives a compact boundary that envelops the points.
% The default shrink factor is 0.5.
s = 1;
k = boundary(x,y,s);
plot(x,y, 'db', x(k), y(k), '-r')
  댓글 수: 25
Alberto Acri
Alberto Acri 2023년 1월 4일
Hi @Mathieu NOE! Can I ask you again for your help? Using the attached files (the files you had attached previously), I noticed a "problem" with the file test_114_check.txt of which I also attach an image.
How can I do to extrapolate, even for this curve, only the outer coordinates?
I thank you for your help in advance!
Mathieu NOE
Mathieu NOE 2023년 1월 4일
편집: Mathieu NOE 2023년 1월 4일
hello Alberto
happy new year !!
for your problem above, simply increase Fd for the second method until you get the expected results
file : code_v3.m
%% test 3 : with find_delaunay_boundary03_fig1
% (from Fex : https://fr.mathworks.com/matlabcentral/fileexchange/60690-boundary-extraction-identification-and-tracing-from-point-cloud-data?s_tid=ta_fx_results )
% Fd = 1.5; %Fd = dmax (max point to point distance)
Fd = 3; %Fd = dmax (max point to point distance)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Alberto Acri
Alberto Acri 2024년 6월 12일
I tried using the various functions to retrieve the outermost nodes for other types of curves like the ones attached. Of these the best would (probably) be the one attached.
Do you happen to know if there is a possibility to identify the 'Fd' parameter automatically so as to retrieve exactly the outer nodes?
Here is the code:
%data
PARAMETER = 0.2;
% ===============
x = data(:,1);
y = data(:,2);
% (from Fex : https://fr.mathworks.com/matlabcentral/fileexchange/60690-boundary-extraction-identification-and-tracing-from-point-cloud-data?s_tid=ta_fx_results )
Fd = PARAMETER; %Fd = dmax (max point to point distance)
[bids, E, Ne] = find_delaunay_boundary03_fig1(data,Fd);
x3 = [];
y3 = [];
for ck = 1:numel(bids)
x3 = [x3; x(bids{ck})];
y3 = [y3; y(bids{ck})];
end
nodes_ext_2D = [x3, y3];
figure
plot(data(:,1),data(:,2),'r.','MarkerSize',10);
hold on
plot(nodes_ext_2D(:,1),nodes_ext_2D(:,2),'k.','MarkerSize',10);
hold off
Here two examples: on the left a 'simple' curve but I can't retrieve all the outer nodes; on the right a more complicated case.
  댓글 수: 1
Mathieu NOE
Mathieu NOE 2024년 6월 12일
hello again
I tried a few things , but it seems we are always a bit loo low or too high, so either we pick too many points or not enough (so we get this small gaps as you show on the left picture). I am not sure there is a magical way to solve that issue - or we need another approach , like how to identify the inner zig zags and remove them.
here what I have tried , based on the averaged distance between points and defining the Fd value from there.
with data_1 it works well , for other cases it's not so good
%data
% ===============
data = data_7;
x = data(:,1);
y = data(:,2);
% Execute boundary
k=boundary(x(:),y(:),1);
xk = x(k);
yk = y(k);
dx = mean(abs(diff(xk)));
dy = mean(abs(diff(yk)));
dr = sqrt(dx.^2 + dy.^2);
PARAMETER = 5*dr;
% dx = max(abs(diff(x)));
% dy = max(abs(diff(y)));
% dr = sqrt(dx.^2 + dy.^2);
% PARAMETER = 10*dr;
% (from Fex : https://fr.mathworks.com/matlabcentral/fileexchange/60690-boundary-extraction-identification-and-tracing-from-point-cloud-data?s_tid=ta_fx_results )
Fd = PARAMETER; %Fd = dmax (max point to point distance)
[bids, E, Ne] = find_delaunay_boundary03_fig1(data,Fd);
x3 = [];
y3 = [];
for ck = 1:numel(bids)
x3 = [x3; x(bids{ck})];
y3 = [y3; y(bids{ck})];
end
nodes_ext_2D = [x3, y3];
figure
plot(data(:,1),data(:,2),'r.','MarkerSize',10);
hold on
plot(xk,yk,'g*','MarkerSize',10);
plot(nodes_ext_2D(:,1),nodes_ext_2D(:,2),'k.','MarkerSize',10);
hold off
legend('raw data','boudary S = 1','delaunay boudary');

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Construction에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by