1 def TestMeasureOperations (geompy, math):
3 p0 = geompy.MakeVertex(0 , 0, 0)
4 p137 = geompy.MakeVertex(10, 30, 70)
6 box = geompy.MakeBoxTwoPnt(p0, p137)
8 p678 = geompy.MakeVertex(60, 70, 80)
9 p789 = geompy.MakeVertex(70, 80, 90)
11 cube = geompy.MakeBoxTwoPnt(p678, p789)
13 ####### PointCoordinates #######
15 Coords = geompy.PointCoordinates(p137)
16 if Coords[0] != 10 or Coords[1] != 30 or Coords[2] != 70:
17 print "Coordinates of p137 must be (10, 30, 70), but returned (", Coords[0], ", ", Coords[1], ", ", Coords[2], ")"
19 ####### CheckShape #######
21 IsValid = geompy.CheckShape(box)
23 raise RuntimeError, "Invalid box created"
25 print "\nBox is valid"
27 ####### WhatIs #######
29 Descr = geompy.WhatIs(box)
30 print "\nBox 10x30x70 description:"
33 ####### BasicProperties #######
35 Props = geompy.BasicProperties(box)
36 print "\nBox 10x30x70 Basic Properties:"
37 print " Wires length: ", Props[0]
38 print " Surface area: ", Props[1]
39 print " Volume : ", Props[2]
41 dl = math.sqrt((Props[0] - 880)*(Props[0] - 880))
42 da = math.sqrt((Props[1] - 6200)*(Props[1] - 6200))
43 dv = math.sqrt((Props[2] - 21000)*(Props[2] - 21000))
44 #print "|Props[0] - 880| = ", dl
46 if dl > 1e-7 or da > 1e-7 or dv > 1e-7:
47 print "While must be:"
48 print " Wires length: ", 880
49 print " Surface area: ", 6200
50 print " Volume : ", 21000
52 ####### BoundingBox #######
54 BB = geompy.BoundingBox(box)
55 print "\nBounding Box of box 10x30x70:"
56 print " Xmin = ", BB[0], ", Xmax = ", BB[1]
57 print " Ymin = ", BB[2], ", Ymax = ", BB[3]
58 print " Zmin = ", BB[4], ", Zmax = ", BB[5]
60 ####### Inertia #######
62 In = geompy.Inertia(box)
63 print "\nInertia matrix of box 10x30x70:"
64 print " (", In[0], ", ", In[1], ", ", In[2], ")"
65 print " (", In[3], ", ", In[4], ", ", In[5], ")"
66 print " (", In[6], ", ", In[7], ", ", In[8], ")"
67 print "Main moments of inertia of box 10x30x70:"
68 print " Ix = ", In[9], ", Iy = ", In[10], ", Iz = ", In[11]
70 ####### Tolerance #######
72 Toler = geompy.Tolerance(box)
73 print "\nBox 10x30x70 tolerance:"
74 print " Face min. tolerance: ", Toler[0]
75 print " Face max. tolerance: ", Toler[1]
76 print " Edge min. tolerance: ", Toler[2]
77 print " Edge max. tolerance: ", Toler[3]
78 print " Vertex min. tolerance: ", Toler[4]
79 print " Vertex max. tolerance: ", Toler[5]
81 ####### MakeCDG #######
83 pcdg = geompy.MakeCDG(box)
85 raise RuntimeError, "MakeCDG(box) failed"
87 print "\nCentre of gravity of box has been successfully obtained:"
88 Coords = geompy.PointCoordinates(pcdg)
89 print "(", Coords[0], ", ", Coords[1], ", ", Coords[2], ")"
90 if Coords[0] != 5 or Coords[1] != 15 or Coords[2] != 35:
91 print "But must be (5, 15, 35)"
93 ####### MinDistance #######
95 MinDist = geompy.MinDistance(box, cube)
97 #print "\nMinimal distance between Box and Cube = ", MinDist[0]
98 #print "It is reached at points:"
99 #print " On Box (", MinDist[1], ", ", MinDist[2], ", ", MinDist[3], ")"
100 #print " On Cube (", MinDist[4], ", ", MinDist[5], ", ", MinDist[6], ")"
102 print "\nMinimal distance between Box and Cube = ", MinDist