;; test program for Pythagorean number 3^2 + 4^2 = 5^2 ;; tessel_pclass.lsp ;; First prototype was done on Feb 16,2003 ;; There are two classes of problems ;; According to Diophantus, a fourth-century Greek mathematician from Alexandria, ;; the general solution is ;; x = m*m - n*n y = 2mn z = m*m + n*n ;; ;; Pythagoras Class m = n + 1 (3 4 5) (5 12 13) (7 24 25), ... ;; Plato Class n = 1 (3 4 5) (8 15 17) (12 35 37), ... ;; (prompt "tessel_pclass") (defun c:tessel_pclass() ;**1**select a value for n (setq n (getint "\nvalue for n (=1,2,3,4, ...)def = 1 ") ) (if (= n nil) (setq n 1)) (draw_grid) (setq x_char (itoa x) y_char (itoa y) z_char (itoa z) z_loc (list (- (+ (* 0.5 z) 3.5)) (+ z 0.5) ) x_loc (list (- (* 0.5 x) 0.75) (+ (* 0.5 x) z 1)) y_loc (list 1.5 (- y 1.75)) z_text (strcat z_char " x " z_char) x_text (strcat x_char " x " x_char) y_text (strcat y_char " x " y_char) ) (setq str (strcat "(" (itoa x) " " (itoa y) " " (itoa z) ") " "case") chr_h (* 0.5 n)) (textdisplay str '(-4 -2.) chr_h 0.) (make_jpg) (comp_points) ;compute corner points (make_jpg) ;**2**start partitioning (alert "partition into pieces") (partition) (make_jpg) (make_jpg) (alert "copy this to the left") ;**3**copy this to the left (setq whole (ssget "C" p_z_z p_0_0)) (my_block_def "WHOLE_1" p_0_0 whole) (command "oops") (my_block_insert "WHOLE_1" (list (- (+ z x)) 0) 1.0) (textdisplay z_text z_loc chr_h 0.) (command "_.regen") (make_jpg) (make_jpg) (make_jpg) ;**4**break these parts apart (alert "break the parts") (set_color "bylayer" ) (break_parts) ;; (textdisplay x_text x_loc chr_h 0.) (textdisplay y_text y_loc chr_h 0.) ;move the parts and build new pieces (setvar "PDMODE" 2) (if (>= n 4) (setq nsize -2) (setq nsize (- n 6))) (setvar "PDSIZE" nsize) (make_jpg) (make_jpg) (make_jpg) );test_main ; ;;; (defun draw_grid( / x_cur y_cur tot_lines x_pos y_pos) (setvar "PDMODE" 32) (setvar "PDSIZE" -1) (setq x_cur 0. g_unit 1. m (1+ n) m_2 (* m m) n_2 (* n n) x (- m_2 n_2) y (* 2 m n) z (+ m_2 n_2) tot_lines (1+ z) lower_left (list (- (+ z 6)) -2.1) upper_right (list (+ z 2) (+ z x 2)) ) (command "_.zoom" "_W" lower_left upper_right) ;;;; (repeat tot_lines (setq y_cur 0. ) (repeat tot_lines (setq x_pos x_cur y_pos y_cur) (make_pt "0" 0 (list x_pos y_pos)) (setq y_cur (+ y_cur g_unit)) );;inner loop (setq x_cur (+ x_cur g_unit)) );;outer loop (command "_.regen") );;draw_grid ; ;;; (defun comp_points() ;define the basic corner points (setq p_0_0 '(0 0) p_zm1_0 (list (1- z) 0) p_z_0 (list z 0) p_0_zmx (list 0 (- z x)) p_0_z (list 0 z) p_x_z (list x z) p_x_zmxp1 (list x (- z (1- x))) p_z_zm2 (list z (- z 2)) p_z_z (list z z) p_x_zmx (list x (- z x)) ) ;define the point list for 2 steps ;;;small_steps ;;;make a list of (2n*n -1) steps (setq n_repeat (1- (* 2 n n)) x1 (1- z) y1 1 step_pt1 nil ) (repeat n_repeat (setq step_pt1 (append step_pt1 (list (list x1 y1) (list (1- x1) y1) ) ) ) (setq x1 (1- x1) y1 (1+ y1)) ;reinitialize ) (setq step_pt1 (append (list p_zm1_0) (append step_pt1 (list p_x_zmx)))) ;;;Move/cut left a distance of 2n ;;;(n - 1) times: [Move/cut down 2;Move/cut left 2n] ;;make a list of (n -1) vertical steps (setq n_rep2 (1- n) x2 (- z (* 2 n)) y2 (- z 2) step_pt2 nil) (repeat n_rep2 (setq step_pt2 (append step_pt2 (list (list x2 y2) (list x2 (- y2 2)) ) ) ) (setq x2 (- x2 (* 2 n)) y2 (- y2 2)) ) (setq step_pt2 (append (list p_z_zm2) (append step_pt2 (list p_x_zmxp1) ))) ) ;;; ;(prompt "check #2") (defun partition( ) ;;;This has to be recoded to make this interactive ;;part_1;Cut a x_square from the upper left corner of z_square (setq pnt_list (list p_0_z p_x_z p_x_zmx p_0_zmx)) (make_polyline "0" 0 "continuous" pnt_list 1) (setq x_x (entlast)) ;(setq part_1 (solid_hatch x_x "magenta")) ;;part_2;Step starting 1 left of the lower right corner of the z-square ;Move/cut up a distance of 1 (2n*n-1) times (setq pnt_list1 (append (list p_0_zmx p_0_0 p_zm1_0) step_pt1)) (make_polyline "0" 0 "continuous" pnt_list1 1) (setq low_left (entlast)) ;(setq part_2 (solid_hatch low_left "yellow")) ;;part_3 ;;;Step starting 2 below the upper right corner of the z-square: ;;;Move/cut left a distance of 2n ;;;(n - 1) times: [Move/cut down 2;Move/cut left 2n] ;;make a list of (n -1) vertical steps (setq pnt_list2 (append step_pt2 (list p_x_z p_z_z )) ) (make_polyline "0" 0 "continuous" pnt_list2 1) (setq up_right (entlast)) ;(setq part_3 (solid_hatch up_right "green")) ;;part_4 (setq pnt_list3 (append step_pt1 (reverse step_pt2) (list p_z_0) )) (make_polyline "0" 0 "continuous" pnt_list3 1) (setq low_right (entlast)) ;(setq part_4 (solid_hatch low_right "blue" )) (command "_.delay" 1000) (alert "\nShade all polygons") (setq part_1 (solid_hatch x_x "magenta")) (setq part_2 (solid_hatch low_left "yellow")) (setq part_3 (solid_hatch up_right "green")) (setq part_4 (solid_hatch low_right "blue" )) (command "_.delay" 1000) (command "_.color" "BYLAYER") );;partition ;;; (defun break_parts() ;*** part_1 *** (setq pnt_start p_0_z pnt_end (move_pnt p_0_z (list 0 (1+ x))) n_speed 100 ndiv 6 ncolor 1 layer_name "0") (move_ent part_1 pnt_start pnt_end n_speed ndiv ncolor layer_name) ;*** part_3 *** (setq pnt_start p_x_zmxp1 pnt_end p_0_zmx ) (move_ent part_3 pnt_start pnt_end n_speed ndiv ncolor layer_name) ;*** part_4 *** (setq pnt_start p_x_zmx pnt_end (move_pnt p_x_zmx (list -1 1) )) (move_ent part_4 pnt_start pnt_end n_speed ndiv ncolor layer_name) );break_parts ;;; ;;;shift a point by (dx,dy) ;;; (defun move_pnt(ref_pnt dx_dy / x_ref y_ref dx dy new_pnt) (setq x_ref (car ref_pnt) y_ref (cadr ref_pnt) dx (car dx_dy) dy (cadr dx_dy) ) (setq new_pnt (list (+ x_ref dx) (+ y_ref dy))) );;;move_pnt