25 views (last 30 days)
Show older comments
Mahesh on 19 Jul 2024 at 12:38
Commented: Mathieu NOE on 19 Jul 2024 at 17:13
- data.txt
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 Comment Show -1 older commentsHide -1 older comments
Show -1 older commentsHide -1 older comments
Mathieu NOE on 19 Jul 2024 at 17:13
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/2138761-finding-a-a-path-between-two-points-on-a-3d-surface-that-proceeds-through-lowest-value-points#comment_3215946
⋮
it would help if you could post the code and "Shortestpath" function
Sign in to comment.
Sign in to answer this question.
Answers (1)
Star Strider on 19 Jul 2024 at 16:26
Open in MATLAB Online
- data.txt
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
dx = 0.0202
dy = abs(mean(diff(ym(1,:)))) % Step In The Y (column) Direction
dy = 1.4286
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)
idx = 1x3
1 24 145
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
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
xe = 1.2734
ye = mean(yv{3}) % End Point: Y
ye = 102.1280
xs = xv{2}(end) % Start Point: X
xs = 3
ys = yv{2}(end) % Start Point: Y
ys = 114.8958
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 Comments Show -2 older commentsHide -2 older comments
Show -2 older commentsHide -2 older comments
Sign in to comment.
Sign in to answer this question.
See Also
Categories
MATLABGraphics2-D and 3-D PlotsSurfaces, Volumes, and PolygonsSurface and Mesh Plots
Find more on Surface and Mesh Plots in Help Center and File Exchange
Tags
- minimum value path between two points on 3d grid
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office