Find the curve connecting points following the gradient
Afficher commentaires plus anciens
Hello, I'm in the following situation:
dx = 0.1;
dy = 0.1;
x = -2:dx:2;
y = -2:dy:2;
[X,Y] = meshgrid(x,y);
t = peaks(X,Y);
[sx,sy] = gradient(t);
contour(X,Y,t)
hold on
quiver(X,Y,sx,sy)
colorbar
[rm,cm]=find(t==min(t,[],"all"));
[rM,cM]=find(t==max(t,[],"all"));
plot(x(cm),y(rm),'b^',"MarkerFaceColor","b")
plot(x(cM),y(rM),'r^',"MarkerFaceColor","r")
hold off
I would like to connect the blue and red points with a curve which follows the arrows. If there are many I would like to pick the shortest one.
As a bonus point, after that I would also like to create a matrix whose elements represent the curve length for each grid point
Réponse acceptée
Plus de réponses (1)
Image Analyst
le 12 Août 2021
0 votes
The shortest point is simply the Euclidean distance. If you want to apply some cost function like the path is weighted by the values along it then you can use a process like dynamic programming or the A* algorithm. But there might be some kind of built-in function in an optimization toolbox that I don't know about. Or maybe you can use one of the built-in algorithms to the shortestpath() function.
1 commentaire
tandemuse
le 12 Août 2021
Catégories
En savoir plus sur Polygonal Shapes dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
