1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| figure(1); ImpRgb=imread('newmap.png'); Imp=rgb2gray(ImpRgb); imshow(Imp) xL=size(Imp,1); yL=size(Imp,2); hold on plot(x_I, y_I, 'ro', 'MarkerSize',5, 'MarkerFaceColor','r'); plot(x_G, y_G, 'go', 'MarkerSize',5, 'MarkerFaceColor','g'); count=1; for iter = 1:3000 p_rand=[]; p_rand(1)=ceil(rand()*xL); p_rand(2)=ceil(rand()*yL); p_near=[]; min_distance = 1000; for i=1:count distance = sqrt( ( T.v(i).x - p_rand(1) )^2 + ( T.v(i).y - p_rand(2) )^2 ); if distance < min_distance min_distance = distance; index = i; end end p_near(1) = T.v(index).x; p_near(2) = T.v(index).y; p_new=[]; p_new(1) = p_near(1) + round( ( p_rand(1)-p_near(1) ) * Delta/min_distance ); p_new(2) = p_near(2) + round( ( p_rand(2)-p_near(2) ) * Delta/min_distance ); if ~collisionChecking(p_near,p_new,Imp) continue; end count=count+1; T.v(count).x = p_new(1); T.v(count).y = p_new(2); T.v(count).xPrev = p_near(1); T.v(count).yPrev = p_near(2); T.v(count).dist = min_distance; new_distance = sqrt( ( p_new(1) - x_G )^2 + ( p_new(2) - y_G )^2 ); if new_distance <= Thr plot(p_new(1), p_new(2), 'bo', 'MarkerSize',2, 'MarkerFaceColor','b'); line( [p_new(1) p_near(1)], [p_new(2) p_near(2)], 'Marker','.','LineStyle','-'); line( [x_G p_new(1)], [y_G p_new(2)], 'Marker','.','LineStyle','-'); break; end plot(p_new(1), p_new(2), 'bo', 'MarkerSize',2, 'MarkerFaceColor','b'); line( [p_new(1) p_near(1)], [p_new(2) p_near(2)], 'Marker','.','LineStyle','-'); hold on; pause(0.1); end
|