# What is the easiest way to draw polygon given only vertices coordinates ?

조회 수: 85(최근 30일)
답변: Steven Lord 5 Jun 2018
What is the easiest way to plot polygon given only vertices coordinates?

댓글을 달려면 로그인하십시오.

### 답변(2개)

Star Strider 5 Jun 2018
One approach:
vertices = randi(9, 10, 2); % Create Vertices Matrix [x(:) y(:)]
verticesc = vertices - mean(vertices,1); % Center Vertices
[~,sortidx] = sortrows(atan2(verticesc(:,2), verticesc(:,1)),1); % Sort
sortidx = [sortidx; sortidx(1)]; % Close Polygon
figure(1)
plot(vertices(sortidx,1), vertices(sortidx,2), '-pr')
axis equal
The ‘vertices’ matrix has the x coordinate in the first column, and the y coordinate in the second column.

#### 댓글 수: 0

댓글을 달려면 로그인하십시오.

Steven Lord 5 Jun 2018
I see that this has the tag "3d plots" but you refer to "polygon". If in fact you're referring to the standard definition of polygon as "a plane figure that is bounded by a finite chain of straight line segments closing in a loop" use your coordinates to build a polyshape object and call plot on that polyshape.
If instead you want a "3d plot", also known as a polyhedron, that's different.

댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

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

Start Hunting!

Translated by