def N(u,i,p,knots):
    """
    u: point for which a spline should be evaluated
    i: spline knot
    p: spline order
    knots: all knots

    Evaluates the spline basis of order p defined by knots
    at knot i and point u.
    """
    if p == 0:
        if knots[int(i)] < u and u <=knots[int(i+1)]:
            return 1.0
        else:
            return 0.0
    else:
        try:
            k = ((float((u-knots[int(i)])) / float((knots[int(i+p)] - knots[int(i)]) ))
                    * N(u,i,p-1,knots))
        except ZeroDivisionError:
            k = 0.0
        try:
            q = ((float((knots[int(i+p+1)] - u)) / float((knots[int(i+p+1)] - knots[int(i+1)])))
                    * N(u,i+1,p-1,knots))
        except ZeroDivisionError:
            q  = 0.0
        return float(k + q)