Code covered by the BSD License  

Highlights from
Finding optimal path on a terrain

image thumbnail

Finding optimal path on a terrain

by

 

13 Nov 2012 (Updated )

Finding optimal path on a terrain using forward dynamic programming.

visualizePath(T, optimalPath)
function visualizePath(T, optimalPath)

% Visualize the path on given terrain T.
%
% manurung.auralius@gmail.com
% 17.11.201
% -------------------------------------------------------------------------

[m, n] = size(T);
l = length(optimalPath);

% Conver back the node number to a xyz coordinate.
x = zeros(1, l);
y = zeros(1, l);
z = zeros(1, l);
for i = 1 : l
    x(i) = mod(optimalPath(i) - 1, n) + 1;
    y(i) = abs((optimalPath(i) - 1 - mod(optimalPath(i) - 1, n)) / n) + 1;
    z(i) = 1.0 + T(y(i), x(i));
end

% Draw the optimal path as line.
plot3(x, y, z, 'r', 'LineWidth', 2)

% Draw asterisk symbol (*) at destination nodes.
plot3(x(l), y(l), z(l), '*m', 'LineWidth', 4)

Contact us