(prompt "\nAngle Trisection by AutoCAD - CARP_SQUARE.lsp") (prompt "\nCommands: TEST DETAIL_TEST CARPENTER_SQUARE ANIMATION_Carpsqr") (prompt "\nFunctions: (SETUP)(SEL_CORNER)(ABET_SETUP)(IS_VALID)(GET_VALUE)(RESET)") (prompt "\n (DISPLAY_RESULT)(FINISH)(INIT_DISPLAY)(DRAW_CURVE_2)(POST_PROC)") (prompt "\n (FINISH_3)(ABET_SETUP_4)(DRAW_CURVE_3)(DEF_ANGLE)(DEF_CARP_SQR)") (prompt "\n (DEF_TOMAHAWK)") ;---------------------------------------------------------- ;Copied from Carp_Sqr.lsp--->Changed radius from 6.5 to 1.0 ; April 11,2006 Takaya Iwamoto ;Tri_section of angle using Carpernter's square (ref. The Trisectors by Underwood Dudley) ;;;Carpenter's Square ;Interactive search trial (defun c:TEST() (setup_carpsqr) ;setup parameters (def_angle) ;specify the angle to be tri_sected ;(make_line_1 "0" 8 '(-3 2) '(8 2) ) (setq last_ent nil) (while ( setq pnt_temp (getpoint "\nSelect a point on the line (y=2), Hit return key to terminate." )) (setq x_temp (car pnt_temp) num (* 2 ref_dim x_temp) denom (- (* x_temp x_temp) (* ref_dim ref_dim)) theta_rad (atan (/ num denom)) theta (rtd theta_rad) pnt_new (list x_temp ref_dim) ) (if (/= last_ent nil) (entdel last_ent)) (command "_insert" "carp_sqr" pnt_new 1.0 1.0 theta) (setq last_ent (entlast)) (show_status) ;;;display the distance to the line ) (reset_sysvar) (prompt "\nZoom and use \"detail_test\" for more precision test.")(terpri) ) (defun c:detail_test() (setup_sysvar) (alert "Click left mouse to move the RED point.\nHit return key to stop.\nLook at the number in the status window.") (while (setq pnt_temp (getpoint) ) (setq pnt_old pnt_temp) (setq x_0 (car pnt_temp) y_0 (cadr pnt_temp) k_1 (+ ref_dim y_0) k_2 (- (* 3 ref_dim) y_0) ) (setq x_temp (+ x_0 (sqrt (* k_1 k_2))) num (* 2 ref_dim x_temp) denom (- (* x_temp x_temp) (* ref_dim ref_dim)) theta_rad (atan (/ num denom)) theta (rtd theta_rad) pnt_new (list x_temp ref_dim) ) (if (/= last_ent nil) (entdel last_ent)) (command "_insert" "carp_sqr" pnt_new 1.0 1.0 theta) (setq last_ent (entlast)) (show_status) ;;;display the distance to the line ) (reset_sysvar) );TEST ;;; (defun SHOW_STATUS( / cur_dist ) ;redfine pnt_temp (setq pnt_temp (polar pnt_new (+ half_pai theta_rad) (* 2. ref_dim))) (setq cur_dist (norm_2_line pnt_org pnt_angle pnt_temp) result (strcat "dist = " (rtos cur_dist 2 12)) ) (move_bar CUR_dist meter_scale) ;;(grtext -1 result) );SHOW_STATUS ;;; ;;;CARPENTER_SQUARE ;;; (defun C:CARPENTER_SQUARE() (setup_carpsqr) ;setup parameters ;define block named "carp_sqr" (def_angle) ;specify the angle to be tri_sected (init_display) ;set initial position (setq flag "GO" dx 0. dy 0 count 0) (command "_.zoom" "e" ) (alert "Click left mouse to start.") (setq answer (getpoint "\nTry to place the red point on the line defined. \nThe process will terminate when the point is within \na specified distance.")) (command "_.vports" "2" "h") ;;;2 Horizontal view ports (command "_.zoom" "w" lower_left upper_right) (while (= flag "GO") (while (and (setq key (grread T)) (= (car key) 5) ) (setq pnt_temp (cadr key)) (if (= count 0) (setq dx 0) (progn (setq y_0 (abs (cadr pnt_temp))) (setq dx (sqrt (* (+ ref_dim y_0) (- (* 3 ref_dim) y_0)))) ) ) (locate pnt_temp dx dy) (block_display) (show_status) );inner while loop ;;;;compute the location of point P (setq pnt_p (polar pnt_new (+ half_pai theta_rad) (* 2 ref_dim))) ;;;;convergence criteria check (if (= (converge) T) (setq flag "STOP")) ;;;;zoom and regen (zoom_regen) (setq count (1+ count)) );outer while loop (command "_.vports" "SI" ) ;;;back to the single view port (command "_.zoom" "_EXTENT") (result_display) (reset_sysvar) );CARPENTER_SQUARE ;;; ;;;LOCATE ;;; ;;;based on the current cursor position, compute the insert point and angle ;;;the offset dx dy can be specified (defun LOCATE(pnt_temp dx_off dy_off / num denom x_temp y_temp) (setq x_temp (+ (car pnt_temp) dx_off) y_temp (+ (cadr pnt_temp) dy_off) num (* (* 2 ref_dim) x_temp) denom (- (* x_temp x_temp) (* ref_dim ref_dim)) theta_rad (atan (/ num denom)) theta (rtd theta_rad) pnt_new (list x_temp ref_dim) ) );LOCATE ;;; ;;;BLOCK_DISPLAY ;;; ;;;display block named carp_sqr (defun BLOCK_DISPLAY( ) (if (/= last_ent nil) (entdel last_ent)) (command "_.insert" "carp_sqr" pnt_new 1.0 1.0 theta) (setq last_ent (entlast)) );BLOCK_DISPLAY ;;; ;;;CONVERGE ;;; ;;;check the convergence compputing the distance from point P to the line OA. (defun CONVERGE( / result) (setq test_length (abs (norm_2_line pnt_org pnt_angle pnt_p)) ) (if (< test_length criteria) (setq result T) (setq result nil)) );CONVERGE ;;; ;;;ZOOM_REGEN ;;; (defun ZOOM_REGEN( / delta x_d y_d lower_left upper_right) (setq delta (* 1.0 test_length) x_d (car pnt_p) y_d (cadr pnt_p) lower_left (list (- x_d delta) (- y_d delta)) upper_right (list (+ x_d delta) (+ y_d delta)) ) (command "_.zoom" lower_left upper_right) (command "_.regen") );ZOOM_REGEN ;;; ;;;SETUP_CARPSQR ;;; (defun SETUP_carpsqr() (setup_sysvar) (set_txstyle "arial") (setvar "PDMODE" 34) (setvar "PDSIZE" -3) (setq ref_dim 0.3 chr_size 0.07 mark_size 0.06 criteria 1.e-9 ;;criteria for target accuracy ) (def_block) (setq lower_left '(-0.4 -0.5) upper_right '(1.1 1)) (make_line_1 "layer8" 8 (setq pnt_org '(0 0)) (setq pnt_b '(1.0 0)) ) (make_line_1 "layer8" 8 '(1 0) '(1 1)) (make_line_1 "layer8" 8 '(1 1) '(0 1)) (make_line_1 "layer8" 8 '(0 1) '(0 0)) ;;;------------------------------------------------------------- ;;;insert precision_meter ;block insert prec_meter.dwg (setq ins_pnt '(-0.25 -0.50) meter_scale 0.35 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 ;;;------------------------------------------------------------- (regapp "my_point") (make_point "layer8" 0 pnt_org "O" 3 chr_size) (make_point "layer8" 0 pnt_b "B" 4 chr_size) (make_line_1 "0" 8 (list 0 ref_dim) (list 1.0 ref_dim) ) );SETUP_carpsqr ;;; ;;;DEF_BLOCK ;;; ;;;define a block named "carp_sqr" ;;;this block will be used for trisection (defun DEF_BLOCK() (def_CarpSqr ref_dim) );DEF_BLOCK ;;; ;;; ;;;DEF_TOMAHAWK ;define a block named "Carp_Sqr" ;this block will be used for trisection ;;;usage : (command "_insert" "Carp_Sqr" pnt_new 1.0 1.0 theta) (defun DEF_CARPSQR(x / pnt_0 pnt_1 pnt_2 pnt_3 pnt_4 pnt_5 pnt_6 x0 x2 x3 x4 pnt_ent_0 pnt_ent_4 hatch_1 pline_1) (setvar "PDSIZE" -3) (command "_.layer" "_set" "layer3" "") (setq x0 ref_dim x2 (* 2 ref_dim) x3 (* 3 ref_dim) x4 (* 4 ref_dim) pnt_0 '( 0 0) pnt_1 (list (- x4) 0) pnt_2 (list 0 x3) pnt_3 (list (- x) x3) pnt_4 (list (- x) x) pnt_5 (list (- x4) x) pnt_6 (list 0 x2) ) (command "_.pline" pnt_1 pnt_0 pnt_2 pnt_3 pnt_4 pnt_5 "_CL") (setq pline_1 (entlast)) (make_pt "layer3" 1 pnt_0) (setq pnt_ent_0 (entlast)) (make_pt "layer3" 1 pnt_6) (setq pnt_ent_6 (entlast)) (command "_.hatch" "_solid" pline_1 "") (setq hatch_1 (entlast)) (command "_.zoom" "_EXTENT" ) (alert "Define this drawing as a block named \"Carp_Sqr\"") (command "_.block" "Carp_Sqr" '(0 0) pline_1 pnt_ent_0 pnt_ent_6 hatch_1 "") (command "_.layer" "_set" "0" "") );DEF_TOMAHAWK ;;; ;;;DEF_ANGLE ;;; ;;;specify the angle to be tri_sected (defun DEF_ANGLE() (setq ref_rad 1.0) (setq half_pai (* 0.5 pi) quart_pai (* 0.25 pi) three_quart_pai (* 0.75 pi) ) (make_arc_cbe "layer8" 8 pnt_org '(1.0 0) '(-0.3521 0.936)) (command "_.zoom" "_EXTENT") (command "_osnap" "_nearest") (setq pnt_angle (getpoint pnt_org "\nPick a point on the circle to define the angle")) (make_line_1 "layer8" 8 pnt_org pnt_angle ) (make_point "0" 0 pnt_angle "A" 2 chr_size) (terpri) );DEF_ANGLE ;;; ;;; ;;;RESULT_DISPLAY ;;;display the results on the drawing window (defun RESULT_DISPLAY( ) (make_point "0" 0 pnt_p "P" 2 chr_size) (make_point "0" 0 pnt_new "S" 2 chr_size) (make_point "0" 0 (setq pnt_q (mid_point pnt_p pnt_new)) "Q" 2 chr_size) (make_point "0" 0 (setq pnt_r (list (car pnt_new) 0)) "R" 4 chr_size) (make_line_1 "layer8" 8 pnt_p pnt_q) (make_line_1 "layer8" 8 pnt_q pnt_new) (make_line_1 "layer8" 8 pnt_new pnt_r) (make_line_1 "layer8" 8 pnt_org pnt_q) (make_line_1 "layer8" 8 pnt_org pnt_new) (mark_angle pnt_r pnt_org pnt_new 0.25 "f" mark_size 1) (mark_angle pnt_new pnt_org pnt_q 0.25 "f" mark_size 2) (mark_angle pnt_q pnt_org pnt_p 0.25 "f" mark_size 2) );RESULT_DISPLAY ;;;INIT_DISPLAY (defun init_display() (setq last_ent nil) (setq init_pos (list 0.5196152 ref_dim));;;the tip is at (0, 0.6) (locate init_pos 0 0) (block_display) (setq last_ent (entlast)) (command "_.zoom" "_extent") );INIT_DISPLAY ;;; ;;;aNIMATION_CARPSQR (75 degree case) ;;; (defun C:animation_carpsqr() (setup_carpsqr) ;setup parameters ;define block named "carp_sqr" (def_angle) ;specify the angle to be tri_sected pick 60 deg. (init_display) ;set initial position ;(make_line_1 "0" 8 '(-2 2) '(6.5 2) ) (command "_.zoom" "e" ) ;(command "_.zoom" "w" lower_left upper_right) (setq end_pos '(0.8242432 0.3) dist (distance init_pos end_pos) nstep 5 del_step (/ 1. (float nstep)) ;;5 steps animation n_cur 1 ) (make_jpg) (alert "\nNext step?") (repeat nstep (setq pnt_temp (plt init_pos end_pos (* n_cur del_step))) (locate pnt_temp 0 0) (block_display) (show_status) (make_jpg) ;;make jpg file (alert "\nNext step?") (command "_.delay" 500) (setq n_cur (1+ n_cur)) );;repeat loop ;;;;compute the location of point P (setq pnt_p (polar pnt_new (+ half_pai theta_rad) (* 2 ref_dim))) (command "_.zoom" "_EXTENT") (result_display) (make_jpg) (reset_sysvar) );;animation_CARPSQR ;;; ;;-------------------------------------------------------------------------- (princ)