Creating a function (pathfinding algorithm)
2 ビュー (過去 30 日間)
古いコメントを表示
How do you create a function:
function [ filled ] = travelDistance ( blank )
where: blank is a two-dimensional array comprised of -1s, 0s and 1s, and filled is blank modified to the specifications below.
To create filled, replace every 0 in blank with its distance to the nearest 1 (staring at 2), traveling along cardinal directions (up, down, left and right) without passing through a -1 value. That is, all 0s that are directly next to a 1 should be changed to a 2 and all 0s next to any new 2s should be changed to 3s, and so on. Spaces with -1 values should be treated as “walls” and should stay -1. If there is no route from a 0 to a 1 without passing through a -1, it should remain a 0. The ultimate result should be that every 0 that is connected to a 1 is replaced with its distance to the nearest 1.
2 件のコメント
回答 (1 件)
Image Analyst
2017 年 10 月 12 日
To do it that way (manually), then fist compute the distance transform with bwdist().
Otherwise, do it automatically with bwdistgeodesic(). See Steve's blog: http://blogs.mathworks.com/steve/2011/11/01/exploring-shortest-paths-part-1/
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!