How to order vertices of a flat convex polygon in 3d space along the edge?

6 Ansichten (letzte 30 Tage)
I have a list of xyz-coordinates which build a flat polygon and i need to order them clockwise or counterclockwise. Its not important which direction it is though. I tried to use the atan2() function by calculating rays from the center of the polygon but it fails if the polygon is close to vertical. I would like to implement an approach which works without exceptions. Here is an example of 5 points.
-2.6055 1.1850 0.0880
-2.6320 1.1700 -0.0593
-2.3126 1.2170 -0.4326
-2.1860 1.2672 0.3596
-1.6203 1.4446 -0.0687
Thank you in advance!
  2 Kommentare
Jan von Kölln
Jan von Kölln am 11 Nov. 2018
I found a way to give me a list of which lines build the vertices. So my goal is to isolate the different Points. How can i do that?
233 291
291 387
388 387
388 471
233 471
I need to keep the order and isolate the nodes. In this case, it should be: 291, 387, 388, 471, 233
Bruno Luong
Bruno Luong am 12 Nov. 2018
Bearbeitet: Bruno Luong am 12 Nov. 2018
E = [...
233 291;
100 233;
291 387;
388 387;
388 471;
100 471 ]
n = size(E,1);
[u,~,L] = unique(E);
[~,is] = sort(L);
is(is) = flip(reshape(is+n*(2*(is <= n)-1),2,[]));
i = 1+n;
I = zeros(n,1);
for j=1:n
I(j) = i;
i = is(i);
end
V = u(L(I));
disp(V)

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Bruno Luong
Bruno Luong am 11 Nov. 2018
Bearbeitet: Bruno Luong am 11 Nov. 2018
xyz =[...
-2.6055 1.1850 0.0880;
-2.6320 1.1700 -0.0593;
-2.3126 1.2170 -0.4326;
-2.1860 1.2672 0.3596;
-1.6203 1.4446 -0.0687 ];
xyzc = mean(xyz,1);
P = xyz - xyzc;
[~,~,V] = svd(P,0);
[~,is] = sort(atan2(P*V(:,1),P*V(:,2)));
xyz = xyz(is([1:end 1]),:);
close all
plot3(xyz(:,1),xyz(:,2),xyz(:,3))
  1 Kommentar
Jan von Kölln
Jan von Kölln am 11 Nov. 2018
That works, thanks! If you know how to deal with my comment about the lines i would highly appreciate to get the answer. And thank you for your time!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Computational Geometry finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by