2 Small example script showing how to create and manage polygons
3 (script works in python 2 and 3)
6 from __future__
import print_function
14 def output_polygon_part(level, part):
15 print(
"level", level,
"part: ", end=
"")
16 if part.positveFace() ==
True:
17 print(
" positive face", end=
"")
19 print(
" negative face", end=
"")
20 if part.isDegenerated() ==
True:
21 print(
", degenerated")
25 for p
in part.points():
26 if sys.float_info.max == p.z:
27 print(
"\t(%.3f," % p.x,
" %.3f," % p.y,
"---)")
29 print(
"\t(%.3f," % p.x,
" %.3f," % p.y,
"%.3f)" % p.z)
31 if part.sizePart() > 0:
32 print(
"part has ", part.sizePart(),
"sub parts")
33 for part
in part.parts():
34 output_polygon_part(level + 1, part)
39 def output_polygon(poly, titel):
41 for part
in poly.parts():
42 output_polygon_part(0, part)
46 f = pyDM.PolygonFactory()
54 pSimple = f.getPolygon(pyDM.Orientation.ccw)
56 output_polygon(pSimple,
"simple positiv polygon --------------------------------")
69 pHole = f.getPolygon(pyDM.Orientation.ccw)
71 output_polygon(pHole,
"polygon with hole -------------------------------------")
81 pSimple2 = f.getPolygon(pyDM.Orientation.ccw)
83 pDiff = pyDM.GeometricOperations.difference(pSimple, pSimple2)
85 output_polygon(pDiff,
"polygon created by difference operation ---------------")
93 pSimple3 = f.getPolygon(pyDM.Orientation.ccw)
95 pJoin = pyDM.GeometricOperations.join(pDiff, pSimple3)
97 output_polygon(pJoin,
"polygon created by join operation ---------------------")