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