MATLAB function for finding intersection points between line and multiple polygon

5 次查看(过去 30 天)
Hello everyone,
I am looking for any MATLAB function or logic to find intersection between single scan-line and multiple polygon (one inside another).
Here as you can see into attached figure, I need to find intersection points 1,2,3 and 4. scan-line Y=2 is intersecting both the polygon-1 and 2 at same time. Polygon 2is inside the polygon 1 and the orange lines indicates the way I want to fill this area between two polygon.
MATLAB library "Geom2d" has function named 'intersectLinePolygon(line, poly, varargin)'. But this function takes only single line and one polygon as a input paramter.
So please help me with any other function which can find intersection between single line and multiple polygon.
thank you in advance.

采纳的回答

Star Strider
Star Strider 2018-12-9
One option is to use the inpolygon function:
rctnglx = [1 1 3 3 1]; % Create Data
rctngly = [1 2 2 1 1]; % Create Data
linx = linspace(0, 4); % Create Data
liny = ones(1,numel(linx))*1.5; % Create Data
[in, on] = inpolygon(linx, liny, rctnglx, rctngly); % Points Of Line In Or On Rectangle
leftidx = find(in,1,'first'); % Left Intersection
rightidx = find(in,1,'last'); % Right Intersection
figure
plot(rctnglx, rctngly)
hold on
plot(linx, liny)
plot(linx(leftidx), liny(leftidx), 'or', linx(rightidx), liny(rightidx), 'or')
hold off
ylim([0 3])
Experiment to get this to work with your data.
  4 个评论
yogi patel
yogi patel 2018-12-9
Thank you so much. Now I can easily set my logic from this code. :) Will get back to you if I will stuck with something else. But for now I got my answer.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by