def baryocentric_coords(pts,pt):
    """See e.g.: http://en.wikipedia.org/wiki/Barycentric_coordinate_system_%28mathematics%29"""
    
    xs,ys=list(zip(*pts))
    x,y=pt
    
    det=(ys[1]-ys[2])*(xs[0]-xs[2])+(xs[2]-xs[1])*(ys[0]-ys[2])
    l1=((ys[1]-ys[2])*(x-xs[2])+(xs[2]-xs[1])*(y-ys[2]))/float(det)
    l2=((ys[2]-ys[0])*(x-xs[2])+(xs[0]-xs[2])*(y-ys[2]))/float(det)
    
    return l1, l2, 1-l1-l2