 # Order Vertex neighbors

#1

Can anyone suggest an algorithm to ‘order’ vertex neighbors (direct connected indexes)? Or a way to collect neighbors in order?
the order is a list where every next index in the list connected to the previous (if it’s possible). Let’s do it for Mesh where we have only triangle faces.

#2

here is something very simple without any optimization… it’s more like a pseudo - code:

``````vv =
(
m = \$.mesh
num = m.numverts
vv = for k=1 to num collect #()
for k=1 to m.numfaces do
(
_vv = getface m k
append vv[_vv] #(int _vv, int _vv)
append vv[_vv] #(int _vv, int _vv)
append vv[_vv] #(int _vv, int _vv)
)

for k=1 to num do
(
do
(
for n=2 to vv[k].count do
(
if vv[k] == vv[k][n] do
(
insertitem vv[k][n] vv[k] 1
vv[k][n] = #()
)
if vv[k] == vv[k][n] do
(
insertitem vv[k][n] vv[k] 1
vv[k][n] = #()
)
if vv[k][vv[k].count] == vv[k][n] do
(
append vv[k] vv[k][n]
vv[k][n] = #()
)
if vv[k][vv[k].count] == vv[k][n] do
(
append vv[k] vv[k][n]
vv[k][n] = #()
)
)
if add > 0 do vv[k] = for p in vv[k] where p.count > 0 collect
(
if (p == p[p.count]) do deleteitem p p.count
p
)
)

for n=2 to vv[k].count do join vv[k] vv[k][n]
vv[k] = vv[k]
)
vv
)
``````

any ideas about smarter algorithm or/and optimization are welcome #3

what’s in “order” ? i.e. what constitutes the first neighbour ? and the next ? and so on

#4

the first ‘neighbour’ in the list doesn’t matter. I only need all other be connected to the previous if it’s possible. also direction of the order doesn’t matter as well.

when i say ‘ordered’ i mean list of neighbours in adjacent order.

#5