How to Find Correct Vertice formation for polyxpoly function
14 views (last 30 days)
Show older comments
I am trying to find intersection points of horizontal lines and drawn polygon with a hole. However, pgon.Vertices does not give proper formation for polyxpoly function and I get incorrect results for intersection points (For example y = 0 intersection point return 0.514 value). The code I am running as follows, how can I transform pgon.Vertices format format suitable for polyxpoly. Figure displays the lines and annulus I am trying to find intersection points.
Thanks

clear
clc
clf
t = 0.05:0.005:2*pi;
x1 = cos(t);
y1 = sin(t);
x2 = 0.5*cos(t);
y2 = 0.5*sin(t);
pgon = polyshape({x1,x2},{y1,y2});
[corrected_x1,corrected_y1] = poly2ccw(pgon.Vertices(:,1), pgon.Vertices(:,2));
plot(pgon)
hold on
for j = -1.5:0.1:2
x = [-2,4];
y = [j, j];
[xi,yi] = polyxpoly(x,y,corrected_x1,corrected_y1);
plot(x,y)
end
2 Comments
Accepted Answer
Matt J
on 30 Mar 2022
Edited: Matt J
on 30 Mar 2022
Instead of polyxpoly, I would recommend downloading linexlines2D(),
t = 0.05:0.005:2*pi;
x1 = cos(t);
y1 = sin(t);
x2 = 0.5*cos(t);
y2 = 0.5*sin(t);
pgon = polyshape({x1,x2},{y1,y2});
lineEq=[0,1,-0.25];
xy=linexlines2D(pgon,lineEq); %intersection points
plot(pgon)
hold on
fimplicit(@(x,y)lineEq*[x;y;x.^0],[-2,2]); %plot line
plot(xy(1,:), xy(2,:),'ro'); %plot intersection points
hold off
axis equal
0 Comments
More Answers (0)
See Also
Categories
Find more on Graph and Network Algorithms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!