(prompt "\nAngle Trisection by AutoCAD - GEN_SECT.LSP") (prompt "\nCommands: TRI_SECT TRISECT_BY_SERIES") (prompt "\nFunctions: (SETUP) (DIVIDE) (FINISH) (STATUS_REPORT) (SETUP_DIALOG)") (prompt "\n ") ;---------------------------------------------------------- ;General scheme for trisecting any given angle 2/12/98 ;;; based on infinite series ;Sn = 1/4 + 1/16 + 1/64 + ....+ 1/4^n ;The limit as n -> infinity is 1/3. ;;;update ;;; April 17,2006 changed tri_sect_2 --->trisect_by_series ;gen_sect.lsp ;;;main routine ;;;TRI_SECT (defun C:TRI_SECT() ;main routine (setup) (setq p1 pnt_xaxis p2 pnt_new) ;start (setq ncount 0) (while (= stop_now 0) (divide p1 p2) ;pick a point on the circle (setq p1 new_pnt1 p2 new_pnt2) (setq ncount (1+ ncount)) (status_report) ;;; This is for interactive option (if (= option 2) (progn (initget "Yes No") (setq response (getkword "\nWant to continue ?(Yes/No) :")) (if (= response "No") (setq stop_now 1)) ) );end of if loop ) ;end of while loop (finish) ;finishing touch );TRI_SECT ;;; ;;;main routine ;;;TRISECT_BY_SERIES (defun C:TRISECT_BY_SERIES() ;main routine (setup_series) (setq option 2) (setq n_repeat (getint "\nHow many steps (def = 6)")) (if (= n_repeat nil) (setq n_repeat 6)) (setq p1 pnt_xaxis p2 pnt_new) ;start (setq ncount 0) (repeat N_repeat (divide p1 p2) ;pick a point on the circle (setq p1 new_pnt1 p2 new_pnt2) (setq ncount (1+ ncount)) (status_report) ;;; This is for interactive option (if (= option 2) (progn (initget "Yes No") (setq response (getkword "\nWant to continue ?(Yes/No) :")) (if (= response "No") (setq stop_now 1)) ) );end of if loop ) ;end of while loop (finish) ;finishing touch );TRI_SECT ;;; ;report the current value (defun STATUS_REPORT() (setq sum (+ sum (expt 0.25 ncount))) (setq current (rtos sum 2 16)) (setq deviation (abs (- third sum))) (move_bar deviation meter_scale) ;(grtext -1 current ) ;status line area display );STATUS_REPORT ;given two points draw a half & a quarter line (defun DIVIDE(p1 p2 / ang1 ang2 ang_dif ang_half ang_quart ) (setq ang1 (angle pnt_cnt p1) ang2 (angle pnt_cnt p2) ang_dif (- ang2 ang1) ang_half (+ ang1 (* ang_dif 0.5)) ang_quart (+ ang1 (* ang_dif 0.25)) ) (setq new_pnt1 (polar pnt_cnt ang_quart radius) new_pnt2 (polar pnt_cnt ang_half radius)) (command "_.layer" "_set" "layer5" "") ;point2 in blue (command "_.line" pnt_cnt new_pnt2 "") (command "_.point" new_pnt2) (command "_.text" '(-2.25 -0.75) "0.15" "0.0" blue_line) (command "_.text" '(-2.25 -1.75) "0.15" "0.0" status_line) (command "_.layer" "_set" "0" "") (command "_.layer" "_set" "layer1" "") ;point1 in red (command "_.line" pnt_cnt new_pnt1 "") (command "_.text" '(-2.25 -1.25) "0.15" "0.0" red_line) (command "_.point" new_pnt1) (command "_.layer" "_set" "0" "") (if (< (distance new_pnt1 new_pnt2) cut_off) (setq stop_now 1)) );DIVIDE ;;; ;setup (defun SETUP() (setq stop_now 0 sum 0.0 red_line "Red ----> quarter-section" blue_line "Blue ----> half-section" status_line "Look at the level of approximation in status line (bottom left)" ) (setup_dialog) ;dialog box to setup cutoff criteria ;(set_layer) (setvar "PDMODE" 32) (command "_.point" (setq pnt_cnt '(0 0))) (command "_.layer" "_set" "layer8" "") (command "_circle" pnt_cnt (setq radius 2.5)) (command "_.line" '(-2.5 0) pnt_cnt (setq pnt_xaxis '(2.5 0)) "") (command "_.layer" "_set" "0" "") (command "_.zoom" "_EXTENT" ) (command "_.regen") (command "_osnap" "_Nearest") (setq pnt_new (polar pnt_cnt (getangle pnt_cnt "\nDefine an angle by Selecting a point on a circle:") radius) ) (command "_.point" pnt_new) (command "_osnap" "_NONe") (command "_.line" pnt_cnt pnt_new "") );SETUP ;;; ;setup _series (defun SETUP_SERIES() (setq stop_now 0 third (/ 1. 3.) sum 0.0 red_line "Red ----> quarter-section" blue_line "Blue ----> half-section" status_line "Look at the level of approximation in status line (bottom left)" ) ;(setup_dialog) ;dialog box to setup cutoff criteria ;(set_layer) (setvar "PDMODE" 32) ;;;------------------------------------------ ;;;insert precision_meter ;block insert prec_meter.dwg (setq ins_pnt '(0.5 -1.) meter_scale 0.80 m_x (car ins_pnt) m_y (cadr ins_pnt) pm_factor (* 0.25 (/ 1. (log 10.))) ) (my_block_insert "prec_meter" ins_pnt meter_scale) ;display initial bar (my_block_insert "prec_bar" ins_pnt meter_scale) (setq old_bar (entlast)) ;;;prec_bar just created ;;;------------------------------------------ (command "_.point" (setq pnt_cnt '(0 0))) (command "_.layer" "_set" "layer8" "") (command "_circle" pnt_cnt (setq radius 2.5)) (command "_.line" '(-2.5 0) pnt_cnt (setq pnt_xaxis '(2.5 0)) "") (command "_.layer" "_set" "0" "") (command "_.zoom" "_EXTENT" ) (command "_.regen") (command "_osnap" "_Nearest") (setq pnt_new (polar pnt_cnt (getangle pnt_cnt "\nDefine an angle by Selecting a point on a circle:") radius) ) (command "_.point" pnt_new) (command "_osnap" "_NONe") (command "_.line" pnt_cnt pnt_new "") );SETUP ; (defun SETUP_DIALOG() (setq dcl_id (load_dialog "gen_sect.dcl")) (if (not (new_dialog "setup" dcl_id)) (exit)) (setq lim_x (dimx_tile "screen") lim_y (dimy_tile "screen")) (start_image "screen") (slide_image 0 0 lim_x lim_y "gen_sect") (end_image) (set_tile "criteria" "0.000001") (action_tile "auto_search" "(setq option 1)") (action_tile "interactive" "(setq option 2)") (action_tile "cancel" "(done_dialog) (exit)") (action_tile "accept" "(setq cut_off (atof (get_tile \"criteria\"))) (done_dialog)") (start_dialog) (unload_dialog dcl_id) );SETUP_DIALOG ;;; ;finishing touch (defun FINISH() (command "_.point" new_pnt1) (command "_.line" pnt_cnt new_pnt1 "") (setq layoff_ok (getint "\nHit return to hide red & blue lines.")) (command "_.layer" "_OFF" "layer1" "_OFF" "layer5" "") (setq str_1 "Result after " str_2 " steps:" str_3 "given angle: " str_4 "result angle: " str_5 "ratio = " str_6 "(deg)" str_7 "given" str_8 "result" ) (setq mid_given (polar pnt_cnt (angle pnt_cnt pnt_new) 1.25) mid_result (polar pnt_cnt (angle pnt_cnt new_pnt1) 1.25) ) (setq iteration (itoa ncount) given (rtos (rtd (angle pnt_cnt pnt_new)) 2 10) result (rtos (rtd (angle pnt_cnt new_pnt1)) 2 10) ratio (rtos (/ 1. sum) 2 10) ) (setq title (strcat (strcat str_1 iteration) str_2) sub_given (strcat (strcat str_3 given) str_6) sub_result (strcat (strcat str_4 result) str_6) sub_ratio (strcat str_5 ratio) ) (command "_style" "arial" "arial" "" "" "" "" "") (command "_.text" '(-2.45 -0.95) "0.20" "0.0" title) (command "_.text" '(-1.95 -1.45) "0.20" "0.0" sub_given) (command "_.text" '(-1.95 -1.95) "0.20" "0.0" sub_result) (command "_.text" '(-1.95 -2.45) "0.20" "0.0" sub_ratio) (command "_.layer" "_set" "layer2" "") (command "_.text" mid_given "0.15" "0.0" str_7) (command "_.text" mid_result "0.15" "0.0" str_8) (command "_.layer" "_set" "0" "") );FINISH ;------------------------------------------------------------------- ;;;Animation files main routine ;;;ANIMATION_SERIES (defun C:ANIMATION_SERIES() ;main routine (setup_series) (setq option 2) ;(setq n_repeat (getint "\nHow many steps (def = 6)")) ;(if (= n_repeat nil) (setq n_repeat 6)) (make_jpg) (command "_.delay" 500) (setq n_repeat 6) (setq p1 pnt_xaxis p2 pnt_new) ;start (setq ncount 0) (repeat N_repeat (divide p1 p2) ;pick a point on the circle (setq p1 new_pnt1 p2 new_pnt2) (setq ncount (1+ ncount)) (status_report) (make_jpg) (command "_.delay" 500) ;;; This is for interactive option (if (= option 2) (progn (initget "Yes No") (setq response (getkword "\nWant to continue ?(Yes/No) :")) (if (= response "No") (setq stop_now 1)) ) );end of if loop ) ;end of while loop (make_jpg) (command "_.delay" 500) (finish) ;finishing touch (make_jpg) );ANIMATION_SERIES (princ)