Extraction of the spatial coordinates of a curve and calculation of the normal line to each of its points

6 Ansichten (letzte 30 Tage)
Hello everyone
I have the following dataset: https://www.dropbox.com/scl/fo/3dthvtj2ex9gmhsu3lkrq/AJt2KVYls3YM89v5SRmSEWk?rlkey=r63d0ej2sv7ku8i4ardla5pvi&dl=0, which gives rise to the data on the panel mz of the figure below:
My idea is to extract the (a,b) set of points that define the whole right side of the whitish curve. Once that it is done, I will need to extract, for each of the points of this curve, the normal line along the track (that it is, the (a,b) coordinates together with the corresponding values of the mz values).
Any ideas on how to do this efficiently?
Additional information (September 3, 2024)
When I talk about the normal to the tangent at each point of the curve mz, I am thinking about something like this:
where the green X symbol corresponds to a certain point of the curve, the black line to the tangent to the curve at that specific (x,y) point, and the dashed yellow line refers to the normal to the tangent line that (x,y) point. I would be interested in extracting the mz value all along that normal line inside the boundaries of the sample. So I would say that some grid data process would be important to make if not too many points actually exist in the given data set.

Akzeptierte Antwort

Mathieu NOE
Mathieu NOE am 2 Sep. 2024
hello
tried a few things here
As far as I have understood correctly your question, the points you are looking for are given by xs,ys,mzs as computed below.
I interpreted this "whole right side of the whitish curve" as the points that have a slightly positive z value so there are slightly on the right side of the white separation line . Adapt the value (and tlerance) to your needs . From the extracted points I obtain a smooth curve using this Fex submission
Zoomed plot showing the raw selected points (in green) and the smoothed curve (in black)
code :
NB : the last portion (commented) is probably not what you need , I have probably misinterpreted the term "normal" in your query
%% load data files
aa = readmatrix('Space_a.txt');
bb = readmatrix('Space_b.txt');
mz = readmatrix('mz_Data.txt');
% get "white line" border points coordinates
ztarget = 0.05;
tol = 0.02;
[r,c] = find(abs(mz - ztarget)<tol);
xl = aa(c);
yl = bb(r);
zl = mz(c,r);
% sort y data
[yl,ia] = sort(yl);
xl = xl(ia);
zl = zl(ia,:);
%% smoothed curve through the points
% see Fex : https://www.mathworks.com/matlabcentral/fileexchange/25634-smoothn/
zs = smoothn({xl,yl});
xs = zs{1};
ys = zs{2};
% find corresponding z data
mzs = interp2(aa,bb,mz,xs,ys); % notice mzs is equal / very close to target z value (ztarget) which is what we wanted !
%% plot
figure(1)
imagesc(aa,bb,mz)
zmin = min(mz(:));
zmax = max(mz(:));
colormap(redwhiteblue(zmin, zmax));
colorbar;
set(gca,'YDir','normal');
hold on
plot(xl,yl,'*g');
plot(xs,ys,'k','linewidth',2)
hold off
% %% find the normal vectors to the curve
% % see Fex : https://fr.mathworks.com/matlabcentral/fileexchange/32696-2d-line-curvature-and-normals?s_tid=ta_fx_results
% % Vertices = [xs';ys'];
% % Vertices = [xs ys];
% ind = (1:10:numel(xs));
% Vertices = [xs(ind) ys(ind)];
%
% N=LineNormals2D(Vertices);
% plot([Vertices(:,1) Vertices(:,1)+10*N(:,1)]',[Vertices(:,2) Vertices(:,2)+10*N(:,2)]','c');
%
  6 Kommentare
Roderick
Roderick am 11 Sep. 2024
Hi @Mathieu NOE. Thank you very much for your very detailed answer to my question! It has been very helpful, I really appreciate it.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Aditya Saikumar
Aditya Saikumar am 2 Sep. 2024
Hi Richard,
From the graph given, the left region has "mz" values less than 0 and the right region has "mz" values greater than 0. We can extract the data points corresponding to the left and the right region along with their "mz" values using "find" function. The following code achieves the same.
% Load data
a = load('Space_a.txt');
b = load('Space_b.txt');
mz = load('mz_Data.txt');
% Extract the indices corresponding to the right region
[aIndicesRight, bIndicesRight] = find(mz > 0);
% Get the noraml values of the right region:
fprintf("Right:\n");
for idx = 1:10
i = aIndicesRight(idx);
j = bIndicesRight(idx);
fprintf("a = %f, b = %f, mz = %f\n", a(i), b(j), mz(i, j));
end
fprintf("\n");
Here is the output of the above code:
Please find more information about the “find” function in the following MATLAB Documentation link:
I hope this helps!
  1 Kommentar
Roderick
Roderick am 3 Sep. 2024
Hi @Aditya Saikumar. Thank you very much! I have modified the question to include some additional information about the normal to the tangent at each (x,y) point of the obtained curve. Hope it helps.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by