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