# Align vertices into a straight line

I moved one vertex in but now I have a kink in my surface.

Is there a clever way to move the second edge so the kink disappears?

A script.

Thought this would be a good little exercise in edit mode bmesh scripting.

• Select two edges that share a middle vert.
• Move middle vert the least distance such that it is on the line defined by the other two.
import bpy
import bmesh
from bmesh.types import BMEdge
from mathutils.geometry import intersect_point_line
ob = bpy.context.edit_object
me = ob.data
bm = bmesh.from_edit_mesh(me)

edges = bm.select_history[-2:]
verts = set(v for e in edges for v in e.verts)

# ensure the last two selections are both edges that share a vert
assert (
len(verts) == 3
and len(edges) == 2
and all(isinstance(e, BMEdge) for e in edges)
)
# All Ok, the edges
e1, e2 = edges
# The middle vert
v =  set(e1.verts).intersection(e2.verts).pop()
# helper method to find closest point on line segment to a given point.
co, d = intersect_point_line(
v.co,
e1.other_vert(v).co,
e2.other_vert(v).co
)
v.co = co

bmesh.update_edit_mesh(me)


other options would be to move middle vert to center (or other defined ratio) of other two, keep the ratio of lengths constant.

• Thanks, didn't even think about a script :) That makes that may faster and less tides. Feb 7, 2021 at 8:45
• could you explain your code a bit? I get everything until verts = set(v for e in edges for v in e.verts) then don't know what it does. Feb 7, 2021 at 11:32
• OY! What's this minus 15 business? :D (Don't worry, @Phönix64, just kidding the scriptmeister...) Feb 7, 2021 at 11:58

To straighten vertices to a line:

• Set pivot to 'Active Element'

• Select the 2 vertices at the ends, and create a Custom Transform Orientation from them. (The little '+' in the header's Transform Orientation dropdown)

• With all 3 vertices selected, and one of the ends selected last, so active, and the new transform orientation active, hit S Shift Y 0, scaling to 0 in all dimensions, except 'Y', the one along the line between the end vertices.

• Okay, thanks. It worked Feb 6, 2021 at 11:34
• @susu Thanks.. I'll have to watch myself... I must be getting lazy :) Feb 6, 2021 at 20:43