Can't see quiver plot
15 次查看(过去 30 天)
显示 更早的评论
I'm currently trying to make a code of potential field for path planning.
I defined potential energy(u_att, u_rep) and then force(fxa,fya,fxr,fyr) by using 'gradient'.
To the best of my knowledge, force vector(fxa,fya,fxr,fyr) is properly calculated,
but when I plot that force vector with 'quiver', I couldn't see anything on the plot.
How can I fix this?
Code for potential field is attached below
Thank you.
close all; clear; clc;
figure, hold on;
axis([0 100 0 100]), axis square, box on;
xlabel('x'), ylabel('y');
obslist = [60 60 15;
20 40 7;
70 30 5];
x_start = [10 10];
x_goal = [90 90];
plot(x_start(1),x_start(2),'rx','linewidth',2);
plot(x_goal(1),x_goal(2),'bo','linewidth',2);
angs = (0:pi/50:2*pi)';
xpu = cos(angs); ypu = sin(angs);
for i=1:size(obslist,1)
xp = obslist(i,1) + obslist(i,3)*xpu;
yp = obslist(i,2) + obslist(i,3)*ypu;
fill(xp,yp,'y');
plot(xp,yp,'k');
end
% Above code is from KAIST Spring 2023 ME652 lecture
% -------------------------------------------------------------------------
slice = 1;
[X, Y] = meshgrid(0:slice:100, 0:slice:100);
Ka = 5;
u_att = 0.5*Ka*sqrt((X-x_goal(1)).^2 + (Y-x_goal(2)).^2);
[fxa,fya] = gradient(u_att,slice,slice);
Kr = 500;
u_rep = zeros(size(X));
for i=1:size(obslist,1)
u_rep = u_rep + 0.5.*Kr*(1./sqrt((X-obslist(i,1)).^2 + (Y-obslist(i,2)).^2) - 1./sqrt((obslist(i,3)+2))).^2;
end
[fxr,fyr] = gradient(u_rep,slice,slice);
fX = - fxr - fxa;
fY = - fyr - fya;
quiver(X,Y,fX,fY, 'k')
% contour(X,Y,u_att+u_rep,25)
0 个评论
采纳的回答
chicken vector
2023-5-3
编辑:chicken vector
2023-5-3
Because there are too many arrows and they overlap, causing the automatic scaling to not display anything.
Set the scale to 'off'with:
quiver(X,Y,fX,fY,0)
And adjust the values of fX and fY accordingly.
You can see an example in the comments.
2 个评论
chicken vector
2023-5-3
close all; clear; clc;
figure, hold on;
axis([0 100 0 100]), axis square, box on;
xlabel('x'), ylabel('y');
obslist = [60 60 15;
20 40 7;
70 30 5];
x_start = [10 10];
x_goal = [90 90];
plot(x_start(1),x_start(2),'rx','linewidth',2);
plot(x_goal(1),x_goal(2),'bo','linewidth',2);
angs = (0:pi/50:2*pi)';
xpu = cos(angs); ypu = sin(angs);
for i=1:size(obslist,1)
xp = obslist(i,1) + obslist(i,3)*xpu;
yp = obslist(i,2) + obslist(i,3)*ypu;
fill(xp,yp,'y');
plot(xp,yp,'k');
end
% Above code is from KAIST Spring 2023 ME652 lecture
% -------------------------------------------------------------------------
slice = 1;
[X, Y] = meshgrid(0:slice:100, 0:slice:100);
Ka = 5;
u_att = 0.5*Ka*sqrt((X-x_goal(1)).^2 + (Y-x_goal(2)).^2);
[fxa,fya] = gradient(u_att,slice,slice);
Kr = 500;
u_rep = zeros(size(X));
for i=1:size(obslist,1)
u_rep = u_rep + 0.5.*Kr*(1./sqrt((X-obslist(i,1)).^2 + (Y-obslist(i,2)).^2) - 1./sqrt((obslist(i,3)+2))).^2;
end
[fxr,fyr] = gradient(u_rep,slice,slice);
fX = - fxr - fxa;
fY = - fyr - fya;
quiver(X,Y,fX/5,fY/5,0,'Color','k')
更多回答(1 个)
Chunru
2023-5-3
figure, hold on;
axis([0 100 0 100]), axis square, box on;
xlabel('x'), ylabel('y');
obslist = [60 60 15;
20 40 7;
70 30 5];
x_start = [10 10];
x_goal = [90 90];
plot(x_start(1),x_start(2),'rx','linewidth',2);
plot(x_goal(1),x_goal(2),'bo','linewidth',2);
angs = (0:pi/50:2*pi)';
xpu = cos(angs); ypu = sin(angs);
for i=1:size(obslist,1)
xp = obslist(i,1) + obslist(i,3)*xpu;
yp = obslist(i,2) + obslist(i,3)*ypu;
fill(xp,yp,'y');
plot(xp,yp,'k');
end
% Above code is from KAIST Spring 2023 ME652 lecture
% -------------------------------------------------------------------------
slice = 1;
[X, Y] = meshgrid(0:slice:100, 0:slice:100);
Ka = 5;
u_att = 0.5*Ka*sqrt((X-x_goal(1)).^2 + (Y-x_goal(2)).^2);
[fxa,fya] = gradient(u_att,slice,slice);
Kr = 500;
u_rep = zeros(size(X));
for i=1:size(obslist,1)
u_rep = u_rep + 0.5.*Kr*(1./sqrt((X-obslist(i,1)).^2 + (Y-obslist(i,2)).^2) - 1./sqrt((obslist(i,3)+2))).^2;
end
[fxr,fyr] = gradient(u_rep,slice,slice);
fX = - fxr - fxa;
fY = - fyr - fya;
% quiver(X,Y,fX,fY, 'k')
figure
quiver(X,Y,fX,fY,0)
% Check your code, fX and fY has inf values so that the autoscale is not
% working
max(fX(:)),max(fY(:))
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Vector Fields 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!