This is a very basic question and it should have been very well studied. CGAL has provided open source code to do this and you can also find related reference therein. Your basic question is point clouds reconstruction problem. It has been very well studied for a long time but still is a good ongoing research topic.