home
Interpolating a bezier curve

It is difficult to implement an interpolation of a bezier curve without seeing how it actually works. It requires too much attention to understand what is really happenning there. It is also difficult to find a clean implementation if you google that. You will most likely find an obfuscated version of a written clean code. So I am sharing a whole food with you.

def lerp(t, a, b):
  dx = b["x"] - a["x"]
  dy = b["y"] - a["y"]
  dz = b["z"] - a["z"]
  return {
    "x": a["x"] + t * dx,
    "y": a["y"] + t * dy,
    "z": a["z"] + t * dz
  }
 
def bezier(t, p0, p1, p2, p3):
  a = lerp(t, p0, p1)
  b = lerp(t, p1, p2)
  c = lerp(t, p2, p3)
  d = lerp(t, a, b)
  e = lerp(t, b, c)
  f = lerp(t, d, e)
  return f

Good luck playing with this.