Formatting and writing data
You could try to replace some loops with string formatting, for example change this

for i in pol.vertices[:3]:
    out.write(str(i)+' ')
for i in pol.vertices[2:]:
    out.write(str(i)+' ')
out.write(str(pol.vertices[0])+' ')  


to this

out.write('{0} {1} {2} {2} {3} {0} '.format(*pol.vertices))