A novel approach for the computation of Legendre polynomial expansions