Borrar filtros
Borrar filtros

Finding intersection of line(vector) and an unclosed shape

5 visualizaciones (últimos 30 días)
Mohammadreza
Mohammadreza el 2 de Jun. de 2023
Comentada: Image Analyst el 3 de Jun. de 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 comentarios
Mohammadreza
Mohammadreza el 2 de Jun. de 2023
Vector(arrow) helps me to visualize the simulation better.

Iniciar sesión para comentar.

Respuestas (1)

Matt J
Matt J el 2 de Jun. de 2023
Editada: Matt J el 2 de Jun. de 2023

Categorías

Más información sobre Elementary Polygons en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by