Finding intersection of line(vector) and an unclosed shape
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a robot and wall obstacles. My robot has binary sensors which can detect obstacles which are directly in front of them. The wall obstacles have an unclosed shape which is challenging cause with closed I could assume it's polygon. I want to find a way(Matlab command) to tell me if the line(vector) is in the shape or on its edge or not.
Here is my obstacle shape:
%Obstacle Parameters
Points = [[6.5 4.5];
[4.5 4.5];
[4.5 2.5];
[1.0 2.5];
[1.0 6.0];
[3.0 6.0];
[3.0 7.5];
[1.5 7.5];
[1.5 8.5];
[5.0 8.5]];
%Find Obstacle Points
Obstacle_Points = [];
for i = 1:9
ang = atan2(Points(i+1 , 2) - Points(i , 2) , Points(i+1 , 1) - Points(i , 1));
if (ang == pi/2 || ang ==-pi/2)
y = linspace(Points(i , 2) , Points(i+1 , 2) , 100);
x = Points(i , 1) * ones(1 , 100);
Obstacle_Points = [Obstacle_Points ; [x' , y']];
else
x = linspace(Points(i , 1) , Points(i+1 , 1) , 100);
y = Points(i , 2) * ones(1 , 100) ;
Obstacle_Points = [Obstacle_Points ; [x' , y']];
end
end
axis equal
line(Obstacle_Points(:,1) , Obstacle_Points(:,2) , 'LineWidth' , 2 , 'color' , [0.8500 0.3250 0.0980]); xlim([0 7]); ylim([0 10]);
4 commentaires
Voir également
Catégories
En savoir plus sur Elementary Polygons dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!