(prompt "\nAngle Trisection by AutoCAD - SPIRAL_A.LSP") (prompt "\nCommands: TEST_1 TEST_2 SPIRAL_3 SPIRAL_4 ") (prompt "\nCommands: DIVIDE_ANGLE ") (prompt "\n ") ;---------------------------------------------------------- ;; by Takaya Iwamoto ;; Nov 27, 2006 fixed bug in spiral_4 ;; SPIRAL_A.LSP ;; Spiral by Archimedes ;; ;; ;;SPIRAL_A.LSP ;; ;Spiral_1-- Archimedian ;; click left mouse to define a point (defun c:TEST_1 () (setvar "PDMODE" 32) (setvar "PDSIZE" -1) (setup_sysvar) (setq const_a (/ 2.0 pi) two_pi (* 2.0 pi) x_left '(-3.0 0) x_right '(4.25 0) y_up '(0 2.5) y_down '(0 -3.0) pnt_origin '(0 0) ) (setq pnt_old pnt_origin) (make_line_1 "0" 8 x_left x_right) (make_line_1 "0" 8 y_down y_up) (make_circle_1 "0" 2 pnt_origin 1.0) (make_circle_1 "0" 3 pnt_origin 2.0) (command "_.zoom" "_EXTENT") (setvar "OSMODE" 512) (regapp "my_point") (make_point "0" 0 '(0 0) "O" 3 0.20) (make_point "0" 0 '(1 0) "P" 1 0.20) (make_point "0" 0 '(2 0) "Q" 1 0.20) (while (setq pnt_temp (getpoint "\nPick a point on the inner circle. Hit return key to quit")) (setq theta (angle pnt_origin pnt_temp)) (if (> (distance pnt_origin pnt_temp) 1.5) (setq theta (+ theta two_pi)) ) (setq radius (* const_a theta) pnt_new (polar pnt_origin theta radius) ) (make_pt "0" 4 pnt_new) (make_line_1 "0" 1 pnt_old pnt_new) (setq pnt_old pnt_new) ) ) ;; ;; ;; Continuous mouse pick ;Spiral_2-- Archimedian (defun c:TEST_2 () (setvar "PDMODE" 32) (setvar "PDSIZE" -1) (setup_sysvar) (setq const_a (/ 2.0 pi) x_left '(-1 0) x_right '(1 0) y_up '(0 1) y_down '(0 -1) pnt_origin '(0 0) pnt_old pnt_origin ) (make_line_1 "0" 8 '(0 -3.25) '(0 1.25)) (make_line_1 "0" 8 '(-2.25 0) '(4.25 0)) (regapp "my_point") (make_point "0" 0 '(0 0) "O" 3 0.15) (make_point "0" 0 '(1 0) "P" 1 0.15) (make_point "0" 0 '(0 1) "Q" 1 0.15) (make_point "0" 0 '(-2 0) "R" 3 0.15) (make_point "0" 0 '(0 -3) "S" 1 0.15) (make_point "0" 0 '(4 0) "T" 2 0.15) (command "_.zoom" "_EXTENT") (setvar "OSMODE" 8) (setq answer (getpoint "Place the cursor at P, then press left mouse to start.\n Press left mouse or return key to terminate." ) ) ;;; while loop to pick a point continuously (make_line_1 "0" 2 pnt_origin '(1 0)) (setq line_ent (entlast)) (while (and (setq key (grread T)) (= (car key) 5)) (setq pnt_temp (cadr key)) (setq theta (angle pnt_origin pnt_temp) radius (* const_a theta) pnt_new (polar pnt_origin theta radius) ) (entdel line_ent) (make_line_1 "0" 4 pnt_old pnt_new) (make_line_1 "0" 2 pnt_origin pnt_new) (setq line_ent (entlast) pnt_old pnt_new ) ) ;while (entdel (entlast)) (reset_sysvar) ) ;; ;; ;Spiral_3-- Archimedian (defun c:SPIRAL_3 () (setvar "PDMODE" 32) (setvar "PDSIZE" -1) (setup_sysvar) (setq n_cycle (getreal "\nHow many rounds (def = 2 )")) (if (= n_cycle nil) (setq n_cycle 2)) (setq const_a (/ 2.0 pi) pnt_org '(0 0) theta_end (* (* 2 n_cycle) pi) theta_old 0.0 pnt_old pnt_org chr_size 0.15 ) (setq del_theta (getreal "\nInput angle step in radian<0.01>:")) (if (<= del_theta 0.0) (setq del_theta 0.01)) (while (<= (setq theta_new (+ theta_old del_theta)) theta_end) (setq radius (* const_a theta_new) pnt_new (polar pnt_org theta_new radius) ) (make_line_1 "0" 4 pnt_old pnt_new) (setq pnt_old pnt_new theta_old theta_new ) ) ;;;; (setq pl_entity (entlast)) (command "_pedit" pl_entity "Y" "_Join" "all" "" "_X") (reset_sysvar) (make_pt "0" 1 pnt_org) (make_line_1 "0" 8 '(-2.25 0) '(1.25 0)) (make_line_1 "0" 8 '(0 1.25) '(0 -1.25)) (regapp "my_point") (make_point "0" 0 '(0 0) "O" 4 chr_size) (make_point "0" 0 '(1.25 0) "B" 1 chr_size) (command "_.zoom" "_EXTENT") (command "_ucsicon" "off") ) ;;; ;;; ;;;Use Archimedes' Spiral to trisect a given angle ;;; ;Spiral_4-- Archimedian (defun c:SPIRAL_4 () (setvar "PDMODE" 32) (setvar "PDSIZE" -1) (setup_sysvar) (setq const_a (/ 2.0 pi) pnt_org '(0 0) theta_end (* 2.0 pi) del_theta 0.001 theta_old 0.0 pnt_old pnt_org ) (while (<= (setq theta_new (+ theta_old del_theta)) theta_end) (setq radius (* const_a theta_new) pnt_new (polar pnt_org theta_new radius) ) (make_line_1 "0" 4 pnt_old pnt_new) (setq pnt_old pnt_new theta_old theta_new ) ) ;;;; (setq pl_entity (entlast)) (command "_pedit" pl_entity "Y" "_Join" "all" "" "_X") (setq pl_total (entlast)) (make_pt "0" 1 pnt_org) (make_line_1 "0" 8 '(-2.25 0) '(4.25 0)) (make_line_1 "0" 8 '(0 1.25) '(0 -3.25)) (command "_.zoom" "_EXTENT") (c:divide_angle) ;execute trisection (reset_sysvar) (command "_ucsicon" "off") ) ;; ;; DIVIDE_ANGLE ;(defun c:DIVIDE_ANGLE (/ line_end one_third ; line_fortest end_point radius_circle ; begin_arc end_arc arc_ent ; trisect ; ) (defun c:DIVIDE_ANGLE ( ) (setq chr_size 0.15) (setq line_end (getpoint '(0 0) "Pick a point to define an angle crossing the spiral:") )(terpri) (make_line_1 "0" 2 line_end pnt_org) ;(mark_point line_end -0.3 0.3 "A" chr_size) (command "_.delay" 500) (setq one_third (/ 1.0 3.0)) (alert "\nTrim the line using spiral as delimiter") (command "_.trim" pl_total "" line_end "") (setq line_fortest (entlast)) (command "_.delay" 500) (setq end_point (cdr (assoc 10 (entget line_fortest))) radius_circle (/ (get_length line_fortest) 3) trisect (* radius_circle pi 0.5) ) ;(make_pt "0" 0 pnt_org ) ; (make_line_1 "0" 8 line_end end_point) (mark_point end_point -0.3 0.3 "P" chr_size) ;(mark_point pnt_org 0.3 -1. "O" chr_size) (alert "\nDivide the yellow line into 3 equal length") (command "_.divide" line_fortest 3) (command "_.delay" 1000) (setq begin_arc (polar pnt_org trisect radius_circle ) end_arc (plt pnt_org end_point one_third) ) ;(alert "\nDraw an arc from x-axis to the end") (command "_.arc" "c" '(0 0) begin_arc end_arc) (setq arc_ent (entlast)) (command "_.delay" 1000) (setq arc_ent (entget (entlast))) (make_line_1 "0" 1 pnt_org begin_arc ) (make_point "0" 0 begin_arc "E" 1 0.15) ;;;display the result (mark_point line_end -0.3 0.3 "A" chr_size) (mark_point '(3.75 0) 0. 0. "B" chr_size) (make_line_1 "0" 8 line_end end_point) (mark_point pnt_org 0.3 -1. "O" chr_size) (setq original (cdr (assoc 51 arc_ent)) ang_aob (angtos original 0 10) ang_eob (angtos trisect 0 10) result_aob (strcat "Angle AOB = " ang_aob " deg") result_eob (strcat "Angle EOB = " ang_eob " deg" ) ang_ratio (rtos (/ original trisect ) 1 10) result (strcat "Angle ratio = " ang_ratio) ) (textdisplay result_aob '(0.05 -0.75) chr_size 0.) (textdisplay result_eob '(0.05 -1.25) chr_size 0.) (textdisplay result '(0.05 -1.75) chr_size 0.) (command "_.zoom" "_Extent") ) ;;-------------------------------------------------------------------------- (princ)