Can't see quiver plot

조회 수: 14 (최근 30일)
기홍 박
기홍 박 2023년 5월 3일
편집: chicken vector 2023년 5월 3일
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)

채택된 답변

chicken vector
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
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')
기홍 박
기홍 박 2023년 5월 3일
Thanks for your help!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Chunru
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(:))
ans = Inf
ans = Inf
  댓글 수: 1
기홍 박
기홍 박 2023년 5월 3일
Thanks for your help!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Vector Fields에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by