필터 지우기
필터 지우기

Rearranging an array of vertices of a geometry to compute the perimeter

조회 수: 2 (최근 30일)
Please, find the attached picture. I have the following x and y coordinates of a geometry which are the vertices of a geometry but they are not orderly arranged (1). I need the vertices to be arranged following a counterclockwise direction in order to be able to estimate the perimeter correctly (2). Please, how can I achieve this with matlab code? Thank you so much.
(1) unordered vertices
x y
0 1
0.5 0
0 0.5
0.5 0.8
0.5 0.5
0.3 1
0.5 0.2
0.5 1
0 0
0.4 0
0.1 1
0.1 0
0 0.8
0 0
(2) ordered vertices in counterclockwise direction
x y
0 0
0.1 0
0.4 0
0.5 0
0.5 0.2
0.5 0.5
0.5 0.8
0.5 1
0.3 1
0.1 1
0 1
0 0.8
0 0.5
0 0

채택된 답변

Image Analyst
Image Analyst 2018년 9월 23일
Use mean() to get the middle of the set of points. Then use atan2d() to get the angle from the center to each of the points. Then use sort(). It's really super easy. Try it and write back if you can't figure it out. Here's a start:
xCenter = mean(x);
yCenter = mean(y);
angles = atan2d(y - yCenter, x - xCenter);
[sortedAngles, sortOrder] = sort(angles);
x = x(sortOrder);
y = y(sortOrder);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Computational Geometry에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by