## Spiral algorithms

### Spiral algorithms

1-2 radius spiral and Archimedean spiral sphere algorithms. I know there are a few great and free plugins out there, but maybe you want to use these functions inside your own program. So just sharing:

Code: Select all
`def spiral1(radius, height, laps, edgesperlap)model = Sketchup.active_modelentities = model.active_entities@Spiral1 = Sketchup.active_model.entities.add_group@Lap = @Spiral1.entities.add_group@TotalEdges = laps * edgesperlap@Zincrement = height / @TotalEdges@EdgeAngle = 360.00.degrees / edgesperlap@LapHeight = height / laps #Make 1st lap @point1 = [radius, 0, 0] for step in 0..edgesperlap  @x = Math.cos(@EdgeAngle * step) * radius  @y = Math.sin(@EdgeAngle * step) * radius  @z = step * @Zincrement  @point2 = [@x, @y, @z]  @line = @Lap.entities.add_line @point1, @point2  @point1 = @point2 end  #Copy-Paste all laps for step in 1..(laps-1)  @Copy = @Lap.copy  @Copy = @Copy.move! [0, 0, @LapHeight*step]  @Copy.explode end @Lap.explode @Pt1 = @Spiral1.entities.add_cpoint [0, 0, 0] @Pt2 = @Spiral1.entities.add_cpoint [0, 0, height]endspiral1(5.mm, 100.mm, 25, 36)`

Code: Select all
`def spiral2(radius1, radius2, height, laps, edgesperlap)model = Sketchup.active_modelentities = model.active_entities@Spiral2 = Sketchup.active_model.entities.add_group@TotalEdges = laps * edgesperlap@Zincrement = height / @TotalEdges@EdgeAngle = 360.00.degrees / edgesperlap@LapHeight = height / laps@Reduction = radius2 - radius1@ReductionPerEdge = @Reduction / @TotalEdges @point1 = [radius1, 0, 0] for step in 0..@TotalEdges  @Radius = (radius1 + (@ReductionPerEdge * step))  @x = Math.cos(@EdgeAngle * step) * @Radius  @y = Math.sin(@EdgeAngle * step) * @Radius  @z = step * @Zincrement  @point2 = [@x, @y, @z]  @line = @Spiral2.entities.add_line @point1, @point2  @point1 = @point2 end @Pt1 = @Spiral2.entities.add_cpoint [0, 0, 0] @Pt2 = @Spiral2.entities.add_cpoint [0, 0, height]endspiral2( 5.mm, 15.mm, 100.mm, 10, 36)`

Archimedean Spiral Sphere:
Code: Select all
`def spiral_sphere(radius, revolutions, edgesperrev, cutoff)#Defining groupmodel = Sketchup.active_modelentities = model.active_entities@Sphere = Sketchup.active_model.entities.add_group#Defining variablesradius = radius.to_frevolutions = revolutions.to_iedgesperrev = edgesperrev.to_icutoff = cutoff.to_i@TotalEdges = revolutions * edgesperrev@VerticalStep = 180.00.degrees / @TotalEdges@HorizontalStep = 360.00.degrees / edgesperrev#CutOff (0% - 100%)@cut = (@TotalEdges / 100.00 * cutoff)@start = (@cut).to_i@ending = (@TotalEdges - @cut).to_i#Defining 1st point@LocalRadius = Math.sin(@VerticalStep * @start) * radius@x = Math.cos(@HorizontalStep * @start) * @LocalRadius@y = Math.sin(@HorizontalStep * @start) * @LocalRadius@z = Math.cos(@VerticalStep * @start) * radius@point1 = [@x, @y, @z]#Making spiral for edge in @start+1..@ending @LocalRadius = Math.sin(@VerticalStep * edge) * radius @x = Math.cos(@HorizontalStep * edge) * @LocalRadius @y = Math.sin(@HorizontalStep * edge) * @LocalRadius @z = Math.cos(@VerticalStep * edge) * radius  @point2 = [@x, @y, @z] @line = @Sphere.entities.add_line @point1, @point2 @point1 = @point2 end@CenterPoint = @Sphere.entities.add_cpoint [0, 0, 0]endspiral_sphere(50.00.mm, 10, 36, 0)`

- https://sketchucation.com/plugin/1379-helix_along_curve
- viewtopic.php?f=323&t=33139
- https://sketchucation.com/plugin/878-jwm_shapes
1

Tax

### Re: Spiral algorithms

Some helix here : http://www.drawmetal.com
1
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie pilou
Top SketchUcator