Plane and space polyline expansion algorithm