1 # Creation of a PipeBiNormalAlongVector
5 from salome.geom import geomBuilder
6 geompy = geomBuilder.New(salome.myStudy)
8 def MakeHelix(radius, height, rotation, direction):
12 rotation = 1.0 * rotation
20 length_xy = radius*rotation
21 length = sqrt(length_z*length_z + length_xy*length_xy)
25 z_step = height / nb_steps
26 angle_step = rotation / nb_steps
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 )
37 angle += direction * angle_step
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
49 def MakeSpring(radius, height, rotation, direction, thread_radius, base_rotation=0.0):
51 thread_radius = 1.0 * thread_radius
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])
65 base = geompy.MakeFace(w, True)
66 # create a binormal vector
67 binormal = geompy.MakeVectorDXDYDZ(0.0, 0.0, 10.0)
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")
79 spring = MakeSpring(50, 100, 2*pi, 1, 5, pi/2)