Ich habe folgendes Problem:
Ich habe eine liste branches mit tuple positione drin.
Das sieht dann in etwa so aus
(0, 0, 0)
(0, 0, 1)
(0, 0, 2)
(0.03521536584636689, 0.047416708336478305, 6.442265053460119) usw.
Wenn ich dann den folgenden Code ausführen möchte:
Code: Alles auswählen
verts = {b.pos:i for i,b in enumerate(branches)}
# create vertex pairs as edge by locating vert index based on coordinates
edges = [ (verts[b.pos],verts[branches[b.parent].pos])for b in branches if b.parent is not None]
# replace vertex mapping by simple list of coordinates
verts = [b.pos for b in branches]
Jedoch funktioniert der Folgende Code:
Code: Alles auswählen
class Branch:
def __init__(self,pos,parent=None):
self.pos = pos
self.parent = parent
branches = []
branches.append(Branch((0,0,0),None))
branches.append(Branch((0,0,1),0))
branches.append(Branch((1,0,2),1))
branches.append(Branch((-1,0,2),1))
# create a mapping from vertex position to vertex index
verts = {b.pos:i for i,b in enumerate(branches)}
# create vertex pairs as edge by locating vert index based on coordinates
edges = [ (verts[b.pos],verts[branches[b.parent].pos])for b in branches if b.parent is not None]
# replace vertex mapping by simple list of coordinates
verts = [b.pos for b in branches]