def triangular_membership(bin_center, bin_width, smoothness = 0.5):
    r"""
    Create a triangular membership function for a fuzzy histogram bin.
    
    Parameters
    ----------
    bin_center : number
        The center of the bin of which to compute the membership function.
    bin_width : number
        The width of a single bin (all expected to be of equal width).
    smoothness : number, optional
        The smoothness of the function; determines the neighbourhood affected.
        See below and `fuzzy_histogram` for a more detailed explanation
    
    Returns
    -------
    triangular_membership : function
        A triangular membership function centered on the bin.
    
    Notes
    -----
    For the triangular function the smoothness factor has to be 0.5. Lower values
    are accepted, but then the function assumes the shape of the trapezium membership
    function. Higher values lead to an exception.
    
    The triangular membership function is defined as

    .. math::
        
        \mu_{\triangle}(x) =
          \left\{
            \begin{array}{ll}
              0, & x<a, x>c\\
              \frac{x-a}{b-a}, & a\leq x\leq b \\
              \frac{c-x}{c-b}, & b<x\leq c\\
            \end{array}
          \right.

    where :math:`a` is the left border, :math:`c` the right border and :math:`b` the center of the triangular
    function. The height of the triangle is chosen such, that all values contribute with
    exactly one.
    
    The standard triangular function (:math:`smoothness = 0.5`) is displayed in the following
    figure
    
    .. .. image:: images/triangular_01.png
    
    "Triangular functions (1)"
    
    where the bin width is :math:`2` with centers at :math:`-2`, :math:`0` and :math:`2`.
    """
    if smoothness > 0.5: raise AttributeError('the triangular/trapezium membership functions supports only smoothnesses between 1/10 and 1/2.')
    if smoothness < 0.5: return trapezoid_membership(bin_center, bin_width, smoothness)
    
    a = bin_center - bin_width
    b = float(bin_center)
    c = bin_center + bin_width
    
    def fun(x):
        if x < a or x > c: return 0
        elif x <= b: return (x-a)/(b-a)
        else: return (c-x)/(c-b)
    return fun