# What's the fastest way to calculate the midpoints of a sequence of edges?

by andyV   Last Updated July 11, 2018 06:15 AM

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[0].co), (ob.matrix_world * e.verts[1].co)
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?

Tags :

Some improvements.

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[0].co + e.verts[1].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[0].co + e.verts[1].co) / 2
``````
batFINGER
July 11, 2018 06:14 AM