(prompt "\nDoubling the Cube by AutoCAD - NICOMEDES_DELIAN.LSP") (prompt "\nCommands: TEST TEST_2 NICOMEDES_delian ") (prompt "\nCommands: ") (prompt "\n ") ;---------------------------------------------------------- ;; ;; NICOMEDES_D.LSP ;; Use Conchoid ;; Jan 28, 2001 Takaya Iwamoto ;; Jan 18,2006 add Conchoid draw option in command "TEST" ;; load Utility_Curves.lsp,then use test_conchoid command ;; Dec 24, 2006 copied test_conchoid and draw_conchoid from utility_curves.lsp ;; ;; ;Test --- one at a time (defun c:test () (setup_nicom) ;;setup (disp_pline 2.5) ;;initial display (while (setq pnt_temp (getpoint "\nPick a point on the line BX. Hit return key to quit")) (setq k_x (car pnt_temp)) (entdel line_ent) (disp_pline k_x) ) (reset_sysvar) );TEST ;; ;; ;; ;Test --- one at a time (defun c:test_0() (setup_nicom) ;;setup (make_jpg) (alert "\ndraw conchoid curve") ;;;draw conchoid (conchoid_draw pnt_c pnt_z pnt_f 1.0 100) ;;; (make_jpg) (make_jpg) (command "_.delay" 500) (make_pt "0" 1 pnt_k) (make_pt "0" 1 pnt_m) (textdisplay "K" pnt_k chr_size 0.) (textdisplay "M" pnt_m chr_size 0.) (command "_.delay" 500) ;;point h (make_line_1 "0" 0 pnt_f pnt_k) (setq pnt_h (inters pnt_f pnt_k pnt_c pnt_z )) (make_pt "0" 0 pnt_h) (textdisplay "H" pnt_h chr_size 0.) (make_jpg) (make_line_1 "0" 8 pnt_k pnt_l) (make_jpg) (command "_.delay" 500) (make_line_1 "0" 8 pnt_m pnt_l) (make_jpg) (command "_.delay" 500) (make_line_1 "0" 3 pnt_c pnt_k) (make_line_1 "0" 4 pnt_a pnt_m) (make_jpg) (make_jpg) (reset_sysvar) );TEST ;; ;; ;Test_2-- Continuous pick (defun c:test_2 () (setup_nicom) ;;setup (disp_pline 2.5) ;;initial display (setq answer (getpoint "Place the cursor near the line BX, then press left mouse to start.\n Press left mouse or return key to terminate." ) ) ;;; while loop to pick a point continuously (while (and (setq key (grread T)) (= (car key) 5)) (setq k_x (car (cadr key))) (entdel line_ent) (disp_pline k_x) ) ;while (reset_sysvar) );TEST_2 ;; ;;; ;;; ;;;Nicomedes_Delian ;;; ;;;main routine ::: zoom & regen is done automatically (defun c:Nicomedes_delian() (setup_nicom) ;;setup (disp_pline 2.5) ;;initial display (setq vscale (getvar "viewsize"));;;GET CURRENT VIEW SIZE (setq flag "GO" split_win "NO") (alert "Move the cursor near the line BX, \nthen click your left mouse to begin moving along the line BX.\n \nHit return key to terminate." ) (setq answer (getpoint "\nPress left mouse for automatic zooming and regen.")) (while (= flag "GO") (while (and (setq key (grread T)) (= (car key) 5) ) (setq k_x (car(cadr key))) (entdel line_ent) ; (entdel pnt_ent) (disp_pline k_x) (show_status) );inner while loop ;;;after the 2-nd round,work with 2 viewports. (if (= split_win "NO") (command "_.vports" "2" "v")) ;;;;convergence criteria check (if (= (converge) T) (setq flag "STOP")) ;;;;zoom and regen automatically for 2 viewports (zoom_regen pnt_kt pnt_k ) (setq split_win "YES") );outer while loop (command "_.vports" "SI" ) ;;;single view port ;(result_display) (show_nodes) (command "_.zoom" "_EXTENT") (reset_sysvar) );NICOMEDES ;; ;;; ;;;CONVERGE ;;; ;;;check the convergence comparing the radius and line segment OL (defun CONVERGE( / result) (setq diff_length (distance pnt_kt pnt_k) ) (if (< diff_length criteria) (setq result T) (setq result nil)) );CONVERGE ;;; ;;;ZOOM_REGEN ;;; (defun ZOOM_REGEN(pnt_target pnt_move) ;;;Target point (setq vscale (/ vscale 4.)) ;;;focus on the target point (setvar "CVPORT" 2) (command "_.zoom" "ce" pnt_target vscale) (command "_.regen") ;;;Mouse control point (setq vscale (/ vscale 4.)) ;;;focus on the control point (setvar "CVPORT" 3) (command "_.zoom" "ce" pnt_move vscale) (command "_.regen") );ZOOM_REGEN ;;; ;;;SHOW_STATUS ;;; show the distance between tip and the horizontal line (defun SHOW_STATUS( / result) (setq diff_length (distance pnt_kt pnt_k) ) (setq result (strcat "dist = " (rtos diff_length 2 12))) ;(grtext -1 result) );SHOW_STATUS ;;; ;;; ;;;RESULT_DISPLAY ;;; show the distance between tip and the horizontal line (defun RESULT_DISPLAY( / result) (make_line_1 "layer1" 1 pnt_a pnt_b) (make_line_1 "layer2" 2 pnt_a pnt_new) (make_line_1 "layer3" 3 pnt_a pnt_c) (setq diff_length (abs (- (distance pnt_o pnt_new) ref_rad))) (setq result (strcat "dist = " (rtos diff_length 2 12))) (grtext -1 result) (make_point "0" 0 pnt_g "G" 1 chr_size) (make_point "0" 0 pnt_new "L" 1 chr_size) (setq len_ab 1.0 len_al (distance pnt_a pnt_new) len_ac 2.0 cube_al (expt len_al 3) ) (setq line_1 "Result" line_2 "AL**3 = AC / AB" line_3 (strcat "AL = " (rtos len_al 2 10)) line_31 "(Exact = 1.259921049895)" line_4 (strcat "AL**3 = " (rtos cube_al 2 10)) line_5 "AC / AB = 2.0 (Given)" ) (textdisplay line_1 '(1.0 0.75) 0.090 0) (textdisplay line_2 '(0.85 0.60) 0.075 0) (textdisplay line_3 '(0.90 0.50) 0.05 0) (textdisplay line_31 '(0.90 0.40) 0.05 0) (textdisplay line_4 '(0.90 0.25) 0.05 0) (textdisplay line_5 '(0.90 0.10) 0.05 0) );RESULT_DISPLAY ;;; ;;SETUP_NICOM (defun setup_nicom() (setvar "PDMODE" 32) (setvar "PDSIZE" -1) (setup_sysvar) (setq sqrt3 (sqrt 3.) pnt_a '(0 2) pnt_b '(0 0) pnt_c '(1 0) pnt_d '(0 1) pnt_e '(0.5 0) pnt_f (list 0.5 (- (* 0.5 sqrt3))) pnt_g '(-1 0) pnt_kx '(4 0) pnt_l '(1 2) pnt_my '(0 3.75) pnt_z (list (+ 1 sqrt3) -1) chr_size 0.125 ref_rad 1.0 criteria 1.e-7 one_third (/ 1. 3.) two_cube (expt 2. one_third) four_cube (expt 4. one_third) pnt_k (list (+ 1 four_cube) 0) pnt_m (list 0 (+ 2 two_cube)) ) (make_line_1 "0" 8 pnt_my pnt_a) (make_line_1 "0" 5 pnt_a pnt_d) (make_line_1 "0" 5 pnt_d pnt_b) (make_line_1 "0" 2 pnt_g pnt_b) (make_line_1 "0" 2 pnt_b pnt_e) (make_line_1 "0" 2 pnt_e pnt_c) (make_line_1 "0" 8 pnt_c pnt_kx) (make_line_1 "0" 8 pnt_c pnt_z) (make_line_1 "0" 8 pnt_c pnt_l) (make_line_1 "0" 8 pnt_g pnt_f) (make_line_1 "0" 8 pnt_e pnt_f) (make_line_1 "0" 5 pnt_c pnt_f) (make_line_1 "0" 2 pnt_a pnt_l) (make_line_1 "0" 8 pnt_l pnt_d) (make_line_1 "0" 8 pnt_d pnt_g) ;(make_circle_1 "0" 8 pnt_o ref_rad) (regapp "my_point") (make_point "0" 0 pnt_a "A" 3 chr_size) (make_point "0" 0 pnt_b "B" 4 chr_size) (make_point "0" 0 pnt_c "C" 4 chr_size) (make_point "0" 0 pnt_d "D" 3 chr_size) (make_point "0" 0 pnt_e "E" 2 chr_size) (make_point "0" 0 pnt_f "F" 4 chr_size) (make_point "0" 0 pnt_g "G" 3 chr_size) (make_point "0" 0 pnt_l "L" 1 chr_size) (make_point "0" 0 pnt_my "Y" 1 chr_size) (make_point "0" 0 pnt_kx "X" 1 chr_size) (make_point "0" 0 pnt_z "Z" 4 chr_size) (command "_.zoom" "_EXTENT") (command "_.regen") ;(setvar "OSMODE" 8) );SETUP_DIOCLES ;;; ;;;SHOW_NODES ;;; (defun show_nodes() (entdel (entlast)) (setq pnt_m (inters pnt_b pnt_my pnt_k pnt_l nil)) (make_point "0" 0 pnt_k "K" 1 chr_size) (make_point "0" 0 pnt_h "H" 4 chr_size) (make_point "0" 0 pnt_m "M" 1 chr_size) (make_line_1 "0" 8 pnt_k pnt_l) (make_line_1 "0" 8 pnt_l pnt_m) (make_line_1 "0" 0 pnt_f pnt_h) (make_line_1 "0" 5 pnt_h pnt_k) ) ;; ;;DISP_PLINE ;;;display pline GECHF after points E,F,and H are computed ;;; (defun disp_pline(k_x) (setq pnt_k (list k_x 0) pnt_h (inters pnt_c pnt_z pnt_f pnt_k) len_fk (+ (distance pnt_f pnt_h) ref_rad) ;pnt_kt (cal "pnt_h + ref_rad*vec1(pnt_h, pnt_k)") pnt_kt (pld pnt_f pnt_h len_fk) ) (command "_.line" pnt_f pnt_kt "") (setq line_ent (entlast)) );DISP_PLINE ;; ;;; ;;;TEST_CONCHOID ;;; (defun c:test_conchoid( / pnt_a pnt_b pnt_c a_length n_div pnt_a_def pnt_b_def pnt_c_def a_length_def n_div_def) ;;;set default value for inputs (setvar "PDMODE" 32) (setq pnt_a_def '(-4 0) pnt_b_def '(4 0) pnt_c_def '(0 -1) a_length_def 2. n_div_def 100 y_up '(0 5) y_down '(0 -2) x_left '(-5 0) x_right '(5 0) ) ;(make_line_1 "0" 8 y_up y_down) ;(make_line_1 "0" 8 x_left x_right) ;;;Input data (setq rule_a (getpoint "\nGet left end of rule: rule_a (def = '(-4 0)): ") rule_b (getpoint "\nGet right end of rule: rule_b (def = '(4 0)): ") pole_c (getpoint "\nGet pole: pole_c (def = '(0 -1)): ") a_length (getreal "\nSpecify distance a (def = 2): ") n_div (getint "\nSpecify number of division between A & B (def = 100): ") ) ;;;default section (if (= rule_a nil) (setq rule_a pnt_a_def)) (if (= rule_b nil) (setq rule_b pnt_b_def)) (if (= pole_c nil) (setq pole_c pnt_c_def)) (if (= a_length nil) (setq a_length a_length_def)) (if (= n_div nil) (setq n_div n_div_def)) (command "_point" rule_a) (command "_point" rule_b) (command "_point" pole_c) ;;;draw conchoid (conchoid_draw rule_a rule_b pole_c a_length n_div) );;;TEST_CONCHOID ;;; ;;; ;;;DRAW_CONCHOID ;;; pnt_a, pnt_b end coordinate of line AB (ruler) ;;; pnt_c Pole ;;; a_length constant length ;;; ndiv no. of division between Point A & B ;;; (defun conchoid_draw(pnt_a pnt_b pnt_c a_length ndiv / inc nstep pnt_old pnt_t pnt_new dist_ca dist_ct ) (setq inc (/ 1. (float ndiv)) nstep 1 dist_ca (distance pnt_c pnt_a) pnt_old (pld pnt_c pnt_a (+ dist_ca a_length)) ) (make_line_1 "0" 3 pnt_c pnt_old) (setq temp_line (entlast)) (repeat ndiv (entdel temp_line) (setq pnt_t (plt pnt_a pnt_b (* nstep inc)) dist_ct (distance pnt_c pnt_t) pnt_new (pld pnt_c pnt_t (+ dist_ct a_length)) ) ;undo (grdraw pnt_c pnt_new 3) ;(command "_.point" pnt_new) (make_line_1 "0" 2 pnt_old pnt_new) (setq nstep (1+ nstep) pnt_old pnt_new ) (make_line_1 "0" 3 pnt_old pnt_c) (setq temp_line (entlast)) (if (= (rem nstep 10) 0) (make_jpg)) (command "_.delay" 50) (command "_.redraw") ) (make_jpg) (command "_.delay" 1000) (entdel temp_line) );;;DRAW_CONCHOID ;;; ;; ;;-------------------------------------------------------------------------- (princ)