def _convert_from_barycentric(barycentric_coords, simplex, coordinates):
    """ Converts barycentric coordinates for a given the simplex to Cartesian coordinates.

    Given barycentric coordinates, a list of coordinates and a simplex (triangle or line
    segment), return the actual coordinates in R^3 corresponding to the barycentric
    coordinates.

    This method will not work when finding the corresponding coordinates in R^2. We will be
    trying to access the z-component, which will cause an index error. If this method is
    needed in such a case, assign 0 as the third coordinate.

    Parameters
    ----------
    barycentric_coords : list of floats, length 2 or 3
        The barycentric coordinates of a point in the triangle or line segment.
    simplex: list of ints, length 2 or 3
        The indices corresponding to vertices making up the triangle or line segment.
    coordinates: list of triples of floats
        Coordinate system in which the vertices exist in. If they are flattened
        coordinates, the third element should be 0.

    Returns
    -------
    list of floats, length 3
        Converted coordinates of the point defined by the barycentric coordinates and the
        given simplex.
    """

    if len(coordinates[0]) != 3:
        raise Exception("_convert_from_barycentric: Invalid coordinate dimensions. " \
                        "This method requires the coordinates to be in 3D.")

    #initialise return value
    result = []

    #if the simplex is a triangle, get the values of the corresponding
    #coordinates in R^3 componentwise
    if len(barycentric_coords) == len(simplex) == 3:
        x_val = barycentric_coords[0] * coordinates[simplex[0]][0] + \
            barycentric_coords[1] * coordinates[simplex[1]][0] + \
            barycentric_coords[2] * coordinates[simplex[2]][0]
        y_val = barycentric_coords[0] * coordinates[simplex[0]][1] + \
            barycentric_coords[1] * coordinates[simplex[1]][1] + \
            barycentric_coords[2] * coordinates[simplex[2]][1]
        z_val = barycentric_coords[0] * coordinates[simplex[0]][2] + \
            barycentric_coords[1] * coordinates[simplex[1]][2] + \
            barycentric_coords[2] * coordinates[simplex[2]][2]
        result = [x_val, y_val, z_val]

    #if the simplex is a line segment, get the values of the corresponding
    #coordinates using the equation of a line
    elif len(barycentric_coords) == len(simplex) == 2:
        #extract the two coordinates of the line segment and just one of the
        #barycentric coordinate weights (the gradient of the line)
        (x_0, y_0, z_0) = coordinates[simplex[0]]
        (x_1, y_1, z_1) = coordinates[simplex[1]]
        lambda_1 = barycentric_coords[1]

        x_val = x_0 + lambda_1 * (x_1 - x_0)
        y_val = y_0 + lambda_1 * (y_1 - y_0)
        z_val = z_0 + lambda_1 * (z_1 - z_0)
        result = [x_val, y_val, z_val]

    else:
        raise Exception("_convert_from_barycentric: Invalid dimensions for barycentric " \
                        "coordinates and/or simplex. They must both be of either length " \
                        "2 or 3, since the method is only defined for triangles and edges.")
    return result