-
Notifications
You must be signed in to change notification settings - Fork 2
/
potential_plots.m
55 lines (50 loc) · 1.25 KB
/
potential_plots.m
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
%Credits Dr Lyuba Alboul's lecture notes
%Potting function
function [plots] = potential_plots(x,y, obstacle)
[xx, yy] = meshgrid(x,y);
% Measuring the distance between two points
pos1 = sqrt((xx-obstacle(1,1)).^2+(yy-obstacle(2,1)).^2);
% The following code produces a mesh graph that provides spikes and downs
% based on the building positions and goal position only ploted it while
% taking into the account of XY plane of the created environment.
for i = 1:numel(x)
for j = 1:numel(y)
if pos1(i,j) > 1.5 && pos1(i,j)<=5
posf1(i,j)= pos1(i,j).^(-1);
end
if pos1(i,j)>= 5
posf1(i,j) =0;
end
if pos1(i,j) <=1.5
posf1(i,j)= 1/(1.5);
end
end
end
negd2=(xx-102).^2 +(yy-105).^2 -0.002;
negd=sqrt(negd2);
neg=negd.^(-1);
zz=posf1-neg;
figure(2)
title('Potential Fields plot')
xlabel('x')
ylabel('y')
hold on
% A 3-D mesh plot of the potential
mesh(real(zz))
pause(1)
figure(3)
title('Quiver plot of the environment')
xlabel('x')
ylabel('y')
hold on
[px,py]=gradient(zz,.1,.1);
quiver(x,y,-px,-py,1.2, 'r'), hold on
quiver(x(12),y(12),-px(12),-py(12),2, 'g')
pause(1)
figure(4)
title('Contour plot of the environment')
xlabel('x')
ylabel('y')
hold on
contour(zz,21)
end