# 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?

## 2 Answers

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. – Phönix 64 Feb 7 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. – Phönix 64 Feb 7 at 11:32
• OY! What's this minus 15 business? :D (Don't worry, @Phönix64, just kidding the scriptmeister...) – Robin Betts Feb 7 at 11:58

To straighten vertices to a line:

• Okay, thanks. It worked – Phönix 64 Feb 6 at 11:34
• @susu Thanks.. I'll have to watch myself... I must be getting lazy :) – Robin Betts Feb 6 at 20:43