Newer
Older
abgabensammlungSS15 / mr / ub10 / DTA.m
@MaxXximus92 MaxXximus92 on 2 Jul 2015 1 KB mr
function [ output_args ] = DTA(map,start,aim)
%UNTITLED4 Summary of this function goes here
%   Detailed explanation goes here

d=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
    -1,-1,inf,inf,-1,inf,inf,inf,inf,-1
    -1,inf,inf,inf,-1,inf,inf,inf,inf,-1
    -1,inf,inf,inf,-1,-1,inf,inf,inf,-1
    -1,inf,-1,inf,inf,-1,-1,inf,-1,-1
    -1,inf,-1,inf,-1,-1,-1,inf,-1,-1
    -1,inf,-1,inf,inf,inf,inf,inf,inf,-1
    -1,0,-1,inf,inf,inf,inf,inf,inf,-1
    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1]
dvt= d

changed = true;
s2= sqrt(2);
step=-1;
while changed 
    step=step+1
    changed= false;
    for y = size(d,1)-1:-1:2
        for x = 2:size(d,2)-1
            x
            y
            d(y,x)
            if(d(y,x) >-1)
                a=[d(y,x)]
                if(d(y,x-1) >-1)
                    a=[a d(y,x-1)+1];
                end
                if(d(y,x+1) >-1)
                    a=[a d(y,x+1)+s2];
                end
                if(d(y+1,x)>-1)
                    a=[a d(y+1,x)+1];
                end
                if d(y+1,x-1) >-1
                    a=[a d(y+1,x-1)+s2];
                end
                mi = min(a);
                if(mi~=d(y,x));
                    changed = true;
                end
                d(y,x) = mi;
                
            end
        end
    end
    forward=0
    d
    for y = 2:size(d,1)-1
        for x = size(d,2)-1:-1:2
            if(d(y,x) >-1)
                a=[d(y,x)];
                if(d(y,x+1) >-1)
                    a=[a d(y,x+1)+1];
                end
                if(d(y-1,x-1) >-1)
                    a=[a d(y-1,x-1)+s2];
                end
                if(d(y-1,x)>-1)
                    a=[a d(y-1,x)+1];
                end
                if d(y-1,x+1) >-1
                    a=[a d(y-1,x+1)+s2];
                end
                mi = min(a);
                if(mi~=d(y,x))
                    changed = true;
                end
                d(y,x) = mi;
            end
        end
    end
    backward=0
    step
    d
end

end