Salome HOME
[bos #36177] [FORUM] - Remove extra-edge on hemisphere
[modules/geom.git] / test / test_proximity_face_face.py
1 # Shape Proximity between faces
2
3 import math
4 import salome
5 salome.salome_init_without_session()
6 import GEOM
7 from salome.geom import geomBuilder
8 geompy = geomBuilder.New()
9
10 O = geompy.MakeVertex(0, 0, 0)
11 OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
12 OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
13 OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
14
15 # Case 1: cylinder and sphere (different coarse and fine proximities)
16 OCyl = geompy.MakeVertex(0, -5, 15)
17 Cyl = geompy.MakeCylinder(OCyl, OY, 3, 10, "Cyl")
18 AX1 = geompy.MakeTranslation(OX, 0, 0, 15, "AX1")
19 geompy.Rotate(Cyl, AX1, -20.0*math.pi/180.0)
20 Cyl_face = geompy.SubShapeAllSortedCentres(Cyl, geompy.ShapeType["FACE"], "Face")[1]
21 Sph = geompy.MakeSphereR(10, "Sph")
22 Box_1 = geompy.MakeBoxDXDYDZ(40, 40, 27.071067)
23 Translation_1 = geompy.MakeTranslation(Box_1, -20, -20, -20)
24 Cut_1 = geompy.MakeCutList(Sph, [Translation_1], True, "Cut_1")
25 Sph_face = geompy.SubShapeAllSortedCentres(Cut_1, geompy.ShapeType["FACE"], "Face")[1]
26
27 pcalc = geompy.ShapeProximity()
28 #pcalc.setShapes(Cyl_face, Sph_face)
29 pcalc.setShapes(Sph_face, Cyl_face)
30 p_coarse = pcalc.coarseProximity()
31 p_fine   = pcalc.preciseProximity()
32
33 assert(math.fabs(p_coarse - 9.8649933) < 1.e-7)
34 assert(math.fabs(p_fine - 7.6984631) < 1.e-7)
35
36 geompy.MakeVertex(0, 2.63303, 17.2342, "p1")
37 geompy.MakeVertex(0, 0, 10, "p2")
38
39 print("With sampling 0: coarse = {} ; fine = {}".format(p_coarse, p_fine))
40
41 pcalc.setSampling(Cyl_face, 100) # number of sample points for the first shape
42 pcalc.setSampling(Sph_face, 100) # number of sample points for the second shape
43 p_coarse = pcalc.coarseProximity()
44 p_fine   = pcalc.preciseProximity()
45
46 print("With sampling 100: coarse = {} ; fine = {}".format(p_coarse, p_fine))
47
48 pcalc.setSampling(Cyl_face, 1000) # number of sample points for the first shape
49 pcalc.setSampling(Sph_face, 1000) # number of sample points for the second shape
50 p_coarse = pcalc.coarseProximity()
51 p_fine   = pcalc.preciseProximity()
52
53 print("With sampling 1000: coarse = {} ; fine = {}".format(p_coarse, p_fine))
54
55 # Case 2: conical and planar faces
56 Cone_1 = geompy.MakeConeR1R2H(100, 0, 300)
57 Cone_1_face_3 = geompy.GetSubShape(Cone_1, [3])
58 Cone_1_wire_4 = geompy.GetSubShape(Cone_1, [4])
59 Face_1 = geompy.MakeFaceFromSurface(Cone_1_face_3, Cone_1_wire_4, "Face_1")
60 Face_1_edge_5 = geompy.GetSubShape(Face_1, [5])
61 Face_2 = geompy.MakeFaceObjHW(Face_1_edge_5, 200, 200)
62 geompy.Rotate(Face_2, OY, 90*math.pi/180.0)
63 Face_2_vertex_7 = geompy.GetSubShape(Face_2, [7])
64 Translation_1 = geompy.MakeTranslationTwoPoints(Face_2, Face_2_vertex_7, O, "Translation_1")
65
66 shape1 = Face_1
67 shape2 = Translation_1
68
69 # perform proximity calculation with the default parameters
70 p1 = geompy.ShapeProximity()
71 proximity1 = p1.proximity(shape1, shape2)
72
73 # perform proximity calculation with custom parameters
74 p2 = geompy.ShapeProximity()
75 p2.setShapes(shape1, shape2)
76 p2.setSampling(shape1, 100) # number of sample points for the first shape
77 p2.setSampling(shape2, 40)  # number of sample points for the second shape
78 proximity2_coarse = p2.coarseProximity()
79 proximity2_fine = p2.preciseProximity()
80
81 assert(math.fabs(proximity1 - proximity2_fine) < 1.e-7)
82 assert(math.fabs(proximity2_coarse - 127.1141386) < 1.e-7)
83 #assert(math.fabs(proximity2_fine - 94.8683298) < 1.e-7)
84 assert(math.fabs(proximity2_fine - 127.1141386) < 1.e-7)
85
86 geompy.MakeVertex(0, 0, 300, "p3")
87 geompy.MakeVertex(-63.2456, 0, 189.737, "p4")