;;; ;;;STRING_HYPOCYCLOID.LSP (prompt "\nCurve-Stitching by AutoCAD - Hypocycloid.LSP") (prompt "\nCommands: hypocycloid ") (prompt "\n ") ;;;Ref. Jon Millington ;;; ;;;Takaya Iwamoto Jan 01-03, 2004 ;;; July 3,2007 modified for web release ;;; Commands hypocycloid then input number of cusps ;;; Oct 10,2007 renamed hypocycloid.lsp -->string_hypocycloid.lsp ;;; (defun C:string_hypocycloid_old() (setq num_cusp (getint "\nNumber of cusp ? (def = 3)")) (if (= num_cusp nil) (setq num_cusp 3)) (if (>= num_cusp 7) (C:case_7) ) (setup_shypocycloid) (make_jpg) ;;;execute the selected program (cond ((= num_cusp 3) (C:deltoid) ) ((= num_cusp 4) (C:astroid) ) ((= num_cusp 5) (C:five_cusped) );;;to be implemented ((= num_cusp 6) (C:six_cusped) ) (t nil) );;;end of cond (make_jpg) (make_jpg) (reset_sysvar) );;;STRING_HYPOCYCLOID_Old ;;; ;;; (defun C:string_hypocycloid() (setup_hypocycloid) ;set up (make_jpg) (make_jpg) (setq ndiv (getint "\nNo of division (def = 36)")) (if (= ndiv nil) (setq ndiv 36)) (alert "\nStart ?") (setq counter 0) (setq total_angle (* 2 pi) del_theta (/ total_angle ndiv) curve_pnt_old pnt_start n_cusp (fix rad_ratio) limit_angle (* pi (float (/ radius_in radius_out))) cur_theta 0. delay_time (fix (/ 18000 ndiv)) ) (setq counter 1) (make_line_1 "layer7" 2 pnt_a pnt_b) (make_jpg) (while (< cur_theta limit_angle) (setq cur_theta (* counter del_theta) alpha (* c2 cur_theta) pnt_u (polar pnt_org (- pi alpha) ref_radius) pnt_um (polar pnt_org (+ pi alpha) ref_radius) pnt_p (polar pnt_org cur_theta ref_radius) ) ;;if U & P coincide, then draw a tangent line on P and find V. (if (> (distance pnt_u pnt_p) 0.00001) (setq pnt_v (inters pnt_u pnt_p pnt_a pnt_b nil)) (setq pnt_v (list (/ ref_radius (cos cur_theta)) 0.)) ) (make_line_1 "layer7" 2 pnt_u pnt_v) (make_jpg) (make_line_1 "layer7" 2 pnt_um pnt_v) (make_jpg) (setq counter (1+ counter)) (command "_.delay" delay_time) );;;while loop (make_jpg) (make_jpg) (command "_.delay" delay_time) (alert "\nCopy this unit around the circle \nusing ARRAY command.") ;;make a selection set of layer7 (setq set_cusp (ssget "X" (list (cons 8 "layer7") ) )) (command "_.array" set_cusp "" "_P" pnt_org n_cusp "" "") ; (command "_.zoom" "_E") (command "_.regen") (reset_sysvar) );; ;;; ;;; (defun C:string_one_cusp() (setup_hypocycloid) ;set up (make_jpg) (make_jpg) (setq ndiv (getint "\nNo of division (def = 36)")) (if (= ndiv nil) (setq ndiv 36)) (alert "\nStart ?") (setq counter 0) (setq total_angle (* 2 pi) del_theta (/ total_angle ndiv) curve_pnt_old pnt_start n_cusp (fix rad_ratio) limit_angle (* pi (float (/ radius_in radius_out))) cur_theta 0. delay_time (fix (/ 18000 ndiv)) ) (setq counter 1) (make_line_1 "layer7" 2 pnt_a pnt_b) (make_jpg) (while (< cur_theta limit_angle) (setq cur_theta (* counter del_theta) alpha (* c2 cur_theta) pnt_u (polar pnt_org (- pi alpha) ref_radius) pnt_um (polar pnt_org (+ pi alpha) ref_radius) pnt_p (polar pnt_org cur_theta ref_radius) ) ;;if U & P coincide, then draw a tangent line on P and find V. (if (> (distance pnt_u pnt_p) 0.00001) (setq pnt_v (inters pnt_u pnt_p pnt_a pnt_b nil)) (setq pnt_v (list (/ ref_radius (cos cur_theta)) 0.)) ) (make_line_1 "layer7" 2 pnt_u pnt_v) (make_jpg) (make_line_1 "layer7" 2 pnt_um pnt_v) (make_jpg) (setq counter (1+ counter)) (command "_.delay" delay_time) );;;while loop (make_jpg) (make_jpg) (command "_.delay" delay_time) (command "_.zoom" "_E") (command "_.regen") (reset_sysvar) );; ;;; ;;; (defun C:five_cusped() (alert "\nNot implemented yet.") (C:refresh_all) (exit) ) ;;; ;;; (defun C:case_7() (alert "\nNot implemented yet.") (exit) ) ;;; ;;; (defun C:deltoid() (setq num_sec (getint "\nNumber of section (def=36)")) (if (= num_sec nil) (setq num_sec 36)) (command "_.divide" ref_circle num_sec) (setq EL1 (entnext ref_circle)) (while EL1 (ssadd EL1 ss1) (setq EL1 (entnext EL1)) );;;now ss1 has entity list of points on the circle (setq del_theta (/ (* 2 pi) num_sec) nstep 1 n_section 100 color_id 2 ) (setq pt_list (append pt_list (list (cdr (assoc 10 (entget (ssname ss1 0)))))) IN 1 EN (ssname ss1 IN) ) (while (< IN num_sec) (setq pt_list (append pt_list (list (cdr (assoc 10 (entget EN))))) IN (1+ IN) EN (ssname ss1 IN) ) );;;end of WHILE LOOP ;;;add the first element to the last (setq pt_list (append pt_list (list (cdr (assoc 10 (entget (ssname ss1 0)))))) ) ;;;now the N-th entry corresponds to pnt_N ;;;define points A,B,C,D,E,F & G. (setq pnt_id 1) (repeat num_sec (set (read (strcat "pnt_" (itoa pnt_id))) (nth pnt_id pt_list)) (setq pnt_id (1+ pnt_id)) ) (setq pnt_g (plt pnt_org pnt_6 3.0) pnt_a (plt pnt_org pnt_6 2.0) pnt_b (inters pnt_org pnt_6 pnt_34 pnt_1 nil) pnt_c (inters pnt_org pnt_6 pnt_32 pnt_2 nil) pnt_d (inters pnt_org pnt_6 pnt_30 pnt_3 nil) pnt_e (inters pnt_org pnt_6 pnt_28 pnt_4 nil) pnt_f (inters pnt_org pnt_6 pnt_26 pnt_5 nil) ) (command "_.point" pnt_a) (command "_.point" pnt_b) (command "_.point" pnt_c) (command "_.point" pnt_d) (command "_.point" pnt_e) (command "_.point" pnt_f) (command "_.point" pnt_g) (setq start nil end nil start (list pnt_36 pnt_34 pnt_32 pnt_30 pnt_28 pnt_26 pnt_24 pnt_22 pnt_20 pnt_18 pnt_16 pnt_14 pnt_12) end (list pnt_a pnt_b pnt_c pnt_d pnt_e pnt_f pnt_g pnt_f pnt_e pnt_d pnt_c pnt_b pnt_a) line_num 0 ) (repeat 13 (setq p_start (nth line_num start) p_end (nth line_num end) ) (make_line_1 "layer2" color_id p_start p_end) ;(slow_line n_section "layer2" color_id p_start p_end) (setq line_num (1+ line_num)) (make_jpg) (command "_.delay" 250) ) ;;;point connection for the first cusp ; 36 a ;;;Tangent 34 b 32 c 30 d 28 e 26 f ; 24 g ;;;Diameter 22 f 20 e 18 d 16 c 14 b ; 12 a ;;;Tangent ;;;copy this cusp mode using "Polar" array command (alert "\nCopy this Cusp to other 2 positions") (entdel outer_circle) (command "_.delay" 500) (command "_.array" "all" "" "P" pnt_org 3 "" "Y") (make_jpg) (command "_.delay" 250) ;(alert "\nWant to make - Four Deltoid - ?") (if (= (Yes_or_No "Want to make - Four Deltoid - ? def is OK ") "_Y") (command "_.array" "all" "" "P" '(-3 0) 4 "" "Y") ) (command "_.zoom" "E") (command "_.regen") (make_jpg) (make_jpg) (reset_sysvar) );;;deltoid ;;; ;;;function to find the number to subtract from ;;; (defun find_bound (test_num / low high test upper_bound) (setq low 0 high num_sec test "no" upper_bound ref_num) (while (= test "no") (if (and (>= test_num low) (< test_num high)) (setq test "yes" upper_bound high) (setq low high high (+ high ref_num)) ) );;;end of while loop (prin1 upper_bound) );;;FIND_BOUND ;;; (defun setup_shypocycloid() (setup_sysvar) (setvar "PDMODE" 32) (setvar "PDSIZE" -1) (setq ref_rad 1.0 pnt_org '(0 0) ref_rad2 (* 2 ref_rad) r_factor (/ (float num_cusp) (- num_cusp 2)) ref_rad3 (* r_factor ref_rad) ss1 nil ss1 (ssadd) pt_list nil ) (make_circle_1 "0" 8 pnt_org ref_rad3) (setq outer_circle (entlast)) (make_circle_1 "0" 8 pnt_org ref_rad) (setq ref_circle (entlast)) (command "_.zoom" "E") (command "_.regen") );;;SETUP_sHYPOCYCLOID ;;; (defun C:test2() (setup_shypocycloid) (setq num_sec (getint "\nNumber of section (def=72)")) (if (= num_sec nil) (setq num_sec 72)) (setq del_theta (/ (* 2 pi) num_sec) nstep 0 n_section 50 color_id 2 ) (setq num_cusp (getint "\nNumber of cusp ? (def = 1)")) (if (= num_cusp nil) (setq num_cusp 1)) (setq ref_num (/ num_sec (1+ num_cusp)) ) (repeat num_sec (setq start_angle (* nstep del_theta) p_start (polar pnt_org start_angle ref_rad) end_angle (* (1+ num_cusp) del_theta (rem nstep ref_num)) p_end (polar pnt_org end_angle ref_rad) ) (make_line_1 "0" color_id p_start p_end) (setq nstep (1+ nstep) ) );;;outer loop (reset_sysvar) );;;TEST2 ;;; ;;; (defun C:astroid() ;(setup_shypocycloid) (make_jpg) (setq num_sec (getint "\nNumber of section (def=36)")) (if (= num_sec nil) (setq num_sec 36)) (command "_.divide" ref_circle num_sec) (setq EL1 (entnext ref_circle)) (while EL1 (ssadd EL1 ss1) (setq EL1 (entnext EL1)) );;;now ss1 has entity list of points on the circle (setq del_theta (/ (* 2 pi) num_sec) nstep 1 n_section 100 color_id 2 ) (setq pt_list (append pt_list (list (cdr (assoc 10 (entget (ssname ss1 0)))))) IN 1 EN (ssname ss1 IN) ) (while (< IN num_sec) (setq pt_list (append pt_list (list (cdr (assoc 10 (entget EN))))) IN (1+ IN) EN (ssname ss1 IN) ) );;;end of WHILE LOOP ;;;add the first element to the last (setq pt_list (append pt_list (list (cdr (assoc 10 (entget (ssname ss1 0)))))) ) ;;;now the N-th entry corresponds to pnt_N ;;;define points A,B,C,D,E,F & G. (setq pnt_id 1) (repeat num_sec (set (read (strcat "pnt_" (itoa pnt_id))) (nth pnt_id pt_list)) (setq pnt_id (1+ pnt_id)) ) (setq pnt_45 (polar pnt_org (* 4.5 del_theta) 1.0) pnt_2223 (polar pnt_org (* 22.5 del_theta) 1.0) pnt_g (plt pnt_org pnt_45 2.0) pnt_a (plt pnt_org pnt_45 (sqrt 2.0)) pnt_b (inters pnt_org pnt_45 pnt_33 pnt_1 nil) pnt_c (inters pnt_org pnt_45 pnt_30 pnt_2 nil) pnt_d (inters pnt_org pnt_45 pnt_27 pnt_3 nil) pnt_e (inters pnt_org pnt_45 pnt_24 pnt_4 nil) ;pnt_f (inters pnt_org pnt_6 pnt_26 pnt_5 nil) ) (command "_.point" pnt_a) (command "_.point" pnt_b) (command "_.point" pnt_c) (command "_.point" pnt_d) (command "_.point" pnt_e) ;(command "_.point" pnt_f) (command "_.point" pnt_g) (setq start nil end nil start (list pnt_36 pnt_33 pnt_30 pnt_27 pnt_24 pnt_21 pnt_18 pnt_15 pnt_12 pnt_9) end (list pnt_a pnt_b pnt_c pnt_d pnt_e pnt_e pnt_d pnt_c pnt_b pnt_a) line_num 0 ) (repeat 10 (setq p_start (nth line_num start) p_end (nth line_num end) ) (make_line_1 "layer2" color_id p_start p_end) ;(slow_line n_section "layer2" color_id p_start p_end) (setq line_num (1+ line_num)) (make_jpg) (command "_.delay" 250) ) ;;;copy this cusp mode using "Polar" array command (alert "\nCopy this Cusp to other 3 positions") (entdel outer_circle) (command "_.delay" 500) (command "_.array" "all" "" "P" pnt_org 4 "" "Y") (make_jpg) (command "_.delay" 250) (command "_.zoom" "E") (command "_.regen") (make_jpg) (reset_sysvar) );;;Astroid ;;; ;;; (defun C:six_cusped() (setq num_sec (getint "\nNumber of section (def=72)")) (if (= num_sec nil) (setq num_sec 72)) (command "_.divide" ref_circle num_sec) (setq EL1 (entnext ref_circle)) (while EL1 (ssadd EL1 ss1) (setq EL1 (entnext EL1)) );;;now ss1 has entity list of points on the circle (setq nstep 1 n_section 100 color_id 2 pt_list (append pt_list (list (cdr (assoc 10 (entget (ssname ss1 0)))))) IN 1 EN (ssname ss1 IN) ) (while (< IN num_sec) (setq pt_list (append pt_list (list (cdr (assoc 10 (entget EN))))) IN (1+ IN) EN (ssname ss1 IN) ) );;;end of WHILE LOOP ;;;add the first element to the last (setq pt_list (append pt_list (list (cdr (assoc 10 (entget (ssname ss1 0)))))) ) ;;;now the N-th entry corresponds to pnt_N ;;;define points A,B,C,D,E,F & G. (setq pnt_id 1) (repeat num_sec (set (read (strcat "pnt_" (itoa pnt_id))) (nth pnt_id pt_list)) (setq pnt_id (1+ pnt_id)) ) (setq pnt_g (plt pnt_org pnt_6 1.5) pnt_a (plt pnt_org pnt_6 (/ 2. (sqrt 3)) ) pnt_b (inters pnt_org pnt_6 pnt_67 pnt_1 nil) pnt_c (inters pnt_org pnt_6 pnt_62 pnt_2 nil) pnt_d (inters pnt_org pnt_6 pnt_57 pnt_3 nil) pnt_e (inters pnt_org pnt_6 pnt_52 pnt_4 nil) pnt_f (inters pnt_org pnt_6 pnt_47 pnt_5 nil) ) (command "_.point" pnt_a) (command "_.point" pnt_b) (command "_.point" pnt_c) (command "_.point" pnt_d) (command "_.point" pnt_e) (command "_.point" pnt_f) (command "_.point" pnt_g) (setq start nil end nil start (list pnt_72 pnt_67 pnt_62 pnt_57 pnt_52 pnt_47 pnt_42 pnt_37 pnt_32 pnt_27 pnt_22 pnt_17 pnt_12) end (list pnt_a pnt_b pnt_c pnt_d pnt_e pnt_f pnt_g pnt_f pnt_e pnt_d pnt_c pnt_b pnt_a) line_num 0 ) (repeat 13 (setq p_start (nth line_num start) p_end (nth line_num end) ) (make_line_1 "layer2" color_id p_start p_end) ;(slow_line n_section "layer2" color_id p_start p_end) (setq line_num (1+ line_num)) (make_jpg) (command "_.delay" 250) ) ;;;copy this cusp mode using "Polar" array command (alert "\nCopy this Cusp to other 5 positions") (entdel outer_circle) (command "_.delay" 500) (command "_.array" "all" "" "P" pnt_org 6 "" "Y") (command "_.delay" 250) (command "_.zoom" "E") (command "_.regen") (make_jpg) (make_jpg) (reset_sysvar) );;;six_cusped ;;; ;;; (defun C:string_hypocycloid_model() (setup_hypocycloid) ;set up (make_jpg) (make_jpg) (setq ndiv (getint "\nNo of division (def = 36)")) (if (= ndiv nil) (setq ndiv 36)) (alert "\nStart ?") (setq counter 0) (setq total_angle (* 2 pi) del_theta (/ total_angle ndiv) curve_pnt_old pnt_start n_cusp (fix rad_ratio) last_step (1- (fix (/ ndiv (* 2 n_cusp))) ) ) (setq counter 0) (repeat last_step (setq cur_theta (* counter del_theta) pnt_tmp (polar pnt_org cur_theta 1.0)) (get_value) (if (>= counter 1) (progn (clear_lines) (setq x_new (+ (* c1 (cos cur_theta)) (* radius_in (cos (* c2 cur_theta)))) y_new (- (* c1 (sin cur_theta)) (* radius_in (sin (* c2 cur_theta)))) curve_pnt_new (list x_new y_new) ) (make_line_1 "layer4" 4 curve_pnt_old curve_pnt_new) (setq curve_pnt_old curve_pnt_new) ) );;end if (command "_.insert" "hypo_cycle" pnt_new 1.0 1.0 angle_disk1) (command "explode" (entlast)) (setq counter (1+ counter)) (command "_.delay" 250) );;;repeat loop (make_circle_1 "layer4" 8 pnt_org ref_radius) (setq ref_circle (entlast)) (make_pt "0" 0 pnt_org) (setq pnt_r (polar pnt_org cur_theta radius_out) pnt_w (shift_pnt pnt_new '(1. 0)) pnt_q pnt_new pnt_s curve_pnt_old pnt_p (polar pnt_org cur_theta ref_radius) alpha (angle pnt_q pnt_s) theta (angle pnt_org pnt_r) beta (+ pi alpha) pnt_t (polar pnt_org alpha ref_radius) pnt_m (polar pnt_org alpha radius_out) pnt_u (polar pnt_org beta ref_radius) pnt_n (polar pnt_org beta radius_out) pnt_v (inters pnt_p pnt_s pnt_org pnt_x nil) ) ;;make points & lines (make_pt "0" 0 pnt_v) (make_pt "0" 0 pnt_w) (make_pt "0" 0 pnt_u) (make_pt "0" 0 pnt_t) (make_pt "0" 0 pnt_a) (make_pt "0" 0 pnt_p) (make_pt "0" 0 pnt_q) (make_pt "0" 0 pnt_r) (make_line_1 "0" 8 pnt_org in_center) (make_line_1 "0" 8 pnt_org pnt_r) (make_line_1 "0" 8 pnt_q pnt_w) (make_line_1 "0" 8 pnt_m pnt_u) (make_line_1 "0" 8 pnt_r pnt_m) (make_line_1 "0" 2 pnt_u pnt_v) ;(make_line_1 "0" 8 pnt_n pnt_r) ;;mark_id (mark_id pnt_org "O" 3 chr_size) (mark_id pnt_p "P" 2 chr_size) (mark_id pnt_q "Q" 2 chr_size) (mark_id pnt_r "R" 1 chr_size) (mark_id pnt_s "S" 1 chr_size) (mark_id pnt_w "W" 1 chr_size) (mark_id pnt_a "A" 3 chr_size) (mark_id pnt_b "B" 1 chr_size) (mark_id pnt_t "T" 4 chr_size) (mark_id pnt_u "U" 2 chr_size) (mark_id pnt_v "V" 4 chr_size) (mark_id pnt_m "M" 3 chr_size) ;(mark_id pnt_n "N" 3 chr_size) ;;divide circles- ref_circle & out_circle ;(command "_.divide" ref_circle ndiv) ;(command "_.divide" out_circle ndiv) ;;mark_angle (mark_angle pnt_s pnt_q pnt_w 0.3 "a" 0.175 4) (mark_angle pnt_b pnt_org pnt_r 0.4 "q" 0.175 1) (mark_angle pnt_m pnt_org pnt_b 0.5 "a" 0.175 1) (mark_angle pnt_b pnt_org pnt_u 0.65 "b" 0.175 2) (mark_angle pnt_u pnt_org pnt_a 0.5 "a" 0.175 3) (command "_.zoom" "_E") (command "_.regen") (reset_sysvar) );; ;;; ;;; ;;; ;compute translation & angle values from pnt_tmp (defun get_value( / theta ) (setq theta (angle out_center pnt_tmp)) (setq angle_disk1 (- (rtd (* (- rad_ratio 1.0) theta)))) (setq pnt_new (polar out_center theta rad_dif)) ) ;clear construction lines (defun clear_lines( / block_set n nminus index ) ;(setq block_set (ssget "X" (list (cons -4 "")) )) (setq block_set (ssget "X" (list (cons 8 "layer8")) ) ) (setq n (sslength block_set)) ;(setq nminus (- n 3)) ;repeat for all circle & line elements (setq index 0) ;(repeat nminus (repeat n (entdel (ssname block_set index)) (setq index (1+ index)) ) );;;CLEAR_LINES ;;; ;;; ;setup_hypocycloid (defun setup_hypocycloid( / set_hypo fraction x_upper x_lower pnt_upper pnt_lower ) (setup_sysvar) (setvar "PDMODE" 32) (setvar "PDSIZE" -2) (setvar "OSMODE" 0) (setq radius_out (getreal "\nradius of outer circle ? (def = 3.0)") radius_in (getreal "\nRadius of inner circle ? (def=1.0)")) (if (= radius_in nil) (setq radius_in 1.0)) (if (= radius_out nil) (setq radius_out 3.0)) ;(setup_hypo_dialog) (setq rad_ratio (/ (float radius_out) (float radius_in)) n_cusp (fix rad_ratio) radius_in (/ (float radius_out) rad_ratio) rad_dif (- radius_out radius_in) ref_radius (- radius_out (* 2 radius_in)) c1 rad_dif c2 (/ rad_dif radius_in) pnt_org '(0 0) out_center '(0 0) in_center (list rad_dif 0.0) pnt_start (list radius_out 0.0 ) pnt_a (list (- ref_radius) 0) pnt_b pnt_start fraction (* radius_in 0.2) x_upper (+ (car pnt_start) fraction) x_lower (- (car pnt_start) fraction) pnt_upper (list x_upper fraction) pnt_lower (list x_lower (- fraction)) chr_size 0.20 ) (make_circle_1 "0" 0 out_center radius_out) (setq out_circle (entlast)) (make_circle_1 "layer4" 8 pnt_org ref_radius) (setq ref_circle (entlast)) (make_line_1 "0" 8 pnt_a pnt_b) ;define block named "hypo_cycle" ;layer 8 (make_circle_1 "layer8" 8 in_center radius_in) (make_pt "layer8" 8 in_center) ;layer 2 (make_pt "layer2" 2 pnt_start) ;layer 3 (make_line_1 "layer3" 3 pnt_start in_center) (command "_.zoom" "_EXTENT") (command "_.regen") ;select entity set for block (setq set_hypo (ssget "X" (list (cons -4 "")) )) (command "_.block" "hypo_cycle" in_center set_hypo "") ;block definition );;;SETUP_HYPOCYCLOID