(prompt "\nAngle Trisection by AutoCAD - LAISANT_2.LSP") (prompt "\nCommands: TEST_Laisant_2 LAISANT_2") (prompt "\nFunctions: (INIT_DISPLAY) (LOCATE) (SETUP) (SHOW_RESULT) (RESET) (DISPLAY_NODES) ") (prompt "\n (SHOW_STATUS) (PL_DISPLAY) (CONVERGE) (ZOOM_REGEN) (DEF_ANGLE)") ;---------------------------------------------------------- ; ;renanmed link_5--->laisant_2 4/27/2006 ;;; (defun C:TEST_Lasant_2() ;Main routine (setup) ;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)) );;;while loop (c:display_nodes) (show_result) (reset_sysvar) );;;TEST_1 ;;; ;;;LAISANT_2 ;;;main routine ::: zoom & regen is done automatically (defun c:LAISANT_2() (setup) ;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 3 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_a 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) (command "_.zoom" "_EXTENT") (reset_sysvar) );LAISANT_2 ;;; ;;;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 upper 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 lower 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_c pnt_a) 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) ) ;; (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 T, U & V (setq pnt_t (point_sym_line pnt_p pnt_q pnt_r) pnt_u (point_sym_line pnt_t pnt_r pnt_q) ) ;; point C & D (setq pnt_c (polar pnt_p (angle pnt_p pnt_t) 2.5) pnt_d (polar pnt_p (angle pnt_p pnt_q) 2.5) ) ) (defun pl_display() (command "_.pline" pnt_c pnt_p pnt_d pnt_u pnt_t pnt_q pnt_u pnt_r pnt_q pnt_p pnt_b pnt_s pnt_r "") ) ;setup (defun setup() (setup_sysvar) (def_angle) (set_txstyle "arial") (setq half_pi (* 0.5 pi) quart_pi (* 0.25 pi) ref_angle (* 0.75 pi) pnt_p '(0 0) pnt_b '(2.25 0) pnt_size 0.10 mark_size 0.08 criteria 1.e-8 ) ;(set_layer) (setvar "PDMODE" 32) (setvar "PDSIZE" -2) (command "_.point" pnt_p) ;;;----------------------------------------------------------- ;;;insert precision_meter ;block insert prec_meter.dwg (setq ins_pnt '(-1.0 -0.75) meter_scale 0.70 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 "_.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) '(-1.41421356 1.41421356)) ;(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") ) ;; ;; ;; (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_c "C" 1 0.10) (make_point "0" 0 pnt_d "D" 1 0.10) (make_point "0" 0 pnt_p "P" 3 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" 1 0.10) (make_point "0" 0 pnt_t "T" 1 0.10) (make_point "0" 0 pnt_u "U" 2 0.10) );;; ;;; ;;;ANIMATION_LAISANT_2 ;;;call jpg_setup(output_filename) before running this executable. ;;;Do not forget to set jpg_yes on (=1) ;;; (defun C:animation_laisant_2() ;Main routine (setup) ;set up (init_display) ;(command "_.zoom" "_E") ;(command "_.regen") (setq end_pos '(1.34202014 0.93969262) dist (distance init_pos end_pos) nstep 5 del_step (/ 1. (float nstep)) ;;5 steps animation n_cur 1 ) (make_jpg) (alert "\nNext step?") (entdel new_pnt_ent) (entdel new_txt_ent) (repeat nstep (setq pnt_tmp (plt init_pos end_pos (* n_cur del_step))) (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)) );;;repeat loop (c:display_nodes) (make_jpg) (show_result) (make_jpg) (make_jpg) (reset_sysvar) );;;ANIMATION_LAISANT_2 ;;; ;;-------------------------------------------------------------------------- (princ)