Salome HOME
bos #29468: Advanced geometry features: distance Edge-Edge & Face-Face
[modules/geom.git] / doc / salome / examples / complex_objs_ex08.py
1 # Creation of a PipeBiNormalAlongVector
2 import salome
3 salome.salome_init_without_session()
4 import GEOM
5 from salome.geom import geomBuilder
6 geompy = geomBuilder.New()
7
8 def MakeSpring(radius, height, rotation, direction, thread_radius, base_rotation, geom_builder):
9
10     def MakeHelix(radius, height, rotation, direction, geom_builder):
11         #  - create a helix -
12         radius = 1.0 * radius
13         height = 1.0 * height
14         rotation = 1.0 * rotation
15         if direction > 0:
16             direction = +1
17         else:
18             direction = -1
19             pass
20         from math import sqrt
21         length_z  = height
22         length_xy = radius*rotation
23         length = sqrt(length_z*length_z + length_xy*length_xy)
24         nb_steps = 1
25         epsilon = 1.0e-6
26         while 1:
27             z_step = height / nb_steps
28             angle_step = rotation / nb_steps
29             z = 0.0
30             angle = 0.0
31             helix_points = []
32             for n in range(nb_steps+1):
33                 from math import cos, sin
34                 x = radius * cos(angle)
35                 y = radius * sin(angle)
36                 p = geom_builder.MakeVertex(x, y, z)
37                 helix_points.append( p )
38                 z += z_step
39                 angle += direction * angle_step
40                 pass
41             helix = geom_builder.MakeInterpol(helix_points)
42             length_test = geom_builder.BasicProperties(helix)[0]
43             prec = abs(length-length_test)/length
44             # print nb_steps, length_test, prec
45             if prec < epsilon:
46                 break
47             nb_steps *= 2
48             pass
49         return helix
50
51     #  - create a pipe -
52     thread_radius = 1.0 * thread_radius
53     # create a helix
54     helix = MakeHelix(radius, height, rotation, direction, geom_builder=geom_builder)
55     # base in the (Ox, Oz) plane
56     p0 = geom_builder.MakeVertex(radius-3*thread_radius, 0.0, -thread_radius)
57     p1 = geom_builder.MakeVertex(radius+3*thread_radius, 0.0, -thread_radius)
58     p2 = geom_builder.MakeVertex(radius+3*thread_radius, 0.0, +thread_radius)
59     p3 = geom_builder.MakeVertex(radius-3*thread_radius, 0.0, +thread_radius)
60     e0 = geom_builder.MakeEdge(p0, p1)
61     e1 = geom_builder.MakeEdge(p1, p2)
62     e2 = geom_builder.MakeEdge(p2, p3)
63     e3 = geom_builder.MakeEdge(p3, p0)
64     w = geom_builder.MakeWire([e0, e1, e2, e3])
65     # create a base face
66     base = geom_builder.MakeFace(w, True)
67     # create a binormal vector
68     binormal = geom_builder.MakeVectorDXDYDZ(0.0, 0.0, 10.0)
69     # create a pipe
70     spring = geom_builder.MakePipeBiNormalAlongVector(base, helix, binormal)
71     # Publish in the study
72     geom_builder.addToStudy(base, "base")
73     geom_builder.addToStudy(helix, "helix")
74     geom_builder.addToStudy(binormal, "binormal")
75     geom_builder.addToStudy(spring, "spring")
76     return spring
77
78 from math import pi
79 spring = MakeSpring(50, 100, 2*pi, 1, 5, pi/2, geom_builder=geompy)