Matlab has built in shortestpath function based on Dijkstra algorithm:
However the algorithm only applies to graph, We need to convert 3d point cloud to graph first in order to use it.
What constitutes a graph:
- nodes (points or vertex)
- edges (connectivity)
In matlab graph, connection is expressed as adjacency matrix,
1. create adjacent matrix
d = pdist(PointsSet);
d_adj = squareform(d);
2. create graph and add in nodes
G = graph(d_adj) ;
G.Nodes = array2table(Position,'VariableNames',{'X','Y','Z'});
1. Random graph
% https://www.mathworks.com/matlabcentral/answers/445321-how-to-find-shortest-distance-in-3d
% for repeatability
rng('default')
% Generate 10 random 3d points
Position = 10*rand(10,3);
%Calculate pa