Version: 8.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Minimal Distance
1 # Minimal Distance
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 
9 # Create two curves with three closest points
10 Vertex_1 = geompy.MakeVertex(0, 0, 0)
11 Vertex_2 = geompy.MakeVertex(0, 70, 0)
12 Vertex_3 = geompy.MakeVertex(30, 100, 0)
13 Vertex_4 = geompy.MakeVertex(60, 70, 0)
14 Vertex_5 = geompy.MakeVertex(90, 100, 0)
15 Vertex_6 = geompy.MakeVertex(120, 70, 0)
16 Vertex_7 = geompy.MakeVertex(120, 0, 0)
17 Vertex_8 = geompy.MakeVertex(90, -30, 0)
18 Vertex_9 = geompy.MakeVertex(60, 0, 0)
19 Vertex_10 = geompy.MakeVertex(30, -30, 0)
20 
21 geompy.addToStudy( Vertex_1, 'Vertex_1' )
22 geompy.addToStudy( Vertex_2, 'Vertex_2' )
23 geompy.addToStudy( Vertex_3, 'Vertex_3' )
24 geompy.addToStudy( Vertex_4, 'Vertex_4' )
25 geompy.addToStudy( Vertex_5, 'Vertex_5' )
26 geompy.addToStudy( Vertex_6, 'Vertex_6' )
27 geompy.addToStudy( Vertex_7, 'Vertex_7' )
28 geompy.addToStudy( Vertex_8, 'Vertex_8' )
29 geompy.addToStudy( Vertex_9, 'Vertex_9' )
30 geompy.addToStudy( Vertex_10, 'Vertex_10' )
31 
32 Curve_a = geompy.MakeInterpol([Vertex_2, Vertex_3, Vertex_4, Vertex_5, Vertex_6], False, True)
33 Curve_b = geompy.MakeInterpol([Vertex_1, Vertex_7, Vertex_8, Vertex_9, Vertex_10], False, True)
34 
35 geompy.addToStudy( Curve_a, 'Curve_a' )
36 geompy.addToStudy( Curve_b, 'Curve_b' )
37 
38 # Get all closest points
39 [nbSols, listCoords] = geompy.ClosestPoints(Curve_a, Curve_b)
40 
41 for i in range(nbSols):
42  v1 = geompy.MakeVertex(listCoords[i*6 + 0], listCoords[i*6 + 1], listCoords[i*6 + 2])
43  v2 = geompy.MakeVertex(listCoords[i*6 + 3], listCoords[i*6 + 4], listCoords[i*6 + 5])
44 
45  geompy.addToStudy(v1, 'MinDist_%d_Curve_a'%(i+1))
46  geompy.addToStudy(v2, 'MinDist_%d_Curve_b'%(i+1))
47 
48 # Get minimum distance
49 print "Minimal distance between Curve_a and Curve_b is", geompy.MinDistance(Curve_a, Curve_b)
50 
51 # Get minimum distance with components along axes
52 [aDist, DX, DY, DZ] = geompy.MinDistanceComponents(Curve_a, Curve_b)
53 print "Minimal distance between Curve_a and Curve_b is (", DX, ",", DY, ",", DZ, ")"

Download this script