(prompt "\nAngle Trisection by AutoCAD - TRIANGLE.LSP") (prompt "\nCommands: TEST_triangle TRIANGLE") (prompt "\nFunctions: (SETUP)(RESET)(ZOOM_REGEN)(CONVERGE)") (prompt "\n (SHOW_RESULT)(SHOW_STATUS)(INIT_DISPLAY)(PL_DISPLAY)(LOCATE)") (prompt "\n ") ;---------------------------------------------------------- ;link test 7/07/99 Takaya Iwamoto ;Trisection using two drafting triangles ;; ;; (defun C:TEST_triangle() ;Main routine (setup_triangle) ;set up (init_display) (alert "Place the cursor near the point \"C\", then click left mouse to start.") (setq answer (getpoint "\nPress left mouse to start.Click mouse to stop."))(terpri) (alert "Move the mouse so that point M (blue) will be on the y_axis") (entdel new_pnt_ent) (entdel new_txt_ent) (command "_.vports" "2" "v") ;;;2 view ports (command "_.zoom" "w" lower_left upper_right) (entdel blue_point) (setq dx 0. dy 0.) (while (and (setq key (grread T)) (= (car key) 5) ) (setq pnt_tmp (cadr key)) (entdel blue_point) (locate pnt_tmp dx dy) (pl_display) (setq last_pline (entlast)) ) (command "_.vports" "SI" ) ;;;single view port (show_result) (reset_sysvar) );TEST ;;; ;;;TRIANGLE main routine with automatic zoom ;;; (defun C:TRIANGLE() (setup_triangle) ;setup parameters ;specify the angle to be tri_sected (init_display) ;set initial position (alert "Place the cursor near the point \"C\", then click left mouse to start.") (setq answer (getpoint "\nPress left mouse to start.Click mouse to stop."))(terpri) (alert "Move the mouse so that point M (blue) will be on the y_axis") (entdel new_pnt_ent) (entdel new_txt_ent) (command "_.vports" "2" "v") ;;;2 view ports (command "_.zoom" "w" lower_left upper_right) (entdel blue_point) (setq flag "GO" dx 0. dy 0. count 0) (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 y_0))) ) ) (entdel blue_point) ;;;;compute all points of triangles' corner (locate pnt_temp dx dy) ;;;;display triangles (pl_display) (setq last_pline (entlast)) ;;;;display the distance of point M to the T-axis in the status window (show_status) );inner while loop ;;;;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") (show_result) (reset_sysvar) );TRIANGLE ;;; ;;;INIT_DISPLAY ;;; display the block at the initial position (defun INIT_DISPLAY() ;(setq init_pos '(-2.0 0 0)) (setq init_pos '(-2.25 0 0)) (locate init_pos 0 0) (pl_display) (entdel blue_point) (setq last_pline (entlast)) (regapp "my_point") (make_point "0" 0 pnt_c "C" 2 pnt_size) );INIT_DISPLAY ;;; ;;;LOCATE ;;; ;;;locate the point to satisfy the condition (defun LOCATE(pnt_temp dx_off dy_off) ;;first triangle (setq x_temp (+ (car pnt_temp) dx_off) pnt_c (list x_temp 0) dist_ct (distance pnt_c pnt_t) pnt_d (point_along_line pnt_c pnt_t (/ 4.0 dist_ct)) pnt_e (point_off_line pnt_c pnt_d 0.0 (- half_pi) (* 4.0 sqrt_3)) ) ;second triangle (setq b_value (/ (2d_scalar_prod pnt_e pnt_c pnt_s) dist_ce) pnt_m (point_along_line pnt_e pnt_c (/ b_value dist_ce)) pnt_l (point_along_line pnt_m pnt_s (/ 3.0 (distance pnt_m pnt_s))) pnt_n (point_along_line pnt_e pnt_c (/ (+ b_value 3.0) dist_ce)) ) );LOCATE ;;; ;;;PL_DISPLAY ;;;polyline entity display (defun PL_DISPLAY() (if (/= last_pline nil) (entdel last_pline)) (make_pt "0" 4 pnt_m) (setq blue_point (entlast)) (command "_.pline" pnt_m pnt_l pnt_n pnt_e pnt_d pnt_c pnt_n "") (setq last_pline (entlast)) );PL_DISPLAY ;;; ;;;SETUP_Triangle ;;; ;;;setup_triangle (defun SETUP_TRIANGLE() (setup_sysvar) (setq half_pi (* 0.5 pi) quart_pi (* 0.25 pi) sqrt_3 (sqrt 3.0) sqrt_2 (sqrt 2.0) pnt_org '(0 0) pnt_b '(2.5 0) pnt_t '(0 1) dist_ce (* 4.0 sqrt_3) pnt_size 0.25 mark_size 0.20 lower_left '(-2.5 -4.0) upper_right '(1.0 -2.0) criteria 1.e-8 last_pline nil blue_point nil ) ;;;------------------------------------------------------------- ;;;insert precision_meter ;block insert prec_meter.dwg (setq ins_pnt '(-3. -7.) meter_scale 1.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 ;;;------------------------------------------------------------- (def_angle) (command "_.zoom" "_Extent" ) (command "_.regen") );SETUP ;;; ;;;DEF_ANGLE ;;;define angle ;;; (defun DEF_ANGLE() (make_circle_1 "0" 8 pnt_org 1.0) (setq cir_ent (entlast)) (command "_.zoom" "_EXTENT") (command "_.regen") (setvar "OSMODE" 512) ;; nearest mode (setq pnt_a (getpoint pnt_org "\nDefine an angle on the circle")) (setq pnt_refa (point_along_line pnt_org pnt_a 2.5)) (make_line_1 "0" 3 pnt_refa pnt_org) (make_line_1 "0" 3 pnt_org '(2.5 0)) (make_line_1 "0" 2 '(-3.5 0) pnt_org) (make_line_1 "0" 2 '(0 2) '(0 -4.5)) (make_pt "0" 1 pnt_a) (make_pt "0" 1 pnt_t) (setq a_value (car pnt_a) pnt_p (list a_value 0) pnt_q (list (* 2.0 a_value) 0) pnt_r (list 0 -3) pnt_s (list (* 2.0 a_value) -3) ) (make_pt "0" 1 pnt_s) (make_pt "0" 1 pnt_p) (make_pt "0" 1 pnt_q) (make_pt "0" 1 pnt_r) (make_line_1 "0" 8 pnt_a pnt_p) (make_line_1 "0" 8 pnt_q pnt_s) (make_line_1 "0" 8 pnt_r pnt_s) (command "_ucsicon" "off") (setvar "OSMODE" 0) ;;reset Snap mode to zero (setvar "PDMODE" 34) (setvar "PDSIZE" -2) (setq pnt_c '(-2 0) pnt_d (point_along_line pnt_c pnt_t (/ 4.0 (sqrt 5.))) pnt_e (point_off_line pnt_c pnt_d 0.0 (- half_pi) (* 4.0 sqrt_3)) ) (command "_.zoom" "_EXTENT") ;(command "_.zoom" "_S" "1.25") (command "_.regen") );DEF_ANGLE ;;; ;;;RESET ;;; ;;; ;;;SHOW_RESULT ;; (defun SHOW_RESULT() (c:display_nodes) (make_line_1 "0" 1 pnt_a pnt_c) (mark_angle pnt_a pnt_c pnt_org 1.25 "f" mark_size 1) (mark_angle pnt_a pnt_org pnt_b 1.5 "3f" mark_size 1) (command "_.zoom" "_EXTENT") (command "_.regen") );SHOW_RESULT ;;; ;;;DISPLAY_NODES ;; ;; (defun c:DISPLAY_NODES() (set_txstyle "arial") (regapp "my_point") (make_point "0" 0 pnt_org "O" 4 pnt_size) (make_point "0" 0 pnt_a "A" 1 pnt_size) (make_point "0" 0 pnt_b "B" 1 pnt_size) (make_point "0" 0 pnt_c "C" 2 pnt_size) (make_point "0" 0 pnt_d "D" 1 pnt_size) (make_point "0" 0 pnt_e "E" 1 pnt_size) (make_point "0" 0 pnt_l "L" 1 pnt_size) (make_point "0" 0 pnt_m "M" 3 pnt_size) (make_point "0" 0 pnt_n "N" 3 pnt_size) (make_point "0" 1 pnt_p "P" 1 pnt_size) (make_point "0" 1 pnt_q "Q" 1 pnt_size) (make_point "0" 1 pnt_r "R" 1 pnt_size) (make_point "0" 1 pnt_s "S" 2 pnt_size) (make_point "0" 0 pnt_t "T" 2 pnt_size) );DISPLAY_NODES ;;; ;;;CONVERGE ;;; ;;;check the convergence computing the distance from point M to the y_axis. (defun CONVERGE( / result) (setq test_length (abs (car pnt_m))) (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) ;;;(defun ZOOM_REGEN( ) (setq delta (* 2.0 test_length) x_d (car pnt_m) y_d (cadr pnt_m) 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 ;;; ;;;SHOW_STATUS ;;; (defun SHOW_STATUS( / cur_dist result) (setq cur_dist (car pnt_m) ;result (strcat "dist = " (rtos cur_dist 2 12)) ) (move_bar CUR_dist meter_scale) ;(grtext -1 result) );SHOW_STATUS ;;; ;;;ANIMATION_TRIANGLE main routine fro animation file creation ;;; (defun C:ANIMATION_TRIANGLE() (setup_triangle) ;setup parameters ;specify the angle to be tri_sected 60 degrees in this example (init_display) ;set initial position (entdel new_pnt_ent) (entdel new_txt_ent) ;(command "_.zoom" "w" lower_left upper_right) (command "_.zoom" "_Extent") (entdel blue_point) (setq init_c '(-2.25 0) end_c '(-1.87939 0.) dist (distance init_c end_c) 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_c end_c (* n_cur del_step))) (entdel blue_point) (locate pnt_temp 0 0) (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 (show_result) (make_jpg) (reset_sysvar) );ANIMATION_TRIANGLE ;;; ;;-------------------------------------------------------------------------- (princ)