CamBam
News:
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
March 30, 2020, 14:58:20 pm


Login with username, password and session length


Pages: [1]
  Print  
Author Topic: VERY rough Conic Helix script  (Read 3151 times)
lloydsp
CNC Jedi
*****
Offline Offline

Posts: 8172



View Profile
« on: June 06, 2014, 14:12:59 pm »

here: http://www.cambam.co.uk/forum/index.php?topic=4209.0

PS... Bob L... this will cut pipe threads, too! <G>
(no leadins/outs yet, but it could be made to have them)

Lloyd

PS... there was a bug that made the start point of the helix the first step in, instead of the real start point.
  (bug was in the original 'boingy')  It's fixed there, and here:

'//////////////////////////////////////////////////////////////////////////////
'
' Conic Helix.vbs
' CamBam vbscript
' With credits to 10 Bulls for the idea from "Boingy"
'
   dim turns as single
   dim start_diameter as single
   dim end_diameter as single
   dim depth_increment as single
   dim strAnswer as string
   dim direction as single
sub main
   start_diameter=val(Inputbox ("Smaller diameter? "))
   end_diameter=val(Inputbox ("Larger diameter? "))
   turns=val(Inputbox("Number of turns? "))
   depth_increment=val(Inputbox ("Depth change per turn -- negative =-Z, or down "))
   direction=val(Inputbox("Direction to turn -- -1=CCW, 1=CW"))
   direction=direction*-1
   dim p as polyline =   MakeConicHelix()
   doc.add(p)
end sub




function  MakeConicHelix as polyline
   dim start as single   = 0         ' in radians
   dim finish as single = turns*2*pi   '30*pi      ' in radians
   dim steps as single   = 500      ' number of steps
   dim radius as single = start_diameter/2
   dim startz as single = -1*depth_increment*turns
   dim endz as single   = 0
   
   dim radius_step as single = (end_diameter-start_diameter)/(steps*2)
   


   dim x as single = 0
   dim y as single = 0
   dim z as single = startz

   dim th as single = start
   dim dt as single = (finish-start)/steps*direction
   dim dz as single = (endz-startz)/steps

   '// Get the drawing ready to draw   
   dim p as Polyline = new Polyline

   '// Play da loop
   for i as short = 0 to steps
      x = radius * math.cos(th)
      y = radius * math.sin(th)
      p.Add(x,y,z)

      radius=radius+radius_step
      z = z + dz
      th = th + dt


   next i

   MakeConicHelix = p
      
end function
« Last Edit: June 06, 2014, 15:37:54 pm by lloydsp » Logged

"Pyro for Fun and Profit for More Than Fifty Years"
lloydsp
CNC Jedi
*****
Offline Offline

Posts: 8172



View Profile
« Reply #1 on: December 21, 2014, 19:56:17 pm »

Here's an adjustment to the script above that allows you to specify the number of segments per turn, in order to smooth the line.

Lloyd

--------------------------


'//////////////////////////////////////////////////////////////////////////////
'
' Conic Helix.vbs
' CamBam vbscript
' By AMDlloydsp, with credits to 10 Bulls for the idea from "Boingy"
'
   dim turns as single
   dim start_diameter as single
   dim end_diameter as single
   dim depth_increment as single
   dim strAnswer as string
   dim direction as single
   dim smooth as single

sub main
   start_diameter=val(Inputbox ("Smaller diameter? "))
   end_diameter=val(Inputbox ("Larger diameter? "))
   turns=val(Inputbox("Number of turns? "))
   depth_increment=val(Inputbox ("Depth change per turn -- negative =-Z, or down "))
   direction=val(Inputbox("Direction to turn -- -1=CCW, 1=CW"))
   direction=direction*-1
    smooth=val(Inputbox("Smoothing factor (number of segments per turn) recommended 100 per turn as a compromise."))
   dim p as polyline =   MakeConicHelix()
   doc.add(p)
end sub




function  MakeConicHelix as polyline
   dim start as single   = 0         ' in radians
   dim finish as single = turns*2*pi   '30*pi      ' in radians
   dim steps as single   = turns*smooth      ' number of steps
   dim radius as single = start_diameter/2
   dim startz as single = -1*depth_increment*turns
   dim endz as single   = 0
   
   dim radius_step as single = (end_diameter-start_diameter)/(steps*2)
   


   dim x as single = 0
   dim y as single = 0
   dim z as single = startz

   dim th as single = start
   dim dt as single = (finish-start)/steps*direction
   dim dz as single = (endz-startz)/steps

   '// Get the drawing ready to draw   
   dim p as Polyline = new Polyline

   '// Play da loop
   for i as short = 0 to steps
      x = radius * math.cos(th)
      y = radius * math.sin(th)
      p.Add(x,y,z)

      radius=radius+radius_step
      z = z + dz
      th = th + dt


   next i

   MakeConicHelix = p
      
end function
« Last Edit: December 21, 2014, 20:00:47 pm by lloydsp » Logged

"Pyro for Fun and Profit for More Than Fifty Years"
dh42
Administrator
CNC Jedi
*****
Offline Offline

Posts: 5840



View Profile WWW
« Reply #2 on: December 21, 2014, 21:57:14 pm »

Hello Lloyd,

Cool, added to the list Wink

++
David
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.123 seconds with 19 queries.

Copyright © 2018 HexRay Ltd. | Sitemap