sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Spiral algorithms

    Scheduled Pinned Locked Moved Developers' Forum
    2 Posts 2 Posters 6.3k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • TaxT Offline
      Tax
      last edited by


      1-2 radius spiral and Archimedean spiral sphere algorithms.

      https://i.imgur.com/FvWm3Fl.png

      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:

      • https://sketchucation.com/plugin/1379-helix_along_curve
      • https://sketchucation.com/forums/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/sketchup-helix-plugin-download.html

      "Between cause and consequence, lots of connivance."
      "Never felt being on same level as others; just bc Ive never been."

      1 Reply Last reply Reply Quote 0
      • pilouP Offline
        pilou
        last edited by

        Some helix here : http://www.drawmetal.com

        Frenchy Pilou
        Is beautiful that please without concept!
        My Little site :)

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Buy SketchPlus
        Buy SUbD
        Buy WrapR
        Buy eBook
        Buy Modelur
        Buy Vertex Tools
        Buy SketchCuisine
        Buy FormFonts

        Advertisement