13
$\begingroup$

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

enter image description here

$\endgroup$
0

2 Answers 2

19
$\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$
1
  • $\begingroup$ i think you mean C == B in your third example $\endgroup$
    – Weaver
    Dec 5, 2014 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$

You must log in to answer this question.

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