1 # Creation of a PipeBiNormalAlongVector
3 def MakeHelix(radius, height, rotation, direction):
7 rotation = 1.0 * rotation
15 length_xy = radius*rotation
16 length = sqrt(length_z*length_z + length_xy*length_xy)
21 z_step = height / nb_steps
22 angle_step = rotation / nb_steps
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 )
33 angle += direction * angle_step
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
45 def MakeSpring(radius, height, rotation, direction, thread_radius, base_rotation=0.0):
47 thread_radius = 1.0 * thread_radius
49 helix = MakeHelix(radius, height, rotation, direction)
50 # base in the (Ox, Oz) plane
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])
62 base = geompy.MakeFace(w, True)
63 # create a binormal vector
64 binormal = geompy.MakeVectorDXDYDZ(0.0, 0.0, 10.0)
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")
76 spring = MakeSpring(50, 100, 2*pi, 1, 5, pi/2)