def grid3d(width, xScale=1.0, yScale=1.0, zScale=1.0, x0=0.0, y0=0.0, z0=0.0):
    """Returns a 3D grid between (0, 0, 0) and (1, 1, 1)
    :param width: The number of rows/columns the grid has
    :type width: int
    :param xScale: Scales the grid along the x axis
    :type xScale: float
    :param yScale: Scales the grid along the y axis
    :type yScale: float
    :param zScale: Scales the grid along the z axis
    :type zScale: float
    :param x0: Translates the grid along the x axis
    :type xScale: float
    :param y0: Translates the grid along the y axis
    :type yScale: float
    :param z0: Translates the grid along the z axis
    :type zScale: float
    :return: A callable grid that returns 3d positions when given an index"""
    xScale /= width
    yScale /= width
    zScale /= width
    g = lambda i: (x0 + xScale * (i % width), y0 + yScale * (i % (width *
        width) / width), z0 + zScale * (i / (width * width)))
    g.type = 'grid3d'
    g.width = width
    g.xScale = xScale
    g.yScale = yScale
    g.zScale = zScale
    g.x0 = x0
    g.y0 = y0
    g.z0 = z0
    g.inverse = lambda x, y, z: int(round(x / xScale - x0)) + width * int(
        round(y / yScale - y0) + width * int(round(z / zScale - z0)))
    return g
