A fast converging and anti-aliasing algorithm for Green's functions in terms of spherical or cylindrical harmonics