# Moving a vertex along an edge

I need to move a vertex along an edge. I want to make a vector of 2 vertices and move the vertex along this vector using Python.

In this example, I show that I want to move the vertex with index 13 to the dot edge.

• I'm not sure to understand what you need: is it about accessing the vertex data? Or a formula to translate/move along an edge? – lemon May 7 '17 at 15:48
• A formula to translate/move along an edge. – Влад Киндюшов May 7 '17 at 15:53

Here is a step by step calculation using vectors:

import bpy

obj = bpy.context.object

edge = obj.data.edges[0] #An edge, the first one

vIndex1 = edge.vertices[0] #Get the indices of the vertices of this edge
vIndex2 = edge.vertices[1]

v1 = obj.data.vertices[vIndex1] #Get the corresponding vertices
v2 = obj.data.vertices[vIndex2]

vCoord1 = v1.co #Get their coordinates
vCoord2 = v2.co

edgeVector = vCoord2 - vCoord1 #The vector formed by these two vertices

edgeVector.normalize() #So that it has 1 unit length

distance = 0.5 #Say we want to move v2 of this distance of 0.5 units

v2.co += edgeVector * distance #Translate the vertex


You can summarize by:

v2.co += (v2.co - v1.co).normalized() * distance #Translate the vertex

• Many thanks. I did almost the same thing, but without .normalize (). Now I know why it .normalize () – Влад Киндюшов May 7 '17 at 16:33