;;; ;;; ;;;HILBERT2.LSP ;;; ;;; June 22,2003 Takaya Iwamoto ;Hilbert's Space-Filling Curve ;Modified pattern proposed by Eliakim Hastings Moore (1862 - 1932) ;Basic algorithm is the same as Hilbert.lsp ;The only difference is MAKE_ALL_BLOCKS function ;directions indices ; 0---up ; 1---right ; 2---down ; 3---left ;starting configuration ;(80 21 32 90) ;;; ;;;Hilbert main ;;; (defun c:hilbert2() (setup_hilbert) ;;parse the box_list and pnt_list (while (= (Yes_or_No "Go to next step ?") "_Y") (setq c_pos 0) ;;;c_pos current position index (setq t_plist nil t_blist nil t_elist nil ) (princ "\nlist_size =")(princ list_size)(princ "; box_scale = ")(princ box_scale)(terpri) ;;;inner loop (repeat list_size (setq box_id (nth c_pos box_list ) box_pt (nth c_pos pnt_list ) ent_id (nth c_pos ent_list ) ) ;;;call pattern to replace the current box by 4 boxes (hilbert_pattern) (setq c_pos (1+ c_pos)) ) (alert "\nErase the previous pattern") (erase_elist) ;;;copy t_plist,t_blist,t_elist to pnt_list,box_list & ent_list (setq pnt_list t_plist box_list t_blist ent_list t_elist list_size (* list_size 4) box_scale (* box_scale 0.5) ) );;;end of while loop (reset_sysvar) );;;HILBERT ;;; ;;; ;;;setup_hilbert ;;; (defun setup_hilbert() (setup_sysvar) (setvar "PDMODE" 32) (setq pnt_1 '(-0.25 -0.25) pnt_12 '(-0.25 0) pnt_2 '(-0.25 0.25) pnt_23 '(0 0.25) pnt_3 '(0.25 0.25) pnt_34 '(0.25 0) pnt_4 '(0.25 -0.25) pnt_41 '(0 -0.25) pnt_01 '(-0.5 -0.5) pnt_02 '(-0.5 0.5) pnt_03 '(0.5 0.5) pnt_04 '(0.5 -0.5) pnt_list (list pnt_1 pnt_2 pnt_3 pnt_4) box_list (list 80 21 32 90) lower_left '(-0.5 -0.5) upper_right '(0.5 0.5) list_size 4 box_scale 0.5 pnt_51 '(-0.25 -0.5) pnt_52 '(0.25 -0.5) pnt_61 '(-0.5 -0.25) pnt_62 '(0.5 -0.25) pnt_71 '(-0.5 0.25) pnt_72 '(0.5 0.25) pnt_81 '(-0.25 0.5) pnt_82 '(0.25 0.5) pnt_ctr '(0 0) ) (make_line_1 "0" 8 pnt_01 pnt_02) (make_line_1 "0" 8 pnt_02 pnt_03) (make_line_1 "0" 8 pnt_03 pnt_04) (make_line_1 "0" 8 pnt_04 pnt_01) (command "_.zoom" "W" lower_left upper_right) ;;;make an entity list ent_list (make_line_1 "0" 0 pnt_1 pnt_12) (setq ent_1 (entlast)) (command "_.pline" pnt_12 pnt_2 pnt_23 "") (setq ent_2 (entlast)) (command "_.pline" pnt_23 pnt_3 pnt_34 "") (setq ent_3 (entlast)) (make_line_1 "0" 0 pnt_34 pnt_4) (setq ent_4 (entlast)) (setq ent_list (list ent_1 ent_2 ent_3 ent_4)) ;;;make all the basic patterns as block entities (make_all_blocks) );;;SETUP_HILBERT ;;; ;;;HILBERT_PATTERN ;;; (defun hilbert_pattern() (if (= box_id 80) (pattern "block_80" box_list_80 pnt_list_80)) (if (= box_id 81) (pattern "block_81" box_list_81 pnt_list_81)) (if (= box_id 90) (pattern "block_90" box_list_90 pnt_list_90)) (if (= box_id 93) (pattern "block_93" box_list_93 pnt_list_93)) (if (= box_id 1) (pattern "block_01" box_list_01 pnt_list_01)) (if (= box_id 2) (pattern "block_02" box_list_02 pnt_list_02)) (if (= box_id 3) (pattern "block_03" box_list_03 pnt_list_03)) (if (= box_id 10) (pattern "block_10" box_list_10 pnt_list_10)) (if (= box_id 20) (pattern "block_20" box_list_20 pnt_list_20)) (if (= box_id 30) (pattern "block_30" box_list_30 pnt_list_30)) (if (= box_id 12) (pattern "block_12" box_list_12 pnt_list_12)) (if (= box_id 32) (pattern "block_32" box_list_32 pnt_list_32)) (if (= box_id 21) (pattern "block_21" box_list_21 pnt_list_21)) (if (= box_id 23) (pattern "block_23" box_list_23 pnt_list_23)) (if (= box_id 13) (pattern "block_13" box_list_13 pnt_list_13)) (if (= box_id 31) (pattern "block_31" box_list_31 pnt_list_31)) );;;HILBERT_PATTERN There are 12 patterns plus 4(end & start) ;;; ;;;Pattern ;;;;PATTERN_01,02,03, 10,12,13, 20,21,23, 30,31,32 & 80,81,90,93 ;;; (defun pattern( blk_name boxlist pntlist) ;;;insert the given block_name at box_pnt, with scale box_scale (my_block_insert blk_name box_pt box_scale) (setq new_ent_id (entlast) t_elist (append t_elist (list new_ent_id)) ) ;;;add boxlist to temp box list t_blist (setq t_blist (append t_blist boxlist)) ;;;convert pntlist to global data,then add to temp_plist (setq npos 0 newplist nil) (repeat 4 (setq pnt_data (nth npos pntlist) x (car pnt_data) y (cadr pnt_data) x_box (car box_pt) y_box (cadr box_pt) new_x (+ (* x box_scale) x_box) new_y (+ (* y box_scale) y_box) newpnt (list new_x new_y) newplist (append newplist (list newpnt)) npos (1+ npos) ) );end of repeat loop ;;;then add newplist to t_plist (setq t_plist (append t_plist newplist)) );;;PATTERN ;;;MAKE_ALL_BLOCKS ;;;make block_01,02,03 10,20,30,12,21,13,31,23,32,80,81,90,93 ;;; (defun make_all_blocks() (setq pnt_list_80 (list pnt_4 pnt_1 pnt_2 pnt_3) box_list_80 (list 81 10 21 30) pnt_list_81 (list pnt_4 pnt_3 pnt_2 pnt_1) box_list_81 (list 80 23 12 3) pnt_list_21 (list pnt_4 pnt_1 pnt_2 pnt_3) box_list_21 (list 23 10 21 31 ) pnt_list_32 (list pnt_2 pnt_3 pnt_4 pnt_1) box_list_32 (list 31 32 3 12) pnt_list_90 (list pnt_2 pnt_3 pnt_4 pnt_1) box_list_90 (list 1 32 3 93) pnt_list_93 (list pnt_4 pnt_3 pnt_2 pnt_1) box_list_93 (list 10 23 12 90) pnt_list_01 (list pnt_2 pnt_1 pnt_4 pnt_3) box_list_01 (list 2 1 30 21) pnt_list_10 (list pnt_4 pnt_1 pnt_2 pnt_3) box_list_10 (list 13 10 21 30) pnt_list_02 (list pnt_2 pnt_3 pnt_4 pnt_1); box_list_02 (list 1 32 3 12) pnt_list_20 (list pnt_4 pnt_1 pnt_2 pnt_3) box_list_20 (list 23 10 21 30) pnt_list_03 (list pnt_2 pnt_3 pnt_4 pnt_1) box_list_03 (list 1 32 3 13) pnt_list_30 (list pnt_2 pnt_1 pnt_4 pnt_3) box_list_30 (list 32 1 30 20) pnt_list_12 (list pnt_4 pnt_3 pnt_2 pnt_1) box_list_12 (list 10 23 12 2) pnt_list_13 (list pnt_4 pnt_3 pnt_2 pnt_1) box_list_13 (list 10 23 12 3) pnt_list_31 (list pnt_2 pnt_1 pnt_4 pnt_3) box_list_31 (list 32 1 30 21 ) pnt_list_23 (list pnt_4 pnt_3 pnt_2 pnt_1) box_list_23 (list 20 23 12 3) ) (command "_.pline" pnt_4 pnt_1 pnt_2 pnt_3 pnt_82 "") (my_block_def "block_80" pnt_ctr (entlast)) (command "_.pline" pnt_4 pnt_3 pnt_2 pnt_1 pnt_61 "") (my_block_def "block_81" pnt_ctr (entlast)) (command "_.pline" pnt_52 pnt_4 pnt_1 pnt_2 pnt_3 pnt_72 "") (my_block_def "block_21" pnt_ctr (entlast)) (command "_.pline" pnt_71 pnt_2 pnt_3 pnt_4 pnt_1 pnt_51 "") (my_block_def "block_32" pnt_ctr (entlast)) (command "_.pline" pnt_81 pnt_2 pnt_3 pnt_4 pnt_1 "") (my_block_def "block_90" pnt_ctr (entlast)) (command "_.pline" pnt_62 pnt_4 pnt_3 pnt_2 pnt_1 "") (my_block_def "block_93" pnt_ctr (entlast)) (command "_.pline" pnt_81 pnt_2 pnt_1 pnt_4 pnt_3 pnt_72 "") (my_block_def "block_01" pnt_ctr (entlast)) (command "_.pline" pnt_62 pnt_4 pnt_1 pnt_2 pnt_3 pnt_82 "") (my_block_def "block_10" pnt_ctr (entlast)) (command "_.pline" pnt_81 pnt_2 pnt_3 pnt_4 pnt_1 pnt_51 "") (my_block_def "block_02" pnt_ctr (entlast)) (command "_.pline" pnt_82 pnt_3 pnt_2 pnt_1 pnt_4 pnt_52 "") (my_block_def "block_20" pnt_ctr (entlast)) (command "_.pline" pnt_81 pnt_2 pnt_3 pnt_4 pnt_1 pnt_61 "") (my_block_def "block_03" pnt_ctr (entlast)) (command "_.pline" pnt_71 pnt_2 pnt_1 pnt_4 pnt_3 pnt_82 "") (my_block_def "block_30" pnt_ctr (entlast)) (command "_.pline" pnt_62 pnt_4 pnt_3 pnt_2 pnt_1 pnt_51 "") (my_block_def "block_12" pnt_ctr (entlast)) (command "_.pline" pnt_62 pnt_4 pnt_3 pnt_2 pnt_1 pnt_61 "") (my_block_def "block_13" pnt_ctr (entlast)) (command "_.pline" pnt_71 pnt_2 pnt_1 pnt_4 pnt_3 pnt_72 "") (my_block_def "block_31" pnt_ctr (entlast)) (command "_.pline" pnt_52 pnt_4 pnt_3 pnt_2 pnt_1 pnt_61 "") (my_block_def "block_23" pnt_ctr (entlast)) );;;MAKE_ALL_BLOCKs ;;; ;;; ;;;Erase all the entity in ent_list ;;; (defun erase_elist( / e_pos t_ent) (setq e_pos 0) (while (setq t_ent (nth e_pos ent_list)) (entdel t_ent) (setq e_pos (1+ e_pos)) );;;end of while loop );;;ERASE_ELIST