An Algorithm for Grid Generation