Create polyshape with no duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected results
16 views (last 30 days)
Show older comments
I am trying to create convex polygons with n vertices, area = 1 and with no intersections between edges, and even though I try to loop until it's a simple polygon (using issimplified), I still get the warning :
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or
unexpected results. Input data has been modified to create a well-defined polyshape.
> In polyshape/checkAndSimplify (line 480)
In polyshape (line 175)
In PolygonConvexe (line 23)
My goal is to have polygons where edges don't intersect.
What I'm looking for
What I get sometimes
Thank yo very much for your help
function [Xpa,Ypa]=PolygonConvexe(n)
Xa=zeros(1,n);
Ya=zeros(1,n);
convex=false;
simple=false ;
one_region=false;
while convex==false || simple==false || one_region==false
for i=1:n
Xa(i)=rand(1,1);
Ya(i)=rand(1,1);
end
convex=est_convexe(Xa,Ya);
polygone=polyshape(Xa,Ya);
simple=issimplified(polygone);
polyout=simplify(polygone);
one_region=polyout.NumRegions==1;
end
a=polyarea(Xa,Ya);
Xa=Xa./sqrt(a);
Ya=Ya./sqrt(a);
pgon=polyshape(Xa,Ya);
plot(pgon)
Xpa=Xa;
Ypa=Ya;
0 Comments
Answers (1)
Matt J
on 8 Dec 2021
Edited: Matt J
on 8 Dec 2021
Perhaps as follows.
n=7; %number of vertices
pgon=nsidedpoly(n);
v=rand(2,1);
v=v/norm(v);
v=[v*0.3;0.7];
v=v/norm(v);
R=null(v');
R(:,2)=cross(v,R(:,1));
R(:,3)=v;
R=R';
c=rand(2,1)*3;
P=[2*eye(2),c;0 0 1]*R*[eye(3),[ 0 ;0 ;0]]; %random camera projection
P=P.';
for i=1:2
pgon.Vertices=pmap(P,pgon.Vertices);
end
pgon.Vertices=pgon.Vertices/sqrt(area(pgon));
pgon=simplify(pgon);
area(pgon)
plot(pgon);shg
function V=pmap(A,V)
m=size(V,1);
V=[V,ones(m,2)]*A;
V=V(:,1:2)./V(:,end);
end
0 Comments
See Also
Categories
Find more on Elementary Polygons 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!