I have an arbitrary edge that I would like to move so that it is in line with an arbitrary empty (in this case it will cross over the empty):

enter image description here

I assume that I will need to perhaps find the translation matrix of the 'line' representing the shortest distance between the edge and the empty but how would I do that using script?

  • $\begingroup$ do you want to do this programmatically or are ways through the interface ok? also are you intending to do this in object mode or edit mode? $\endgroup$
    – David
    Jun 29 '15 at 15:27
  • $\begingroup$ I need to do this programmatically. Probably in edit mode but for purposes of understanding the translation I don't think it would make too much difference :) --- I'm approaching a solution to the following question but need this translation to test it: blender.stackexchange.com/questions/32190/… $\endgroup$
    – Eben Roux
    Jun 30 '15 at 3:56

I think I may have sorted this now using Vector.project. For the script to work one would need to create a 2 vertex edge and call it line as well as adding an empty that is renamed empty (not Empty):

import bpy
from mathutils import Matrix

empty = bpy.data.objects["empty"]
line = bpy.data.objects["line"]

mw = line.matrix_world
ev = empty.location

# get the two line points in world space
lv0 = mw * line.data.vertices[0].co
lv1 = mw * line.data.vertices[1].co

# get the vector of the line
lv = (lv0 - lv1)

# get the translation between the original line and the line vector
# and apply that to the empty location to get the location of the 
# empty relative to the line vector
evt = Matrix.Translation(lv - lv0) * ev

# get the projection of the new empty location onto the line vector
# - `project` gets the perpendicular vector where `evt` intersects `lv`
evp = evt.project(lv)

# get the translation between the projected vector and the empty
tm = Matrix.Translation(evp - evt).inverted()

# now move the line
line.location = tm * line.location

I have created a simple add-on on GitHub to demonstrate the behaviour.


I disagree. Select the edge you want in edit mode, press Ctrl+H> Hook to a New Object and it will create an empty and use its position for the edge.

Edit: Noted the purpose was something different. I'm still not sure you need to do this as a script. Take a look at the curve deformer.


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.