# Drawing polygon from lines

7 views (last 30 days)
Tchilabalo on 18 Sep 2020
Commented: Vasishta Bhargava on 18 Sep 2020
I have polygon as shown in Fig1. I also know the coordinates of the vertices. I now want to use those vertices to create a serie of lines that reproduce the same polygon. I have the following code, but can't reproduce the initial figure (see Fig2). I know the "patch" function can be used but it doesn't serve my goal.
clear all
Vertex_X=[30;43;49;45;22;19;30;43;89;28;30;28;0;19;54;45;49;89;54;89;96;66];%X coordinate of vertex
Vertex_Y=[38;40;55;69;66;41;38;40;0;16;38;16;19;41;86;69;55;44;86;44;40;100];%Y coordinate of vertex
for i=1:(length(Vertex_X)-1)
X1(i)=Vertex_X(i);
Y1(i)=Vertex_Y(i);
X2(i)=Vertex_X(i+1);
Y2(i)=Vertex_Y(i+1);
end
A=[X1 Y1];
B=[X2 Y2];
plot(A.',B.','LineWidth', 0.75)

Bruno Luong on 18 Sep 2020
Not smart. A polygon is a set of vertexes and connectivity list.
If you throw away the connectivity list then there is no reliable way to bring them back.
So try to make the connectivity of those Voronoi's diagram available instead of asking such request.
Vasishta Bhargava on 18 Sep 2020
@ Bruno
You are right ! thats why it does not resemble

Vasishta Bhargava on 18 Sep 2020
Edited: Vasishta Bhargava on 18 Sep 2020
Try this
%if true
% code
%end
clear all
Vertex_X=[30;43;49;45;22;19;30;43;89;28;30;28;0;19;54;45;49;89;54;89;96;66];%X coordinate of vertex
Vertex_Y=[38;40;55;69;66;41;38;40;0;16;38;16;19;41;86;69;55;44;86;44;40;100];%Y coordinate of vertex
for i=1:(length(Vertex_X)-1)
X1(i)=Vertex_X(i+1);
Y1(i)=Vertex_Y(i+1);
X2(i)=Vertex_X(i+1);
Y2(i)=Vertex_Y(i+1);
end
A=[X1 X2];
B=[Y1 Y2];
plot(A.',B.','LineWidth', 0.75)

Tchilabalo on 18 Sep 2020
Thanks Vasishta for your response. I have tried the code, but the result doesn't quite match the initial polygon.
Vasishta Bhargava on 18 Sep 2020
See figures attached.
One is without fill option, using plot function
other with fill option using patch
You have to specify the color options according to your choice.
I used rand() to generate colors with colorbar