11
$\begingroup$

How to interpolate vector between 2 vectors in blender-python? I hope you get my question. Example:

enter image description here

$\endgroup$
15
$\begingroup$

See mathutils.Vector:

  1. Vector.lerp for linear interpolation.

  2. Vector.slerp for spherical interpolation. https://en.wikipedia.org/wiki/Slerp


c = a.lerp(b, 0.0)
# c == a
c = a.lerp(b, 0.5)
# c == (a + b) / 2
c = a.lerp(b, 1.0)
# c == b
$\endgroup$
  • $\begingroup$ i think you mean C == B in your third example $\endgroup$ – StarWeaver Dec 5 '14 at 23:38
7
$\begingroup$
from mathutils import Vector

v = Vector((0,1,2))
v.negate()
print(v)
# <Vector (-0.0000, -1.0000, -2.0000)>

def interpolate(t, vector_a, vector_b):
# t is from interval <0, 1>
    return (1 - t) * vector_a + t * vector_b
$\endgroup$

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.