フィルターのクリア

Robotics in Wall Collision Problem

1 回表示 (過去 30 日間)
Ho Nam Ernest Yim
Ho Nam Ernest Yim 2018 年 2 月 23 日
回答済み: Cam Salzberger 2018 年 2 月 23 日
I was trying to do Path Planning for a robot by generating random nodes and linking them together. However, when nodes are linked, lines could be outside the map that I set. Therefore, I've tried to find intersections between the wall lines and nodes lines and delete them. The below shows my code of working :
map = [-30,0;-30,40;30,40;30,60;5,60;45,90;85,60;60,60;60,40;120,40;120,60;95,60;135,90;175,60;150,60;150,40;210,40;210,60;185,60;225,90;265,60;240,60;240,40;300,40;300,0]; %repeated features
botSim = BotSim(map,[0,0,0]); %sets up a botSim object a map, and debug mode on.
botSim.drawMap();
N_n = 20; % number of nodes
N = zeros(N_n,2);
a = size(map);
for i = 1:a(1)
n_cor(i,1) = map(i,1);
n_cor(i,2) = map(i,2);
L_w = line(n_cor(i,1),n_cor(i,2));
for i = 1:N_n
q = botSim.getRndPtInMap(10)';
N(i,:) = q;
plot(N(:,1),N(:,2),'o')
plot(N(:,1),N(:,2),'-')
L_n = line(N(:,1),N(:,2));
hold on
end
if L_w == L_n
L_n = [];
end
end
With the above code, I couldn't manage to delete those lines which intersect with walls. Can I know why and will there be an easier/efficient way to work on this?? Thank you

採用された回答

Cam Salzberger
Cam Salzberger 2018 年 2 月 23 日
It looks like the logic that you are using to see if the lines are intersecting is simply comparing the handles to the graphics objects. Remember that (unless you have overloaded it), the line function creates the graphics object and returns a handle to it. That handle contains information about the line, but direct comparisons to different lines will always return false.
It also looks like you have it set to simply set the variable to empty if the lines are equal. This will not delete the line, just change the value of the variable. To delete the line, use the delete method.
Here are some suggestions for ways to check if the line segments intersect. Then you can just check the path line against each wall.
-Cam

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRobotics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by