Effacer les filtres
Effacer les filtres

Finding intersection of line(vector) and an unclosed shape

1 vue (au cours des 30 derniers jours)
Mohammadreza
Mohammadreza le 2 Juin 2023
Commenté : Image Analyst le 3 Juin 2023
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
Mohammadreza
Mohammadreza le 2 Juin 2023
Vector(arrow) helps me to visualize the simulation better.
Image Analyst
Image Analyst le 3 Juin 2023
Would inpolygon help?

Connectez-vous pour commenter.

Réponses (1)

Matt J
Matt J le 2 Juin 2023
Modifié(e) : Matt J le 2 Juin 2023

Catégories

En savoir plus sur Elementary Polygons dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by