def centroid_of_points(pts):
    """Returns the centroid of a cluster of points. Automatically
    works with either 2D or 3D point tuples."""
    xs, ys, zs = 0, 0, 0
    for pt in pts:
        xs += pt[0]
        ys += pt[1]
        if len(pt) > 2:
            zs += pt[2]
    if len(pts) > 0:
        xs /= len(pts)
        ys /= len(pts)
        if len(pts[0]) > 2:
            zs /= len(pts)
            return xs, ys, zs
    return xs, ys