Finding intersection of line(vector) and an unclosed shape

2 visualizzazioni (ultimi 30 giorni)
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 Commenti
Mohammadreza
Mohammadreza il 2 Giu 2023
Vector(arrow) helps me to visualize the simulation better.

Accedi per commentare.

Risposte (1)

Matt J
Matt J il 2 Giu 2023
Modificato: Matt J il 2 Giu 2023

Categorie

Scopri di più su Elementary Polygons in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by