;;;SUM of cubes ;;;copyright 2006 Takaya Iwamoto ;;;Ref. Page 87 "Proofs without words" ;;;Update Nov 02,2004 changed ARRAY command to block-copy ;;;Update Apr 24,2005 added JPGout option for documentation ;;; (defun c:sumcube_1 () (setup_sumcube1) (while (= (Yes_or_No "Go to next step ?") "_Y") (NxNxN_sqr nstep) (IF (= JPG_Yes 1) (make_jpg) ) (setq nstep (1+ nstep)) ) ;;;end of while loop (command "_.pline" p00 "_Width" 0.2 "" p50 "") (alert "\nCopy & rotate this unit 90, 180, 270 degrees") (copy_stair_block) (alert "\nAdd final texts & titles") (final_text) ;;final text and title (reset_sysvar) (command "_.pline" '(-100 -100) "_width" 0. 0. "") ;;reset pline width 1-20/2005 (IF (= JPG_YES 1) (make_jpg) ) ) ;;;SUMCUBE_1 ;;; ;;;SETUP_SUMCUBE1 ;;; (defun setup_sumcube1 (/ lower_left upper_right) (setup_sysvar) (setq nstep 1 lower_left '(-16 -16) upper_right '(16 16) ) ;draw N section of N x N squares (setq sqr_plate "white_hatch") (my_block_insert sqr_plate '(-1 -1) 1.0) (command "_.pline" '(-1 0) "_Width" 0.2 "" '(-1 -1) "") (setq nstep (1+ nstep) ss1 nil ss1 (ssadd) ) (setq EL1 (entnext)) ;selection set for all entities (command "_.zoom" "_W" lower_left upper_right) (IF (= JPG_YES 1) (make_jpg) ) ) ;;;setup_sumcube1 ;;; ;;;NxNxN_sqr ;;; (defun NxNxN_sqr (num) (setq x_start (- (sum_n num)) pnt_base (list x_start x_start) nloop 1 ) ;(setq col_id (rem num 7) ; sqr_plate ; (cond ((= col_id 0) "white_plate3") ; ((= col_id 1) "red_plate3") ; ((= col_id 2) "yel_plate3") ; ((= col_id 3) "green_plate3") ; ((= col_id 4) "cyan_plate3") ; ((= col_id 5) "blue_plate3") ; ((= col_id 6) "magen_plate3") ; (t "white_plate3") ;) ;) (repeat num (my_block_insert sqr_plate pnt_base 1.0) (command "_.array" (entlast) "" "_R" num num 1 1) (setq p0 pnt_base p1 (shift_pnt p0 (list num 0)) p2 (shift_pnt p0 (list num num)) p3 (shift_pnt p0 (list 0 num)) p4 (shift_pnt p0 (list (* num num) num)) p5 (shift_pnt p0 (list (* num num) 0)) pnt_base p1 ) (command "_.pline" p0 "_Width" 0.15 "" p3 "") (if (= nloop 1) (progn (command "_.pline" p2 "_Width" 0.10 "" p4 "") (command "_.pline" p0 "_Width" 0.2 "" p3 p2 "") (setq nloop (1+ nloop)) (setq p00 p0 p50 p5 ) ) ) ;;;end of if loop ) ;;;repeat loop ) ;;;NXNXN_SQR ;;; ;;;SUM_N ;;; (defun sum_n (num) (setq sum (/ (* num (1+ num)) 2)) ) ;;;SUM_N ;;; ;;;LINE_TEXT ;;; (defun line_text (p1 p2 el string chr_size nh nv / p1e p2e mid_12 dxdy pnt_text text_angle ) (setq p1e (plt p1 p2 el) p2e (plt p2 p1 el) mid_12 (mid_point p1 p2) dxdy (list (* chr_size nh) (* chr_size nv)) pnt_text (shift_pnt mid_12 dxdy) text_angle (rtd (angle p1 p2)) ) (if (/= el 0.0) (progn (make_line_1 "0" 0 p1 p1e) (make_line_1 "0" 0 p2e p2) ) ) (command "_.text" pnt_text chr_size text_angle string "") ) ;;;LINE_TEXT ;;; ;;; (defun final_text (/ dx down left right pnt_right pnt_left mid_left mid_base mid_right down_left down_base down_right title enu pnt_title ) (setq dx (- nstep 1) down (list 0 -3) left (list (- (* dx dx)) 0) right (list (- nstep 1) 0) pnt_right (shift_pnt pnt_base right) pnt_left (shift_pnt pnt_base left) mid_left (shift_pnt pnt_left '(0 -1.5)) mid_base (shift_pnt pnt_base '(0 -1.5)) mid_right (shift_pnt pnt_right '(0 -1.5)) dwn_left (shift_pnt pnt_left down) dwn_base (shift_pnt pnt_base '(0 -2)) dwn_right (shift_pnt pnt_right down) ) (make_line_1 "0" 0 pnt_left dwn_left) (make_line_1 "0" 0 pnt_base dwn_base) (make_line_1 "0" 0 pnt_right dwn_right) ;;texts and lines (line_text mid_left mid_base 0.30 "N x N" 0.75 -2.0 -0.5) (line_text mid_base mid_right 0.25 " N " 0.75 -1.0 -0.5) (line_text dwn_left dwn_right 0.30 "N x (N + 1)" 0.75 -3.0 -0.5) ;;title (setq title "Sum of Cube = 1/4 * (N x (N + 1))^ 2" enu (- nstep 1) pnt_title (list -16 (+ 1.5 (* 0.5 enu (+ enu 1)))) ) (textdisplay title pnt_title 1.5 0.) (command "_.zoom" "_EXTENT") ) ;;; ;;; ;;; (defun copy_stair_block (/ deg_270) (while EL1 (ssadd EL1 ss1) (setq EL1 (entnext EL1)) ) (command "_.copy" ss1 "" '(0 0) "") (command "_.block" "qtr_unit" '(0 0) ss1 "") (command "_.layer" "_Set" "layer1" "") (command "_.insert" "qtr_unit" "0,0" "" "" 90.) (IF (= JPG_YES 1) (make_jpg) ) (command "_.delay" 1500) (command "_.layer" "_Set" "layer2" "") (command "_.insert" "qtr_unit" "0,0" "" "" 180.) (IF (= JPG_YES 1) (make_jpg) ) (command "_.delay" 1500) (command "_.layer" "_Set" "layer3" "") (command "_.insert" "qtr_unit" "0,0" "" "" 270.) (setq deg_270 (entlast)) (IF (= JPG_YES 1 1) (make_jpg) ) (command "_.draworder" deg_270 "" "_Back") (command "_.delay" 1500) (command "_.layer" "_Set" "0" "") ) ;;; ;;;