How to Find Correct Vertice formation for polyxpoly function

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 件のコメント

Torsten
Torsten 2022 年 3 月 29 日
An annulus is not a polygon.
Kayra Dernek
Kayra Dernek 2022 年 3 月 30 日
Thanks I updated the question.

サインインしてコメントする。

 採用された回答

Matt J
Matt J 2022 年 3 月 30 日
編集済み: Matt J 2022 年 3 月 30 日

1 投票

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 件)

カテゴリ

ヘルプ センター および File ExchangeGraph and Network Algorithms についてさらに検索

製品

リリース

R2020b

質問済み:

2022 年 3 月 29 日

編集済み:

2022 年 3 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by