Version: 9.16.0
GEOM_TestMeasures.py


GEOM_TestMeasures.py

0def TestMeasureOperations (geompy, math):
26
27 p0 = geompy.MakeVertex(0 , 0, 0)
28 p137 = geompy.MakeVertex(10, 30, 70)
29
30 box = geompy.MakeBoxTwoPnt(p0, p137)
31
32 p678 = geompy.MakeVertex(60, 70, 80)
33 p789 = geompy.MakeVertex(70, 80, 90)
34
35 vz = geompy.MakeVectorDXDYDZ(0, 0, 1)
36
37 cube = geompy.MakeBoxTwoPnt(p678, p789)
38
39 cylinder = geompy.MakeCylinder(p0, vz, 5, 70)
40
41

42
43 Coords = geompy.PointCoordinates(p137)
44 if Coords[0] != 10 or Coords[1] != 30 or Coords[2] != 70:
45 print("Coordinates of p137 must be (10, 30, 70), but returned (", Coords[0], ", ", Coords[1], ", ", Coords[2], ")")
46
47

48
49 (IsValid, err) = geompy.CheckShape(box, 0, 2)
50 if IsValid == 0:
51 geompy.PrintShapeError(box, err)
52 raise RuntimeError("Invalid box created")
53 else:
54 print("\nBox is valid")
55
56

57
58 selfIntersected = geompy.MakeCompound([box, cylinder])
59 if geompy.CheckSelfIntersections(selfIntersected):
60 raise RuntimeError("Existing self-intersection is not detected")
61
62

63
64 if salome_version.getXVersion() > "0x70600":
65 if geompy.CheckSelfIntersectionsFast(selfIntersected):
66 raise RuntimeError("Existing self-intersection is not detected")
67
68

69
70 if not geompy.FastIntersect(box, cylinder)[0]:
71 raise RuntimeError("Existing intersection is not detected")
72
73

74
75 Descr = geompy.WhatIs(box)
76 print("\nBox 10x30x70 description:")
77 print(Descr)
78
79
80
81 NbSolids = geompy.NbShapes(box, geompy.ShapeType["SOLID"])
82 print("\nBox 10x30x70 quantity of solids:", NbSolids)
83
84
85
86 BoxInfo = geompy.ShapeInfo(box)
87 print("\nBox 10x30x70 shapes:")
88 print(BoxInfo)
89
90

91
92 Props = geompy.BasicProperties(box)
93 print("\nBox 10x30x70 Basic Properties:")
94 print(" Wires length: ", Props[0])
95 print(" Surface area: ", Props[1])
96 print(" Volume : ", Props[2])
97
98 dl = math.sqrt((Props[0] - 880)*(Props[0] - 880))
99 da = math.sqrt((Props[1] - 6200)*(Props[1] - 6200))
100 dv = math.sqrt((Props[2] - 21000)*(Props[2] - 21000))
101 #print "|Props[0] - 880| = ", dl
102
103 if dl > 1e-7 or da > 1e-7 or dv > 1e-7:
104 print("While must be:")
105 print(" Wires length: ", 880)
106 print(" Surface area: ", 6200)
107 print(" Volume : ", 21000)
108
109

110
111 BB = geompy.BoundingBox(box)
112 print("\nBounding Box of box 10x30x70:")
113 print(" Xmin = ", BB[0], ", Xmax = ", BB[1])
114 print(" Ymin = ", BB[2], ", Ymax = ", BB[3])
115 print(" Zmin = ", BB[4], ", Zmax = ", BB[5])
116 BB = geompy.MakeBoundingBox(box)
117 geompy.addToStudy(BB, "BoundingBox")
118
119

120
121 In = geompy.Inertia(box)
122 print("\nInertia matrix of box 10x30x70:")
123 print(" (", In[0], ", ", In[1], ", ", In[2], ")")
124 print(" (", In[3], ", ", In[4], ", ", In[5], ")")
125 print(" (", In[6], ", ", In[7], ", ", In[8], ")")
126 print("Main moments of inertia of box 10x30x70:")
127 print(" Ix = ", In[9], ", Iy = ", In[10], ", Iz = ", In[11])
128
129

130
131 Toler = geompy.Tolerance(box)
132 print("\nBox 10x30x70 tolerance:")
133 print(" Face min. tolerance: ", Toler[0])
134 print(" Face max. tolerance: ", Toler[1])
135 print(" Edge min. tolerance: ", Toler[2])
136 print(" Edge max. tolerance: ", Toler[3])
137 print(" Vertex min. tolerance: ", Toler[4])
138 print(" Vertex max. tolerance: ", Toler[5])
139
140

141
142 pcdg = geompy.MakeCDG(box)
143 if pcdg is None:
144 raise RuntimeError("MakeCDG(box) failed")
145 else:
146 print("\nCentre of gravity of box has been successfully obtained:")
147 Coords = geompy.PointCoordinates(pcdg)
148 print("(", Coords[0], ", ", Coords[1], ", ", Coords[2], ")")
149 if Coords[0] != 5 or Coords[1] != 15 or Coords[2] != 35:
150 print("But must be (5, 15, 35)")
151
152
153
154 faces = geompy.SubShapeAllSortedCentres(box, geompy.ShapeType["FACE"])
155 face0 = faces[0]

156 vnorm = geompy.GetNormal(face0)
157 if vnorm is None:
158 raise RuntimeError("GetNormal(face0) failed")
159 else:
160 geompy.addToStudy(face0, "Face0")
161 geompy.addToStudy(vnorm, "Normale to Face0")
162 print("\nNormale of face has been successfully obtained:")
163 #Coords = geompy.PointCoordinates(pcdg)
164 #print "(", Coords[0], ", ", Coords[1], ", ", Coords[2], ")"
165 #if Coords[0] != 5 or Coords[1] != 15 or Coords[2] != 35:
166 # print "But must be (5, 15, 35)"
167
168

169
170 MinDist = geompy.MinDistance(box, cube)
171
172 #print "\nMinimal distance between Box and Cube = ", MinDist[0]
173 #print "It is reached at points:"
174 #print " On Box (", MinDist[1], ", ", MinDist[2], ", ", MinDist[3], ")"
175 #print " On Cube (", MinDist[4], ", ", MinDist[5], ", ", MinDist[6], ")"
176
177 print("\nMinimal distance between Box and Cube = ", MinDist)
178
179 MinDistComps = geompy.MinDistanceComponents(box, cube)
180 print("\nMinimal distance between Box and Cube = ", MinDistComps[0])
181 print("Its components are (", MinDistComps[1], ", ", MinDistComps[2], ", ", MinDistComps[3], ")")
182
183 # Get all closest points
184 [nbSols, listCoords] = geompy.ClosestPoints(box, cube)
185 for i in range(nbSols):
186 v1 = geompy.MakeVertex(listCoords[i*6 + 0], listCoords[i*6 + 1], listCoords[i*6 + 2])
187 v2 = geompy.MakeVertex(listCoords[i*6 + 3], listCoords[i*6 + 4], listCoords[i*6 + 5])
188
189 geompy.addToStudy(v1, 'MinDist_%d_on_Box'%(i+1))
190 geompy.addToStudy(v2, 'MinDist_%d_on_Cube'%(i+1))
191 pass
192
193
194
195 OX = geompy.MakeVectorDXDYDZ(10, 0,0)
196 OXY = geompy.MakeVectorDXDYDZ(10,10,0)
197
198 # in one plane

199 Angle = geompy.GetAngle(OX, OXY)
200
201 print("\nAngle between OX and OXY = ", Angle)
202 if math.fabs(Angle - 45.0) > 1e-05:
203 print(" Error: returned angle is", Angle, "while must be 45.0")

204
205 Angle = geompy.GetAngleRadians(OX, OXY)
206
207 print("\nAngle between OX and OXY in radians = ", Angle)
208 if math.fabs(Angle - math.pi/4) > 1e-05:
209 print(" Error: returned angle is", Angle, "while must be pi/4")
210 pass