How to Find Correct Vertice formation for polyxpoly function

5 visualizaciones (últimos 30 días)
Kayra Dernek
Kayra Dernek el 29 de Mzo. de 2022
Editada: Matt J el 30 de Mzo. de 2022
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

Respuesta aceptada

Matt J
Matt J el 30 de Mzo. de 2022
Editada: Matt J el 30 de Mzo. de 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

Más respuestas (0)

Categorías

Más información sobre Graph and Network Algorithms en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by