Generating polygons from spaghetti