import torch


def Compute_structures_surface(V,F):
    """
    For the linear normal kernel
    
    Parameters
    ----------
    @param : V : torch tensor
                 n-points x d-dimension points.
    @param : F : torch Long tensor
                 m-connections x 2-dim tensor containing pair of connected points' indices.

    Returns
    -------
    @output : centers        : torch tensor
                               npoints-1 x d-dimension points, the centers of each face.
    @output : length         : float
                               npoints-1 x 1-dimension tensor, the areas of each face.
    @output : normals        : torch tensor
                               npoints-1 x d-dimension normalized vectors of normals of each face. 
    """

    V0, V1, V2 = V.index_select(0, F[:, 0]), V.index_select(0, F[:, 1]), V.index_select(0, F[:, 2])   
    centers, normals =  (V0 + V1 + V2) / 3, .5 * torch.cross(V1 - V0, V2 - V0)    
    length = (normals ** 2).sum(dim=1)[:, None].sqrt()
    
    return centers, length, normals/(length+1e-5)