Flores
9th Apr 2003, 04:35 am
I found an interesting helix /spring routine that you might be interested in. Actually it is called "spiral", but spirals are on a 2D plane, but anyway... What makes this one interesting is that it has a dialog box to enter your data. One thing I noticed though, is that the "number of segments per revolution" cannot be increased too high, but if you uncheck the little checkbox that turns the "solid model" on or off, you can increase the number as high as you want and it will be a really smooth spring (125 for example). If you uncheck the "solid model", it will draw a helix, but you will have to draw your circle and extrude it yourself, but I think it is better that way anyway. Enough with the rambling!
Save below as spiral.lsp
;;;
;;; SPIRAL.LSP Alireza Parsai Ver 1.02 3/23/02
;;; Draws a 3D wirefram/solid spiral using a 3D dialog box
;;;
(defun C:SPIRAL (/ cm bm sm r_del angInc
z_inc steps n draw_it dcl_id sp_cen
sp_zz sp_anglee sp_radiuss ent1
ent2 entlist pt1 pt2 angleangle
zz cencen radiusradius ss1 ss2
)
(setq cm (getvar "CMDECHO")
bm (getvar "BLIPMODE")
sm (getvar "OSMODE")
)
(setvar "CMDECHO" 0)
(command "UNDO" "BE")
;;Initialization
(if (not (= (type sp_x) 'real))
(setq sp_x 0.0)
)
(if (not (= (type sp_y) 'real))
(setq sp_y 0.0)
)
(if (not (= (type sp_z) 'real))
(setq sp_z 0.0)
)
(if (not (= (type sp_radius) 'real))
(setq sp_radius 0.5)
)
(if (not (= (type sp_r_inc) 'real))
(setq sp_r_inc 0)
)
(if (not (= (type sp_pitch) 'real))
(setq sp_pitch 0.25)
)
(if (not (= (type sp_angle) 'real))
(setq sp_angle 0.0)
)
(if (not (= (type sp_revs) 'real))
(setq sp_revs 5.0)
)
(if (not (= (type sp_div) 'int))
(setq sp_div 10)
)
(if (not (= (type sp_ch_thick) 'real))
(setq sp_ch_thick 0.125)
)
(if (not (= (type sp_type) 'int))
(setq sp_type 1)
)
;;Dialog Box
(setq dcl_id (load_dialog "spiral.dcl"))
(if (not (new_dialog "spiral" dcl_id))
(exit)
)
(set_tile "sp_x" (rtos sp_x))
(set_tile "sp_y" (rtos sp_y))
(set_tile "sp_z" (rtos sp_z))
(set_tile "sp_radius" (rtos sp_radius))
(set_tile "sp_r_inc" (rtos sp_r_inc))
(set_tile "sp_pitch" (rtos sp_pitch))
(set_tile "sp_angle" (rtos sp_angle))
(set_tile "sp_revs" (rtos sp_revs))
(set_tile "sp_div" (itoa sp_div))
(set_tile "sp_ch_thick" (rtos sp_ch_thick))
(set_tile "sp_type" (itoa sp_type))
(setq draw_it t
ss1 nil
ss2 nil
)
(defun itsok ()
(setq draw_it nil
sp_x (atof (get_tile "sp_x"))
sp_y (atof (get_tile "sp_y"))
sp_z (atof (get_tile "sp_z"))
sp_radius (atof (get_tile "sp_radius"))
sp_r_inc (atof (get_tile "sp_r_inc"))
sp_pitch (atof (get_tile "sp_pitch"))
sp_angle (atof (get_tile "sp_angle"))
sp_revs (atof (get_tile "sp_revs"))
sp_div (atoi (get_tile "sp_div"))
sp_ch_thick (atof (get_tile "sp_ch_thick"))
sp_type (atoi (get_tile "sp_type"))
sp_anglee sp_angle
sp_radiuss sp_radius
)
)
(action_tile "accept" "(itsok) (done_dialog)")
(start_dialog)
(unload_dialog dcl_id) ;_end of dialog box
;;Final Work
(setvar "BLIPMODE" 0)
(setvar "osmode" 0)
(if (not draw_it)
(progn
(setq angInc (/ 6.283185307 sp_div)
z_inc (/ sp_pitch sp_div)
steps (* sp_div sp_revs)
sp_zz sp_z
sp_cen (list sp_x sp_y sp_zz)
n 0
r_del (/ sp_r_inc sp_div)
pt1 (polar sp_cen sp_angle sp_radius)
angleangle (+ sp_angle angInc)
zz (+ sp_z z_inc)
cencen (list sp_x sp_y zz)
radiusradius (+ sp_radius r_del)
pt2 (polar cencen angleangle radiusradius)
)
(if (/= sp_type 0)
(progn
(command "UCS" "N" "ZA" pt1 pt2)
(command "CIRCLE" '(0 0 0) "D" sp_ch_thick)
(command "UCS" "P")
(setq ent1 (entlast)
ss1 (ssadd ent1)
)
)
)
(command "3DPOLY" (polar sp_cen sp_angle sp_radius))
(while (< n steps)
(setq sp_anglee (+ sp_anglee angInc)
sp_zz (+ sp_zz z_inc)
sp_cen (list sp_x sp_y sp_zz)
n (1+ n)
sp_radiuss (+ sp_radiuss r_del)
)
(command (polar sp_cen sp_anglee sp_radiuss))
) ;_ end while
(command "")
(if (/= sp_type 0)
(progn
(setq ent2 (entlast)
ss2 (ssadd ent2)
)
(command "extrude" ss1 "" "p" ss2)
(entdel ent2)
)
)
)
)
(setvar "BLIPMODE" bm)
(setvar "OSMODE" sm)
(command "UNDO" "End")
(setvar "CMDECHO" cm)
(princ)
) ;_ end function spiral
Save below as spiral.dcl
spiral : dialog {
label = "Draw Spiral" ;
: row {
: boxed_column {
label = "Base Center Point" ;
: row {
: column {
: text {
label = " X:" ;
}
: edit_box {
key = "sp_x" ;
width = 7 ;
fixed_width = true;
}
}
: column {
: text {
label = " Y:" ;
}
: edit_box {
key = "sp_y" ;
width = 7 ;
fixed_width = true;
}
}
: column {
: text {
label = " Z:" ;
}
: edit_box {
key = "sp_z" ;
width = 7 ;
fixed_width = true;
}
}
}
spacer ;
}
: image {
color = -15 ;
width = 10 ;
fixed_width = true ;
}
}
: row {
: column {
: text {
label = "Initial radius of spiral" ;
}
: text {
label = "Radius increment per revolution" ;
}
: text {
label = "Pitch of spiral" ;
}
: text {
label = "Direction from center to spiral start point" ;
}
: text {
label = "Number of revolutions" ;
}
: text {
label = "Spiral chord thickness" ;
}
: text {
label = "Number of divisions per revolution" ;
}
}
: column {
: edit_box {
key = "sp_radius" ;
}
: edit_box {
key = "sp_r_inc" ;
}
: edit_box {
key = "sp_pitch" ;
}
: edit_box {
key = "sp_angle" ;
}
: edit_box {
key = "sp_revs" ;
}
: edit_box {
key = "sp_ch_thick" ;
}
: edit_box {
key = "sp_div" ;
}
}
}
spacer ;
: toggle {
key = "sp_type" ;
label = "Solid Model" ;
}
ok_cancel ;
}
Flores
Save below as spiral.lsp
;;;
;;; SPIRAL.LSP Alireza Parsai Ver 1.02 3/23/02
;;; Draws a 3D wirefram/solid spiral using a 3D dialog box
;;;
(defun C:SPIRAL (/ cm bm sm r_del angInc
z_inc steps n draw_it dcl_id sp_cen
sp_zz sp_anglee sp_radiuss ent1
ent2 entlist pt1 pt2 angleangle
zz cencen radiusradius ss1 ss2
)
(setq cm (getvar "CMDECHO")
bm (getvar "BLIPMODE")
sm (getvar "OSMODE")
)
(setvar "CMDECHO" 0)
(command "UNDO" "BE")
;;Initialization
(if (not (= (type sp_x) 'real))
(setq sp_x 0.0)
)
(if (not (= (type sp_y) 'real))
(setq sp_y 0.0)
)
(if (not (= (type sp_z) 'real))
(setq sp_z 0.0)
)
(if (not (= (type sp_radius) 'real))
(setq sp_radius 0.5)
)
(if (not (= (type sp_r_inc) 'real))
(setq sp_r_inc 0)
)
(if (not (= (type sp_pitch) 'real))
(setq sp_pitch 0.25)
)
(if (not (= (type sp_angle) 'real))
(setq sp_angle 0.0)
)
(if (not (= (type sp_revs) 'real))
(setq sp_revs 5.0)
)
(if (not (= (type sp_div) 'int))
(setq sp_div 10)
)
(if (not (= (type sp_ch_thick) 'real))
(setq sp_ch_thick 0.125)
)
(if (not (= (type sp_type) 'int))
(setq sp_type 1)
)
;;Dialog Box
(setq dcl_id (load_dialog "spiral.dcl"))
(if (not (new_dialog "spiral" dcl_id))
(exit)
)
(set_tile "sp_x" (rtos sp_x))
(set_tile "sp_y" (rtos sp_y))
(set_tile "sp_z" (rtos sp_z))
(set_tile "sp_radius" (rtos sp_radius))
(set_tile "sp_r_inc" (rtos sp_r_inc))
(set_tile "sp_pitch" (rtos sp_pitch))
(set_tile "sp_angle" (rtos sp_angle))
(set_tile "sp_revs" (rtos sp_revs))
(set_tile "sp_div" (itoa sp_div))
(set_tile "sp_ch_thick" (rtos sp_ch_thick))
(set_tile "sp_type" (itoa sp_type))
(setq draw_it t
ss1 nil
ss2 nil
)
(defun itsok ()
(setq draw_it nil
sp_x (atof (get_tile "sp_x"))
sp_y (atof (get_tile "sp_y"))
sp_z (atof (get_tile "sp_z"))
sp_radius (atof (get_tile "sp_radius"))
sp_r_inc (atof (get_tile "sp_r_inc"))
sp_pitch (atof (get_tile "sp_pitch"))
sp_angle (atof (get_tile "sp_angle"))
sp_revs (atof (get_tile "sp_revs"))
sp_div (atoi (get_tile "sp_div"))
sp_ch_thick (atof (get_tile "sp_ch_thick"))
sp_type (atoi (get_tile "sp_type"))
sp_anglee sp_angle
sp_radiuss sp_radius
)
)
(action_tile "accept" "(itsok) (done_dialog)")
(start_dialog)
(unload_dialog dcl_id) ;_end of dialog box
;;Final Work
(setvar "BLIPMODE" 0)
(setvar "osmode" 0)
(if (not draw_it)
(progn
(setq angInc (/ 6.283185307 sp_div)
z_inc (/ sp_pitch sp_div)
steps (* sp_div sp_revs)
sp_zz sp_z
sp_cen (list sp_x sp_y sp_zz)
n 0
r_del (/ sp_r_inc sp_div)
pt1 (polar sp_cen sp_angle sp_radius)
angleangle (+ sp_angle angInc)
zz (+ sp_z z_inc)
cencen (list sp_x sp_y zz)
radiusradius (+ sp_radius r_del)
pt2 (polar cencen angleangle radiusradius)
)
(if (/= sp_type 0)
(progn
(command "UCS" "N" "ZA" pt1 pt2)
(command "CIRCLE" '(0 0 0) "D" sp_ch_thick)
(command "UCS" "P")
(setq ent1 (entlast)
ss1 (ssadd ent1)
)
)
)
(command "3DPOLY" (polar sp_cen sp_angle sp_radius))
(while (< n steps)
(setq sp_anglee (+ sp_anglee angInc)
sp_zz (+ sp_zz z_inc)
sp_cen (list sp_x sp_y sp_zz)
n (1+ n)
sp_radiuss (+ sp_radiuss r_del)
)
(command (polar sp_cen sp_anglee sp_radiuss))
) ;_ end while
(command "")
(if (/= sp_type 0)
(progn
(setq ent2 (entlast)
ss2 (ssadd ent2)
)
(command "extrude" ss1 "" "p" ss2)
(entdel ent2)
)
)
)
)
(setvar "BLIPMODE" bm)
(setvar "OSMODE" sm)
(command "UNDO" "End")
(setvar "CMDECHO" cm)
(princ)
) ;_ end function spiral
Save below as spiral.dcl
spiral : dialog {
label = "Draw Spiral" ;
: row {
: boxed_column {
label = "Base Center Point" ;
: row {
: column {
: text {
label = " X:" ;
}
: edit_box {
key = "sp_x" ;
width = 7 ;
fixed_width = true;
}
}
: column {
: text {
label = " Y:" ;
}
: edit_box {
key = "sp_y" ;
width = 7 ;
fixed_width = true;
}
}
: column {
: text {
label = " Z:" ;
}
: edit_box {
key = "sp_z" ;
width = 7 ;
fixed_width = true;
}
}
}
spacer ;
}
: image {
color = -15 ;
width = 10 ;
fixed_width = true ;
}
}
: row {
: column {
: text {
label = "Initial radius of spiral" ;
}
: text {
label = "Radius increment per revolution" ;
}
: text {
label = "Pitch of spiral" ;
}
: text {
label = "Direction from center to spiral start point" ;
}
: text {
label = "Number of revolutions" ;
}
: text {
label = "Spiral chord thickness" ;
}
: text {
label = "Number of divisions per revolution" ;
}
}
: column {
: edit_box {
key = "sp_radius" ;
}
: edit_box {
key = "sp_r_inc" ;
}
: edit_box {
key = "sp_pitch" ;
}
: edit_box {
key = "sp_angle" ;
}
: edit_box {
key = "sp_revs" ;
}
: edit_box {
key = "sp_ch_thick" ;
}
: edit_box {
key = "sp_div" ;
}
}
}
spacer ;
: toggle {
key = "sp_type" ;
label = "Solid Model" ;
}
ok_cancel ;
}
Flores