(prompt "\nAngle Trisection by AutoCAD - LAISANT_1.LSP") (prompt "\nCommands: TEST_Laisant_1 LAISANT_1") (prompt "\nFunctions: (INIT_DISPLAY) (LOCATE) (SETUP) (SHOW_RESULT) (RESET) (DISPLAY_NODES) ") (prompt "\n (SHOW_STATUS) (PL_DISPLAY) (CONVERGE) (ZOOM_REGEN) (DEF_ANGLE)") ;---------------------------------------------------------- ;link test #4 6/27/99 Takaya Iwamoto ;renamed link_4.lsp --->Laisant_1.lsp 4/27/2006 ;; (prompt "\nLoading test_Laisant_1")(terpri) ;;;TEST_1 (defun C:TEST_Laisant_1() ;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 ;;; (prompt "\nLoading Laisant_1")(terpri) ;;; ;;;LAISANT_1 ;;;main routine ::: zoom & regen is done automatically (defun c:LAISANT_1() (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_ref 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) (c:z_e) ;;;zoom extent (reset_sysvar) );LAISANT_1 ;;; ;;;CONVERGE ;;; ;;;check the convergence by computing distance between pnt_ref & pnt_g. (defun CONVERGE( / result) (if (< 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 (abs (norm_2_line pnt_org pnt_a pnt_ref))) (setq result (strcat "dist = " (rtos test_length 2 12))) (move_bar test_length meter_scale) ;(grtext -1 result) );SHOW_STATUS ;;; ;;; ;;;INIT_DISPLAY ;;; (defun INIT_DISPLAY() (setq init_pos '(1.55005 0.627436 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" 2 pnt_c pnt_e) ;(c:display_nodes) (mark_angle pnt_e pnt_p pnt_f 0.30 "f" mark_size 3) (mark_angle pnt_a pnt_p pnt_c 0.30 "f" mark_size 2) (mark_angle pnt_d pnt_p pnt_b 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 a (tan (angle pnt_p pnt_tmp)) 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_v (point_along_line pnt_p pnt_r ratio_1) pnt_t (point_along_line pnt_p pnt_q ratio_2) pnt_u (point_off_line pnt_p pnt_t 0.5 half_pi proj) ) ) ;; ;;;display the polyline (defun pl_display( / angle_oa angle_ob angle_oc angle_od) ;;;;additional point definition done here. (setq angle_ob (angle pnt_p pnt_s) angle_od (angle pnt_p pnt_r) angle_oc (angle pnt_p pnt_t) angle_oa (angle pnt_p pnt_u) pnt_a (polar pnt_p angle_oa 2.0) pnt_b (polar pnt_p angle_ob 2.0) pnt_c (polar pnt_p angle_oc 2.0) pnt_d (polar pnt_p angle_od 2.0) pnt_e (polar pnt_p (+ angle_od pi) 1.0) pnt_f (polar pnt_p (+ angle_oc pi) 1.0) ) (command "_.pline" pnt_e pnt_p pnt_a pnt_u pnt_t pnt_v pnt_d pnt_p pnt_b pnt_s pnt_r pnt_q pnt_c pnt_f "") ) ;setup (defun setup() (setup_sysvar) (setq pnt_org '(0 0)) (def_angle) (set_txstyle "arial") (setq half_pi (* 0.5 pi) quart_pi (* 0.25 pi) pnt_p pnt_org pnt_size 0.1 mark_size 0.07 criteria 1.e-10 ) (make_circle_1 "0" 8 pnt_p 1.0) (setvar "PDMODE" 32) (setvar "PDSIZE" -3) (command "_.point" pnt_p) ;;;----------------------------------------------------------- ;;;insert precision_meter ;block insert prec_meter.dwg (setq ins_pnt '(0.25 -0.75) meter_scale 0.5 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 pnt_org '(2 0) '(-1.41421356 1.41421356)) (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_ref (getpoint pnt_org "\nDefine a point \"X\":")) ) (make_pt "0" 3 pnt_ref) (command "_osnap" "None") ) ;; ;; (defun c:display_nodes() (set_txstyle "arial") (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_e "E" 3 0.10) (make_point "0" 0 pnt_f "F" 3 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) (make_point "0" 0 pnt_v "V" 1 0.10) );; ;;; (prompt "\nLoading animation_Laisant_1")(terpri) ;;; ;;;ANIMATION_LAISANT_1 ;;;call jpg_setup(output_filename) before running this executable. ;;;Do not forget to set jpg_yes on (=1) ;;; (defun C:animation_laisant_1() ;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_1 ;;; ;;-------------------------------------------------------------------------- (princ)