# arrange points (representing a boundary of an enclosed area) to clockwise/anti-clockwise sequence

8 visualizzazioni (ultimi 30 giorni)
Quan il 15 Gen 2015
Risposto: Image Analyst il 15 Gen 2015
Hi! I have an array of points constituting the boundary of an enclosed area. The sequence of the points are messed up during the processing. How can I arrange these points in a nice order so that they run in an anti-clockwise/clockwise manner? Is there a function to do this? Thanks in advance.
The area is concave and the points are next to each other.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (1)

Image Analyst il 15 Gen 2015
Find the center by taking the average of the x and y coordinates
xCenter = mean(x);
yCenter = mean(y);
then calculate the angles from the center
angles = atand2d((y-yCenter) ./ (x-xCenter));
Then sort
[sortedAngles, sortIndexes] = sort(angles);
x = x(sortedIndexes); % Reorder x and y with the new sort order.
y = y(sortedIndexes);
This is untested, just off the top of my head, so you may have to tweak it a bit. Let me know how it works.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Grid Lines, Tick Values, and Labels in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!