Spiral algorithms

Spiral algorithms

Postby Tax » Fri Oct 23, 2020 3:26 pm



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:
Code: Select all
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:
Code: Select all
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:
Code: Select all
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:
- https://sketchucation.com/plugin/1379-helix_along_curve
- viewtopic.php?f=323&t=33139
- https://sites.google.com/site/spirixcode/
- https://sketchucation.com/plugin/878-jwm_shapes
- https://mabimo.blogspot.com/2019/10/ske ... nload.html
1

Tax 
 

Re: Spiral algorithms

Postby pilou » Fri Oct 23, 2020 6:27 pm

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

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Developers' Forum

Who is online

Users browsing this forum: No registered users and 9 guests

Visit our sponsors: