In [1]:
%matplotlib inline
from matplotlib import pyplot as plt
In [2]:
class Bezier():

    def __init__(self, vertices):
        self.vertices = vertices
        
    def interpolate(self, t):
        new_vert = []
        vertices = self.vertices
        for axis in range(len(vertices[0])):
            coord, alpha, beta, coeff = 0, len(vertices) - 1, 0, 1
            for vertex in vertices:
                if alpha < len(vertices) - 1:
                    coeff = (alpha + 1)*coeff/beta
                coord += vertex[axis]*((1 - t)**alpha)*(t**beta)*coeff
                alpha -= 1
                beta += 1
            new_vert.append(coord)
        return new_vert
        
    def draw(self, res):
        output = []
        for i in range(res):
            t = i/(res - 1)        
            output.append(self.interpolate(t))
        return output       
In [3]:
b = Bezier([[0, 0], [2.0, 0.0], [-1.0, 3], [2, 2]])
plt.scatter([x for x,_ in b.draw(20)], [y for _,y in b.draw(20)])
Out[3]:
<matplotlib.collections.PathCollection at 0x4af3be0>
In [4]:
b.interpolate(0.25)
Out[4]:
[0.734375, 0.453125]