def get_centroids(vertices, entities, dim=2):
    """Calculate the centroids of all the entities.

    :param vertex: vertex coordinates of mesh
    :type vertex: numpy.ndarray[float64 x dim]
    :param entities: mesh connectivity
    :type entities: numpy.ndarray[int x (dim+1)]
    :param dim: dimension of mesh
    :type dim: int, optional

    :return: centroids of entities
    :rtype: numpy.ndarray[float64 x dim]
    """
    return vertices[entities].sum(1) / (dim + 1)