1
$\begingroup$

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.

enter image description here

$\endgroup$
2
  • $\begingroup$ 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? $\endgroup$
    – lemon
    Commented May 7, 2017 at 15:48
  • $\begingroup$ A formula to translate/move along an edge. $\endgroup$ Commented May 7, 2017 at 15:53

1 Answer 1

4
$\begingroup$

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
$\endgroup$
1
  • 1
    $\begingroup$ Many thanks. I did almost the same thing, but without .normalize (). Now I know why it .normalize () $\endgroup$ Commented May 7, 2017 at 16:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .