I'm trying to create a list that calculates the midpoints of a sequence of edges.
Right now I'm doing it like this:
eList =  for e in [e for e in bm.edges if e.select]: pt_1, pt_2 = (ob.matrix_world * e.verts.co), (ob.matrix_world * e.verts.co) addPt = pt_1 + pt_2 co = mathutils.Vector((addPt/2,addPt/2,addPt/2 )) eList.append((e, co))
I multiply each vert in the edge by the object's world matrix, then add the verts together. I divide each axis in the vert by 2 and covert them to a vector and then put the edge and the vector in a tuple and append that to a list.
It's probably not a very efficient process but I'm still pretty new to python and can't think of a faster way.
Is this something that could be done faster in numpy?
What would be the fastest way to perform this function over a large sequence of edges?
Use list comprehension Only need to multiply the local average edge coord by matrix world once. Multiply / divide a vector by a scalar, rather than on a per component basis.
import bpy import bmesh ob = bpy.context.edit_object me = ob.data bm = bmesh.from_edit_mesh(me) mw = ob.matrix_world elist = [(e, mw * (e.verts.co + e.verts.co) / 2) for e in bm.edges if e.select]
could make a little helper routine. Will have a default of local avge if not passed a matrix.
def mid_edge(e, matrix = mathutils.Matrix()): return matrix * (e.verts.co + e.verts.co) / 2