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$
  • $\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 May 7 '17 at 15:48
  • $\begingroup$ A formula to translate/move along an edge. $\endgroup$ – Влад Киндюшов May 7 '17 at 15:53
3
$\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
| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ Many thanks. I did almost the same thing, but without .normalize (). Now I know why it .normalize () $\endgroup$ – Влад Киндюшов May 7 '17 at 16:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.