Finding a a path between two points on a 3d surface that proceeds through lowest value points.
30 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mahesh
el 19 de Jul. de 2024 a las 12:38
Comentada: Mathieu NOE
el 19 de Jul. de 2024 a las 17:13
Hello,
I have data (100X50 array for X, Y and Z coordiantes ) corresponding to the surface shown in the below image. I am interested in obtaining paths from flat region (right side yellow circle) of the surface to the minima at red and brown cricle on the left side of the surface. Only condition is that the path should proceed through lowest value points along the Z axis. I could obtain one path connecting yellow and red circles by using "min" function in matlab. I tried find peaks in order to obtain the other path (shown with black arrow in the image). But, the well around the brown circle is very shallow resulting the findpeaks gives only one peak at the region of red circle. Could you please help me to obtain the second path that connects yellow and brown circles. I have also attached my data file. "Shortestpath" function in matlab might be useful for this purpose. I am however not sure how to use it.
These type of paths are referred as "minimum energy paths" in chemistry, assuming that the Z-axis is energy and X- and Y-axis represent molecular coordiantes. In other words, I am looking for a steepest descent path between yellow and brown circles.
Thank you very much for your time
Regards,
Mahesh
1 comentario
Mathieu NOE
el 19 de Jul. de 2024 a las 17:13
it would help if you could post the code and "Shortestpath" function
Respuestas (1)
Star Strider
el 19 de Jul. de 2024 a las 16:26
I am not certain what you wantt, and I doubt there is a way to impoose the energy constraints on the path. (The shortestpath function is for graph objects. What you want to do will not apply since it is not a graph.)
I did two things here, the first was to determine the contours of the regions where the gradient result (numerical derivative) is 0 using the contour function (actually contour3 because I want to draw the contours on the gradient plot), then I drew the contours on the original plot, as well as a direct line from what I believe to be the desired origin to the desired end point. (I guessed at those using tthe contour results because they were not specifically stated in your question.)
Try this —
A1 = readmatrix('data.txt');
[U2,ix] = unique(A1(:,2),'stable');
coldim = mean(diff(ix));
xm = reshape(A1(:,1), coldim, []);
ym = reshape(A1(:,2), coldim, []);
zm = reshape(A1(:,3), coldim, []);
figure
surf(xm, ym,zm)
xlabel('X')
ylabel('Y')
zlabel('Z')
title('Original Surface')
view(30,60)
dx = abs(mean(diff(xm(:,1)))) % Step In The X (row) Direction
dy = abs(mean(diff(ym(1,:)))) % Step In The Y (column) Direction
dzm = gradient(zm, dy, dx); % Surface Numerical Derivative
figure
surf(xm, ym, dzm)
hold on
c = contour3(xm, ym, dzm, [0 0], 'r', 'LineWidth',2);
idx = find(c(1,:)==0);
hold off
xlabel('X')
ylabel('Y')
zlabel('dZ')
title('Derivative Surface')
view(30,60)
% view(0,90)
Fz = scatteredInterpolant(A1(:,1), A1(:,2), zm(:));
idx = find(c(1,:)==0)
for k = 1:numel(idx)
seglen = c(2,idx(k));
xv{k} = c(1,idx(k)+(1:seglen));
yv{k} = c(2,idx(k)+(1:seglen));
zv{k} = Fz(xv{k}.',yv{k}.');
end
xe = mean(xv{3}) % End Point: X
ye = mean(yv{3}) % End Point: Y
xs = xv{2}(end) % Start Point: X
ys = yv{2}(end) % Start Point: Y
N = 250;
xl = linspace(xs, xe, N); % Define Line: X
yl = linspace(ys, ye, N); % Define Line: Y
zl = Fz(xl.', yl.'); % Define Line: Z
rgb = 'rgb';
figure
surf(xm, ym,zm, 'DisplayName','Surface')
hold on
for k = 1:numel(zv)
plot3(xv{k}, yv{k}, zv{k}, rgb(k), 'LineWidth',2, "DisplayName",["Minimum Contour "+k])
end
plot3(xl.', yl.', zl, 'm', 'LineWidth',2, 'DisplayName','Direct Path')
hold off
xlabel('X')
ylabel('Y')
zlabel('Z')
title('Original Surface With Contour & Path Lines')
view(30,60)
legend('Location','bestoutside')
.
0 comentarios
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!