1 # Creation of a PipeBiNormalAlongVector
3 salome.salome_init_without_session()
5 from salome.geom import geomBuilder
6 geompy = geomBuilder.New()
8 def MakeSpring(radius, height, rotation, direction, thread_radius, base_rotation, geom_builder):
10 def MakeHelix(radius, height, rotation, direction, geom_builder):
14 rotation = 1.0 * rotation
22 length_xy = radius*rotation
23 length = sqrt(length_z*length_z + length_xy*length_xy)
27 z_step = height / nb_steps
28 angle_step = rotation / nb_steps
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 )
39 angle += direction * angle_step
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
52 thread_radius = 1.0 * thread_radius
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])
66 base = geom_builder.MakeFace(w, True)
67 # create a binormal vector
68 binormal = geom_builder.MakeVectorDXDYDZ(0.0, 0.0, 10.0)
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")
79 spring = MakeSpring(50, 100, 2*pi, 1, 5, pi/2, geom_builder=geompy)