Clear Filters
Clear Filters

Finding intersection of line(vector) and an unclosed shape

1 view (last 30 days)
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 Comments
Mohammadreza
Mohammadreza on 2 Jun 2023
Vector(arrow) helps me to visualize the simulation better.

Sign in to comment.

Answers (1)

Matt J
Matt J on 2 Jun 2023
Edited: Matt J on 2 Jun 2023

Categories

Find more on Elementary Polygons in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!