Featured post

new redirect for blender.org bpy docs.

http://www.blender.org/api/blender_python_api_current/ As of 10/11 november 2015 we can now link to the current api docs and not be worr...

May 14, 2011

Blender 2.5 Python Find Connected Vertices

given a list of edges, how do you find what vertices are connected to a given vertex?
Edges = [   
                [0,1],[1,2],[2,3],[3,0],
                [4,5],[5,6],[6,7],[7,4],
                [0,4],[1,5],[2,6],[3,7]
            ]
numbered_vertex = 1   # where 1 is an arbitrary choice of vertex
for i in Edges:
    if numbered_vertex in i:
        print(i)

or this way..a little bit more confusing at first.. but ultimately not too unwieldy.
Edges = [   
                [0,1],[1,2],[2,3],[3,0],
                [4,5],[5,6],[6,7],[7,4],
                [0,4],[1,5],[2,6],[3,7]
            ]
n = 1   # where 1 is an arbitrary choice of vertex
print([x for x in Edges if x[0] == n or x[1] == n])
# or 
print([x for x in Edges if n in x])

No comments:

Post a Comment

Please use Blender.StackExchange.com for python scripting questions unrelated to this post.