Tutorial5_MotionPlanning/checkCollisionAlongLine.m

21 lines
621 B
Matlab

% Function to check for collisions along the line segment
function collision = checkCollisionAlongLine(pointA, pointB, L1, L2)
collision = false;
% Define a set of points along the line segment
numPoints = 100;
xValues = linspace(pointA(1), pointB(1), numPoints);
yValues = linspace(pointA(2), pointB(2), numPoints);
for i = 1:numPoints
x = xValues(i);
y = yValues(i);
% Check if the point collides with obstacles
if (y >= L1) || (y <= -L1) || (x >= -L2 && x <= L2 && y >= -L2 && y <= L2)
collision = true;
break;
end
end
end