(prompt "\nAngle Trisection by AutoCAD - LAISANT.LSP") (prompt "\nCommands: TEST_Laisant LAISANT ANIMATION_LAISANT") (prompt "\nFunctions: (INIT_DISPLAY) (LOCATE) (SETUP) (SHOW_RESULT) (RESET) (DISPLAY_NODES) ") (prompt "\n (SHOW_STATUS) (PL_DISPLAY) (CONVERGE) (ZOOM_REGEN) (DEF_ANGLE)") ;---------------------------------------------------------- ;link test #5 6/27/99 Takaya Iwamoto ; (defun C:TEST_Laisant() ;Main routine (setup_laisant) ;set up (init_display) (alert "Place the cursor near the point \"R\", then click left mouse to start.") (setq answer (getpoint "\nPress left mouse to start.Click mouse to stop."))(terpri) (entdel new_pnt_ent) (entdel new_txt_ent) (while (and (setq key (grread T)) (= (car key) 5) ) (setq pnt_tmp (cadr key)) (entdel last_pline) (locate pnt_tmp) (pl_display) (setq last_pline (entlast)) (show_status) );;;while loop (c:display_nodes) (show_result) (reset_sysvar) );TEST ;;; ;;;LAISANT ;;;main routine ::: zoom & regen is done automatically (defun c:LAISANT() (setup_laisant) ;setup parameters ;specify the angle to be tri_sected (init_display) ;set initial position (alert "Place the cursor near the point \"R\", then click left mouse to start.") (setq answer (getpoint "\nMove the mouse and Press left mouse for automatic zooming and regen.")) (terpri) (entdel new_pnt_ent) (entdel new_txt_ent) (setq flag "GO" split_win "NO") (while (= flag "GO") (while (and (setq key (grread T)) (= (car key) 5) ) (setq pnt_tmp (cadr key)) (entdel last_pline) (locate pnt_tmp) (pl_display) (setq last_pline (entlast)) (show_status) );inner while loop ;;;after the 2-nd round,work with 2 viewports. ;(if (= split_win "NO") (command "_.vports" "2" "v")) (if (= split_win "NO") (progn (command "_.vports" "3" "_L") (setvar "CVPORT" 2) (command "_.zoom" "_E") (setvar "CVPORT" 3) (command "_.zoom" "_E") (setvar "CVPORT" 4) (command "_.zoom" "_E") ) ) ;;;;convergence criteria check (if (= (converge) T) (setq flag "STOP")) ;;;;zoom and regen automatically for 2 viewports (zoom_regen pnt_t pnt_r ) (setq split_win "YES") );outer while loop (command "_.vports" "SI" ) ;;;back to single view port (command "_.zoom" "_EXTENT") (c:display_nodes) (show_result) (reset_sysvar) );LAISANT_3 ;;; ;;;CONVERGE ;;; ;;;check the convergence by computing distance between pnt_ref & pnt_g. (defun CONVERGE( / result) ;(setq test_length (abs (distance pnt_ref pnt_g))) (if (< (abs test_length) criteria) (setq result T) (setq result nil)) );CONVERGE ;;; ;;;ZOOM_REGEN ;;; (defun ZOOM_REGEN(pnt_target pnt_move) ;;;Target point (setq vscale (/ vscale 5.)) ;;;focus on the target pnt window ;(setvar "CVPORT" 2) (setvar "CVPORT" 3) (command "_.zoom" "ce" pnt_target vscale) (command "_.regen") ;;;Mouse control point (setq vscale (/ vscale 5.)) ;;;focus on the control pnt window ;(setvar "CVPORT" 3) (setvar "CVPORT" 4) (command "_.zoom" "ce" pnt_move vscale) (command "_.regen") );ZOOM_REGEN ;;; ;;;SHOW_STATUS ;;; show the deviation from the exact solution in status line (defun SHOW_STATUS( / result) (setq test_length (norm_2_line pnt_p pnt_a pnt_t) result (strcat "dist = " (rtos test_length 2 12)) ) (move_bar test_length meter_scale) ;(grtext -1 result) );SHOW_STATUS ; (defun INIT_DISPLAY() (setq init_pos '(1.80118 0.767236 0)) (locate init_pos) (pl_display) (setq last_pline (entlast)) (regapp "my_point") (make_point "0" 0 pnt_r "R" 2 pnt_size) );INIT_DISPLAY ;; (defun SHOW_RESULT() ;;draw lines with different colors (make_line_1 "0" 8 pnt_p pnt_r) ;(c:display_nodes) (mark_angle pnt_t pnt_p pnt_u 0.30 "f" mark_size 2) (mark_angle pnt_q pnt_p pnt_r 0.25 "f" mark_size 2) (mark_angle pnt_r pnt_p pnt_s 0.30 "f" mark_size 1) (mark_angle pnt_a pnt_p pnt_b 0.45 "3f" mark_size 1) );SHOW_RESULT ;locate the point to satisfy the condition (defun locate(pnt_tmp) (setq check_angle (angle pnt_p pnt_tmp)) (if (> check_angle quart_pi) (setq check_angle quart_pi)) (setq a (tan check_angle) denom (+ (* a a) 1.0) x_r (/ 2.0 denom) y_r (* a x_r) pnt_r (list x_r y_r) ) (if (> (distance pnt_p pnt_r) 2.0) (setq pnt_r (polar pnt_p (angle pnt_p pnt_r) 2.0)) ) (setq dist_pr (distance pnt_p pnt_r) half_el (* 0.5 dist_pr) ratio_1 (/ 1.0 dist_pr) ratio_2 (/ dist_pr 1.0) ) (if (<= half_el 1.0) (setq proj (sqrt (- 1.0 (* half_el half_el))) ) (setq proj 0.0) ) ;; point Q & S(fixed now) (setq pnt_q (point_off_line pnt_p pnt_r 0.5 half_pi proj)) (setq pnt_s '(1 0)) ;; point U is on the line PQ (setq pnt_u (point_along_line pnt_p pnt_q 1.75)) ;; P1 & P2 are the end points of perpendicular bisector of line UR (setq pnt_p1 (point_off_line pnt_r pnt_u 0.5 (- half_pi) 0.5) pnt_p2 (point_off_line pnt_r pnt_u 0.5 half_pi 0.5) pnt_f (point_sym_line pnt_p1 pnt_p2 pnt_q) ) ;;point H is on line UF (setq pnt_h (point_along_line pnt_u pnt_f (/ 9. 16.))) ;;point G is the the symmetric point of point U wrt the bisector of HQ ;; P1 & P2 are the end points of perpendicular bisector of line UR (setq pnt_p1 (point_off_line pnt_q pnt_h 0.5 (- half_pi) 0.5) pnt_p2 (point_off_line pnt_q pnt_h 0.5 half_pi 0.5) pnt_g (point_sym_line pnt_p1 pnt_p2 pnt_u) ) ;;point T is on the line QG (setq pnt_t (point_along_line pnt_q pnt_g (/ 16. 9.))) ) (defun pl_display() (command "_.pline" pnt_h pnt_u pnt_q pnt_t pnt_g pnt_h pnt_f pnt_r pnt_q pnt_p pnt_s pnt_r "") ) ;setup (defun setup_laisant() (setup_sysvar) (def_angle) (set_txstyle "arial") ;; ;;;insert precision_meter ;block insert prec_meter.dwg (setq ins_pnt '(-1.5 -1.) meter_scale 0.8 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 ;; (setq half_pi (* 0.5 pi) quart_pi (* 0.25 pi) ref_angle (* 0.75 pi) pnt_p '(0 0) pnt_b '(2.0 0) pnt_size 0.10 mark_size 0.08 criteria 1.e-8 ) ;(set_layer) (setvar "PDMODE" 32) (setvar "PDSIZE" -2) (textdisplay "A" pnt_a 0.1 0.) (textdisplay "B" pnt_b 0.1 0.) (command "_.point" pnt_p) (command "_.zoom" "_EXTENT") (setq vscale (getvar "viewsize"));;;GET CURRENT VIEW SIZE ) ;; ;; (defun def_angle() (make_arc_cbe "0" 8 (setq pnt_org '(0 0)) '(2 0) '(-2 0)) ;(make_pt "0" 8 '(3 2.5)) ;(make_pt "0" 8 '(-2 2.5)) (command "_osnap" "_nearest") (command "_.zoom" "_EXTENT") (command "_.regen") (alert "Select a point on the arc to define an angle") (make_line_1 "0" 3 pnt_org (setq pnt_a (getpoint pnt_org "\nDefine a point \"X\":")) ) (make_pt "0" 3 pnt_a) (command "_osnap" "None") );DEF_ANGLE ;; ;; (defun c:reset() (command "_.erase" "all" "") );RESET ;; ;; (defun c:display_nodes() (regapp "my_point") ;(make_point "0" 0 pnt_a "A" 2 0.10) ;(make_point "0" 0 pnt_b "B" 1 0.10) (make_point "0" 0 pnt_g "G" 1 0.10) (make_point "0" 0 pnt_h "H" 1 0.10) (make_point "0" 0 pnt_p "P" 4 0.10) (make_point "0" 0 pnt_q "Q" 2 0.10) (make_point "0" 0 pnt_r "R" 1 0.10) (make_point "0" 0 pnt_s "S" 4 0.10) (make_point "0" 0 pnt_t "T" 1 0.10) (make_point "0" 0 pnt_u "U" 2 0.10) );DISPLAY_NODES ;;; ;;; ;;;ANIMATION_LAISANT input angle @2<120. ;;; ;;;main routine fro creating a series of jpg files for animation (defun c:ANIMATION_LAISANT() (setup_laisant) ;setup parameters ;specify the angle to be tri_sected (init_display2) ;set initial position (setq init_deg 25. end_deg 40.00001 pnt_end (polar '(0 0) (dtr 40.) 2.) deg_del (- end_deg init_deg) ;;=20. degrees nstep 5 deg_step (/ deg_del (float nstep)) ;;5 steps animation n_cur 1 ) (make_jpg) (alert "\nNext step?") (entdel new_pnt_ent) (entdel new_txt_ent) (repeat nstep (setq cur_deg (+ init_deg (* n_cur deg_step)) pnt_tmp (polar '(0 0) (dtr cur_deg) 2.) ) (entdel last_pline) (locate pnt_tmp) (pl_display) (setq last_pline (entlast)) (show_status) (make_jpg) ;;make jpg file (alert "\nNext step?") (command "_.delay" 500) (setq n_cur (1+ n_cur)) );;;end of repeat loop (command "_.zoom" "_EXTENT") (c:display_nodes) (make_jpg) (command "_.delay" 500) (show_result) (make_jpg) (command "_.delay" 500) (reset_sysvar) );ANIMATION_LAISANT ;;; ; (defun INIT_DISPLAY2() (setq init_pos (polar '(0 0) (dtr 23.) 2.)) (locate init_pos) (pl_display) (setq last_pline (entlast)) (regapp "my_point") (make_point "0" 0 pnt_r "R" 2 pnt_size) );INIT_DISPLAY2 ;;-------------------------------------------------------------------------- (princ)