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:
1 radius spiral:
def spiral1(radius, height, laps, edgesperlap) model = Sketchup.active_model entities = 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] end spiral1(5.mm, 100.mm, 25, 36)2 radius spiral:
def spiral2(radius1, radius2, height, laps, edgesperlap) model = Sketchup.active_model entities = 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] end spiral2( 5.mm, 15.mm, 100.mm, 10, 36)Archimedean Spiral Sphere:
def spiral_sphere(radius, revolutions, edgesperrev, cutoff) #Defining group model = Sketchup.active_model entities = model.active_entities @Sphere = Sketchup.active_model.entities.add_group #Defining variables radius = radius.to_f revolutions = revolutions.to_i edgesperrev = edgesperrev.to_i cutoff = 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] end spiral_sphere(50.00.mm, 10, 36, 0)Some ready plugins:
-
Some helix here : http://www.drawmetal.com
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement