;;;Angle Trisection by AutoCAD - QD_TRIX.LSP ;;; (prompt "\nAngle Trisection by AutoCAD - QD_TRIX.LSP") (prompt "\nCommands: TEST_1 TEST_2 QUADRATRIX_2 QUADRATRIX_3") (prompt "\nFunctions: (DIVIDE_ANGLE) (LIMIT_TEST) ") (prompt "\n ") ;---------------------------------------------------------- ;test for grread usage 11/16/1998 ;quadratrix for angle trisection trial ;;; TEST_1 shows how this curve is generated ;;; TEST_2 shows how this curve is generated ;;; QUADRATRIX_2 shows how this curve is used used to trisect a given angle ;;; Step 1: define angle AOB ;;; Step 2: Trim the line OA by the quadratrix curve-->OF ;;; Step 3: Divide line OF or CO into N-equal parts ;;; Step 4: ;;; QUADRATRIX_3 shows how this curve is used for angle-trisection ;;; limit_test shows how this curve will cut x-axis at pi/4 ;; (defun c:test_1 () (setup_qdtrix) (textdisplay "How to draw" '(0 -0.15) 0.05 0.) (setq n_divide (getint "\nHow many division ?(def=10)")) (if (<= n_divide 0) (setq n_divide 10) ) (command "_.divide" arc_ent n_divide) (command "_.divide" line_ent n_divide) (setq answer (getint "Place the cursor at P, then hit return key")) (setq counter 0) (setvar "OSMODE" 8) (setq pnt_old '(0 1)) (while (setq pnt_temp (getpoint "\nselect a node on the arc:(Hit return key to end)" ) ) (setq temp_angle (angle pnt_center pnt_temp) temp_x (* (cos temp_angle) ref_radius) temp_y (* (sin temp_angle) ref_radius) cir_loc (list temp_x temp_y) ratio (/ temp_angle half_pai) left_pt (list 0 ratio) right_pt (list 1 ratio) ) (if (/= counter 0) (progn (entdel rad_line) (entdel hor_line) ) );;;end of IF loop (make_line_1 "0" 1 pnt_center cir_loc) (setq rad_line (entlast)) (make_line_1 "0" 2 left_pt right_pt) (setq hor_line (entlast) int_pnt (inters pnt_center cir_loc left_pt right_pt nil) ) (if (/= int_pnt nil) (progn (make_pt "0" 4 int_pnt) (make_line_1 "0" 4 pnt_old int_pnt) (setq pnt_old int_pnt) (setq counter (1+ counter)) );;;end of progn );;;end of IF loop );;;end of WHILE loop (entdel rad_line) (entdel hor_line) (reset_sysvar) ) ;;; (defun c:test_2 () (setup_qdtrix) (textdisplay "How to draw" '(0 -0.15) 0.05 0.) (command "_.divide" arc_ent "10") (command "_.divide" line_ent "10") ;(prompt ""Place the cursor at P, then move mouse while left mouse being pressed.") (setq answer (getpoint "Place the cursor at P, then press left mouse to start.\n Press left mouse or return key to terminate.")) (setq counter 0) ;;; while loop to pick a point continuously ;(while (setq pnt_temp (cadr (grread T))) (while (and (setq key (grread T)) (= (car key) 5) ) (setq pnt_temp (cadr key) ) (setq temp_angle (angle pnt_center pnt_temp)) (if (and (> temp_angle pi) (< temp_angle 2_pai)) (setq temp_angle (- temp_angle 2_pai)) );;;end of if (setq temp_x (* (cos temp_angle) ref_radius) temp_y (* (sin temp_angle) ref_radius) cir_loc (list temp_x temp_y) ratio (/ temp_angle half_pai) left_pt (list 0 ratio) right_pt (list 1 ratio) ) (if (/= counter 0) (progn (entdel rad_line) (entdel hor_line) ) ) (make_line_1 "0" 1 pnt_center cir_loc) (setq rad_line (entlast)) (make_line_1 "0" 2 left_pt right_pt) (setq hor_line (entlast)) (setq int_pnt (inters pnt_center cir_loc left_pt right_pt nil)) (if (/= int_pnt nil) (make_pt "0" 4 int_pnt) );;;end of if (setq counter (1+ counter)) ) ;;;while loop (entdel rad_line) (entdel hor_line) (reset_sysvar) ) ;;; (defun setup_qdtrix() (setvar "PDMODE" 32) (setvar "PDSIZE" -4) (setup_sysvar) (setq ref_radius 1.0 pnt_center '(0 0) half_pai (* pi 0.5) inv_half_pai (/ 2.0 pi) ) (command "_.arc" "_C" '(0 0 ) '(1 0) '(0 1)) (setq arc_ent (entlast)) (command "_.line" '(0 0) '(1 0) '(1 1) '(0 1) "_c") (setq line_ent (entlast)) (make_line_1 "0" 8 '(0 -0.25) '(1 -0.25)) (regapp "my_point") (make_point "0" 0 '(0 0) "O" 3 0.05) (make_point "0" 0 '(0 1) "P" 3 0.05) (make_point "0" 0 '(1 1) "Q" 1 0.05) (make_point "0" 0 '(1 0) "B" 1 0.05) ;(textdisplay "How to draw" '(0 -0.15) 0.05 0.) (textdisplay "Hippias's Quadratrix curve" '(0 -0.25) 0.05 0.) (command "_.zoom" "_EXTENT") (command "_.regen") );;;SETUP_QDTRIX ;;; ;;;plot quadratrix automatically using analytical expression (defun c:quadratrix_2 () (setup_qdtrix) (setq theta_end 0.0 del_theta (/ half_pai 1000) theta_old half_pai ) (setq pnt_old '(0 1)) (while (>= (setq theta_new (- theta_old del_theta)) theta_end) (setq y_new (* inv_half_pai theta_new) sine (sin theta_new) cosine (cos theta_new) tangent (/ sine cosine) ) (if (/= tangent 0.0) (setq x_new (/ y_new tangent) ) (setq x_new inv_half_pai) ) (setq pnt_new (list x_new y_new)) (make_line_1 "0" 4 pnt_old pnt_new) (setq pnt_old pnt_new) (setq theta_old theta_new) ) ;;;; (setq pick_line (entlast)) (command "_.pedit" pick_line "Y" "_Join" "all" "" "_X") (setq pick_pline (entlast)) (command "_.arc" "_C" '(0 0) '(1 0) '(0 1)) (command "_.line" '(0 0) '(1 0) '(1 1) '(0 1) "_c") (make_point "0" 1 (list (/ 2.0 pi) 0) "R" 1 0.05) ) ;;;add tri_section operation after quadratrix_2 operation (defun c:quadratrix_3 () (setup_qdtrix) (setq num_step (getint "\nNumber of division:")) (if (<= num_step 0) (setq num_step 1000) ) (setq theta_end 0.0 del_theta (/ half_pai num_step) theta_old half_pai ) (setq pnt_old '(0 1)) (while (>= (setq theta_new (- theta_old del_theta)) theta_end) (setq y_new (* inv_half_pai theta_new) sine (sin theta_new) cosine (cos theta_new) tangent (/ sine cosine) ) (if (/= tangent 0.0) (setq x_new (/ y_new tangent)) (setq x_new inv_half_pai) ) (setq pnt_new (list x_new y_new)) (make_line_1 "0" 4 pnt_old pnt_new) (setq pnt_old pnt_new) (setq theta_old theta_new) ) ;;;end of while loop (setq pick_line (entlast)) (command "_.pedit" pick_line "_Y" "_Join" "_all" "" "_X") (setq pick_pline (entlast)) (command "_.arc" "_C" '(0 0) '(1 0) '(0 1)) (make_line_1 "0" 8 '(0 0) '(1 0)) (make_line_1 "0" 8 '(1 0) '(1 1)) (make_line_1 "0" 8 '(1 1) '(0 1)) (make_line_1 "0" 8 '(0 1) '(0 0)) (command "_.delay" 1000) (c:divide_angle) (reset_sysvar) ) ;;; ;;; (defun c:divide_angle () (setq trial_point (getpoint '(0 0) "\nDefine an angle to be equally divided." ) ) (make_line_1 "0" 2 pnt_center trial_point) ;;;the subsequent stage save (within zoom_regen function) (command "_.delay" 1000) (setq trial_line (entlast)) (command "_.trim" pick_pline "" trial_point "") (setq line_oa_ent (entget trial_line) line_end (cdr (assoc 11 line_oa_ent)) y_line_ca (cadr line_end) ) (make_line_1 "0" 2 (list 0 y_line_ca) line_end) (make_point "0" 1 (list 0 y_line_ca) "C" 3 0.05) (make_point "0" 1 line_end "A" 1 0.05) ;;;the subsequent stage save (within zoom_regen function) (command "_.delay" 1000) (setq num_div (getint "\nNumber of division::")) (if (<= num_div 0) (setq num_div 3) ) (setq end_pnt (cdr (assoc 11 (entget trial_line))) y_end_pnt (/ (cadr end_pnt) num_div) div_pnt (point_along_line pnt_center end_pnt (/ 1.0 num_div)) right_end (list 0.7500 y_end_pnt) ) ;;;the subsequent stage save (within zoom_regen function) (command "_.delay" 1000) (make_point "0" 1 (list 0 (cadr div_pnt)) "D" 3 0.05) (make_line_1 "0" 3 (list 0 (cadr div_pnt)) right_end) (setq horiz_line (entlast)) (command "_.trim" pick_pline "" right_end "") (setq pnt_e (cdr (assoc 11 (entget horiz_line)))) ;;;the subsequent stage save (within zoom_regen function) (command "_.delay" 1000) (command "_.divide" trial_line num_div) ;;;the subsequent stage save (within zoom_regen function) (command "_.delay" 1000) (make_point "0" 1 pnt_e "E" 1 0.05) (make_point "0" 1 (list (/ 2.0 pi) 0) "R" 1 0.05) (make_line_1 "0" 3 '(0 0) pnt_e) ;;;the subsequent stage save (within zoom_regen function) (command "_.delay" 1000) (setq ang_orig (angle '(0 0) line_end) ang_div (angle '(0 0) pnt_e) ang_aob (angtos ang_orig 0 10) ang_eob (angtos ang_div 0 10) result_aob (strcat "angle AOB = " ang_aob) result_eob (strcat "angle EOB = " ang_eob) ang_ratio (rtos (/ ang_div ang_orig) 1 10) result (strcat "angle ratio = " ang_ratio) ) (textdisplay result_aob '(1.02 0.5) 0.05 0.) (textdisplay result_eob '(1.02 0.4) 0.05 0.) (textdisplay result '(1.02 0.3) 0.05 0.) (prin1 result_aob) (terpri) (prin1 result_eob) (terpri) (prin1 result) (terpri) ) ;;; (defun c:limit_test() (while (setq input (getreal "\nInput test number:")) (setq output (/ (sin input) input)) (prin1 (rtos (- 1.0 output) 2 15)) ) ) ;;; (defun c:make_image () ; (setq nstep (getint "\nHow many steps:")) (setq pnt_old '(0 1) step 0) (while (setq pnt_temp (getpoint "\nselect a node on the arc:(Hit return key to end)" ) ) (setq temp_angle (angle pnt_center pnt_temp) temp_x (* (cos temp_angle) ref_radius) temp_y (* (sin temp_angle) ref_radius) cir_loc (list temp_x temp_y) ratio (/ temp_angle half_pai) left_pt (list 0 ratio) right_pt (list 1 ratio) ) (if (/= step 0) (entdel rad_line) ) (if (/= step 0) (entdel hor_line) ) (make_line_1 "0" 1 pnt_center cir_loc) (setq rad_line (entlast)) (make_line_1 "0" 2 left_pt right_pt) (setq hor_line (entlast) ) (setq int_pnt (inters pnt_center cir_loc left_pt right_pt nil) ) (if (/= int_pnt nil) (progn (make_pt "0" 4 int_pnt) (make_line_1 "0" 4 pnt_old int_pnt) (setq pnt_old int_pnt) );;;end of progn );;;end of IF loop ;(alert "\nSave as WMF ?") ;(command "export" (strcat "quadratrix_" (itoa step) ".wmf") "all" "" ) (command "_.jpgout" (strcat "quadratrix_" (itoa step) ) "" ) (setq step (1+ step)) );;;end of WHILE loop (entdel rad_line) (entdel hor_line) (reset_sysvar) ) ;;; ;;-------------------------------------------------------------------------- (princ)