;;;Generalized Pythagoren theorem ;; "The sum of the area of two squares,whose sides are the ;; lenghts of the two diagonals of a parallelogram, is equal ;; to the sum of the areas of four squares, whose sides are ;; its four sides." ;; Ref. David S. Wise ;; "Proofs without Words II" , by Roger B. Nelson , page 9. ;; Originally from "Mathematics Magazine, Vol.71, no.1 (Feb 1998), p.64 ;; Programmed by Takaya Iwamoto ;; Nov 2-7 ,2003 ;;;GEN_PYTHAGORAS.LSP ;; (defun c:gen_pythagoras() (setup_genpyth) (draw_squares) (sqr_id) (command "_.zoom" "_E") (command "_.regen") (shaded_pl) (copy_whole) (move_pl) (final_text2) ;;modified (reset_sysvar) );;;GEN_PYTHAGORAS ;;; ;;; (defun setup_genpyth() (setup_sysvar) (setvar "PDMODE" 32) (setvar "PDSIZE" -3) (setq lower_left '(-6 -5) upper_right '(6 5)) (command "_.zoom" "W" lower_left upper_right) (alert "\nDefine your parallelogram ABCD") (parlgrm1) );;; ;draw parallelogram ; pnt1: lower left corner ; pnt3: upper right corner ; theta oblique angle (if = 90. rectangle) ; draw lines counter clock wise. (defun parlgrm1 () ;(alert "\nFirst point A of parallelogram ABCD") (command "_.point" (setq pnt_a '( 0 0)) ) (mark_id pnt_a "A" 3 0.25) ;(command "_.move" (entlast) "" pnt_a PAUSE) ;(command "_.point" (setq pnt_b (getpoint pnt_a "\nSecond corner of rectangle: ")) ) (command "_.point" (setq pnt_b '( 2.75 0)) ) (mark_id pnt_b "B" 3 0.25) ;(command "_.move" (entlast) "" pnt_b PAUSE) (command "_.line" pnt_a pnt_b "") (setq line_ab (entlast)) (command "_.point" (setq pnt_c (getpoint pnt_b "\ndiagonal point C:" )) ) (mark_id pnt_c "C" 3 0.25) ;(command "_.move" (entlast) "" pnt_c PAUSE) (command "_.copy" line_ab "" pnt_b pnt_c) (command "_.point" (setq pnt_d (cdr (assoc 10 (entget (entlast)) ))) ) (entdel line_ab) (command "_.pline" pnt_a pnt_b pnt_c pnt_d "cl") (setq ABCD (entlast)) (mark_id pnt_d "D" 3 0.25) ;(command "_.move" (entlast) "" pnt_d PAUSE) );;; ;;; ;;;DRAW_SQUARES ---draw 4 squares on 4 sides of the parallelogram ;;; (defun draw_squares() (command "polygon" 4 "Edge" pnt_b pnt_a) (setq BAEF (entlast)) (command "polygon" 4 "Edge" pnt_c pnt_b) (setq CBGH (entlast)) (command "polygon" 4 "Edge" pnt_d pnt_c) (setq DCIJ (entlast)) (command "polygon" 4 "Edge" pnt_a pnt_d) (setq ADKL (entlast)) );;; ;;; ;;; (defun sqr_id() (alert "\nMark Grid ID from E to L") (setq rev_list (reverse (entget BAEF)) pnt_f (cdr (nth 4 rev_list)) pnt_e (cdr (nth 8 rev_list)) rev_list (reverse (entget CBGH)) pnt_h (cdr (nth 4 rev_list)) pnt_g (cdr (nth 8 rev_list)) rev_list (reverse (entget DCIJ)) pnt_j (cdr (nth 4 rev_list)) pnt_i (cdr (nth 8 rev_list)) rev_list (reverse (entget ADKL)) pnt_l (cdr (nth 4 rev_list)) pnt_k (cdr (nth 8 rev_list)) ) (mark_id pnt_e "E" 3 0.25) ;(command "_.move" (entlast) "" pnt_e PAUSE) (mark_id pnt_f "F" 3 0.25) ;(command "_.move" (entlast) "" pnt_f PAUSE) (mark_id pnt_g "G" 3 0.25) ;(command "_.move" (entlast) "" pnt_g PAUSE) (mark_id pnt_h "H" 3 0.25) ;(command "_.move" (entlast) "" pnt_h PAUSE) (mark_id pnt_i "I" 3 0.25) ;(command "_.move" (entlast) "" pnt_i PAUSE) (mark_id pnt_j "J" 3 0.25) ;(command "_.move" (entlast) "" pnt_j PAUSE) (mark_id pnt_k "K" 3 0.25) ;(command "_.move" (entlast) "" pnt_k PAUSE) (mark_id pnt_l "L" 3 0.25) ;(command "_.move" (entlast) "" pnt_l PAUSE) (command "_.point" (setq pnt_m (plt pnt_i pnt_j 2.0)) ) (mark_id pnt_m "M" 3 0.25) ;(command "_.move" (entlast) "" pnt_m PAUSE) ;(command "_.copy" pnt_m "" pnt_j pnt_k) (setq pnt_mid_mk (plt pnt_k pnt_m 0.5) pnt_n (plt pnt_j pnt_mid_mk 2.0)) (mark_id pnt_n "N" 3 0.25) ;(command "_.move" (entlast) "" pnt_n PAUSE) (make_line_1 "0" 8 pnt_h pnt_i) (make_line_1 "0" 8 pnt_n pnt_l) (command "_.pline" pnt_n pnt_k pnt_j pnt_m "cl") ;(make_line_1 "0" 8 pnt_h pnt_i) ;(make_line_1 "0" 8 pnt_n pnt_l) );;SQR_ID writing GRID ID ;;; ;;;SHADED_PL ;;; (defun shaded_pl() (setq upper_right (getvar "EXTMAX") lower_left (getvar "EXTMIN") y_b (cadr pnt_b) y_ur (cadr upper_right) l_ab (distance pnt_a pnt_b) l_bc (distance pnt_b pnt_c) del_y (+ l_bc (max y_ur (- y_ur y_b))) new_a (list (- l_bc) del_y) new_b (shift_pnt pnt_b new_a) new_c (shift_pnt pnt_c new_a) new_d (shift_pnt pnt_d new_a) new_aa (list l_ab del_y ) new_bb (shift_pnt pnt_b new_aa) new_cc (shift_pnt pnt_c new_aa) new_dd (shift_pnt pnt_d new_aa) ) (alert "\nTwo ways to divide the parallelogram") (command "_.copy" ABCD "" pnt_a new_a) (setq new_1 (entlast)) (command "_.copy" ABCD "" pnt_a new_aa) (setq new_2 (entlast)) (shaded_triangle "layer5" new_a new_b new_d) (setq new_ABD (entlast)) (shaded_triangle "layer1" new_aa new_bb new_cc) (setq new_ABC (entlast)) (command "_.zoom" "E") (command "_.delay" 1000) (alert "\nFill with shaded triangles and quad") (shaded_triangle "layer5" pnt_k pnt_n pnt_l) (setq KNL (entlast)) (command "_.delay" 500) (shaded_triangle "layer5" pnt_k pnt_j pnt_d) (setq KJD (entlast)) (command "_.delay" 500) (shaded_triangle "layer5" pnt_f pnt_g pnt_b) (setq FGB (entlast)) (command "_.delay" 500) (shaded_triangle "layer1" pnt_l pnt_a pnt_e) (setq LAE (entlast)) (command "_.delay" 500) (shaded_triangle "layer1" pnt_c pnt_h pnt_i) (setq CHI (entlast)) (command "_.delay" 500) (shaded_triangle "layer1" pnt_a pnt_b pnt_c) (setq ABC (entlast)) (command "_.delay" 500) (shaded_triangle "layer1" pnt_c pnt_d pnt_a) (setq CDA (entlast)) (command "_.delay" 500) (shaded_quad "layer3" pnt_k pnt_j pnt_m pnt_n) (setq KJMN (entlast)) (command "_.delay" 500) (command "_.pline" pnt_a "W" 0.02 "" pnt_c "") (command "_.delay" 500) (setvar "PLINEWID" 0.0) );;;SHADED_PL ;;; ;;;COPY_WHOLE ;;; (defun copy_whole( / whole dx) (setq dx (- (car upper_right) (car lower_left))) (alert "\nCopy the whole figure to the right") (setq whole (ssget "C" upper_right lower_left )) (my_block_def "WHOLE_1" lower_left whole) (command "oops") (my_block_insert "WHOLE_1" (shift_pnt lower_left (list dx 0)) 1.0) (command "_.zoom" "E") );;;COPY_WHOLE ;;; ;;;MOVE_PL Move shaded triangles & parallelogram ;;; (defun move_pl( / n_speed ndiv ncolor layer_name n_repeat) (alert "\nMove shaded triangles & parallelogram") (setq n_speed 200 ndiv 6 ncolor 1 layer_name "0" n_repeat 5 ) ;FGB pnt_f to pnt_e (move_ent FGB pnt_f pnt_e n_speed ndiv ncolor layer_name) (command "_.delay" 1000) ;KJMN pnt_k to pnt_f (move_ent KJMN pnt_k pnt_f n_speed ndiv ncolor layer_name) (command "_.delay" 1000) ;KNL pnt_k to pnt_j (move_ent KNL pnt_k pnt_j n_speed ndiv ncolor layer_name) (command "_.delay" 1000) ;KJD pnt_k to pnt_l (move_ent KJD pnt_k pnt_l n_speed ndiv ncolor layer_name) (command "_.delay" 1000) ;ABC pnt_b to pnt_g (move_ent ABC pnt_b pnt_g n_speed ndiv ncolor layer_name) (command "_.delay" 1000) ;CHI rotate around pnt_i by -90. degrees (rotate_ent CHI pnt_i pnt_c -90. n_speed n_repeat ncolor) (command "_.delay" 1000) ;CDA move pnt_d to pnt_a, then 90 deg rotation abput pnt_a (rotate_ent CDA pnt_d pnt_c 90. n_speed n_repeat ncolor) (command "_.delay" 1000) (move_ent CDA pnt_d pnt_a n_speed ndiv ncolor layer_name) (command "_.delay" 1000) );; ;;; ;;;FINAL_TEXT ;;; (defun final_text() (setq dx (- (car upper_right) (car lower_left)) p1 (list (+ (car new_cc) (* 0.5 l_bc)) (cadr upper_right) ) p2 (list (* 1.75 dx) (cadr new_dd) ) text_height (/ (- (cadr new_dd) (cadr upper_right)) 10.) text_loc0(shift_pnt p1 (list text_height (* 8.5 text_height))) ) (command "_.rectangle" p1 p2) ;(setq final_msg (list " The sum of the area of two squares," ; "whose sides are the lengths of the two" ; "diagonals of a parallelogram, is equal" ; "to the sum of the areas of four squares," ; "whose sides are its four sides.") ;) (setq final_msg "A + B = 2 (a + b)") ;(setq nline 0) ;(repeat 5 ; (setq line_text (nth nline final_msg) ; text_loc (shift_pnt text_loc0 (list 0 (- (* 2 nline text_height)))) ; ) ; (textdisplay line_text text_loc 0.75 0. ) ; (setq nline (1+ nline)) ;(princ text_loc)(terpri) ; );;end of repeat (textdisplay final_msg text_loc0 0.75 0.) (command "_.zoom" "E") );; ;;;FINAL_TEXT2 ;;; (defun final_text2() ;draw TEXTS A,B,a b for area identification (setq dx (- (car upper_right) (car lower_left)) p1 (list (+ (car new_cc) (* 0.2 l_bc)) (cadr new_aa) ) p2 (list (* 1.55 dx) (cadr new_dd) ) text_height (/ (abs (- (cadr new_dd) (cadr new_bb) ) ) 2.5) text_loc (shift_pnt p1 '(0.1 0.2)) dx (- dx text_height) ) (setq mid_lm (plt pnt_l pnt_m 0.5) mid_cj (plt pnt_c pnt_j 0.3) mid_af (plt pnt_a pnt_f 0.6) mid_ak (plt pnt_a pnt_k 0.4) mid_cg (plt pnt_c pnt_g 0.6) pnt_cj (shift_pnt mid_cj (list dx 0)) pnt_af (shift_pnt mid_af (list dx 0)) pnt_ak (shift_pnt mid_ak (list dx 0)) pnt_cg (shift_pnt mid_cg (list dx 0)) ) (command "_.rectangle" p1 p2) ;;change color to yellow (set_color "yellow") (textdisplay "A" mid_lm text_height 0.) (textdisplay "B" mid_cj text_height 0.) (textdisplay "a" pnt_af text_height 0.) (textdisplay "a" pnt_cj text_height 0.) (textdisplay "b" pnt_ak text_height 0.) (textdisplay "b" pnt_cg text_height 0.) (setq final_msg "A + B = 2 (a + b)") (textdisplay final_msg text_loc text_height 0.) (command "_.zoom" "E") (set_color "BYLAYER") );;