;;; UTILITY_CURVES.LSP ;;;collection of special curves drawing utility ;;; ;;; ;;; 1. conchoid ;;; 2. cissoid ;;; 3. conics ;;; 4. Concentric_circles used in Archimedian Spiral ;;; 5. Multiple_rays used in Archimedian Spiral & Quadratrix ;;; ;;; Jan 18, 2006 by Takaya Iwamoto ;;; Feb 4,2006 added Concentrated_circles and Multiple_rays ;;; Nov 26,2006 modified test_conchoid ;;; ;;;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 ;(setup_sysvar) (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) (command "_.zoom" "_Extent") ;;;Input data (setq pnt_a (getpoint "\nGet point A (def '(-4 0)): ") pnt_b (getpoint "\nGet point B (def '(4 0)): ") pnt_c (getpoint "\nGet point C (def '(0 -1)): ") a_length (getreal "\nSpecify constant length a (def 2): ") n_div (getint "\nSpecify number of division between A & B (def 100): ") ) ;;;default section (if (= pnt_a nil) (setq pnt_a pnt_a_def)) (if (= pnt_b nil) (setq pnt_b pnt_b_def)) (if (= pnt_c nil) (setq pnt_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" pnt_a) (command "_point" pnt_b) (command "_point" pnt_c) ;;;draw conchoid (conchoid_draw pnt_a pnt_b pnt_c a_length n_div) ;(command "_.zoom" "_Extent") ;(command "_.regen") );;;TEST_CONCHOID ;;; ;;; ;;;DRAW_CONCHOID ;;; pnt_a, pnt_b end coordinate of line AB (ruler) ;;; pnt_v 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 n_div)) nstep 1 dist_ca (distance pnt_c pnt_a) pnt_old (pld pnt_c pnt_a (+ dist_ca a_length)) ) (repeat n_div (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 ;(command "_.point" pnt_new) (make_line_1 "0" 2 pnt_old pnt_new) (setq nstep (1+ nstep) pnt_old pnt_new ) ) );;;DRAW_CONCHOID ;;; ;;; (prompt "\nLoading TEST_CONICS") ;;;DRAW_CONICS ;;; ;;;General routine using the CONICS EQUATION ;;; y^2 + (1-e^2)x^2 -2kx + k^2 = 0 ;;; ;;; Select a focus point PNT_A ;;; Select a directrix end points PNT_B & PNT_C ;;; Specify eccentricity E_VALUE ;;; e < = > 1.0 , Ellipse, Parabola & HYperbola ;;; specify Y-range Y_MIN & Y_MAX ;;; ;;; (defun C:test_conics() (setup_test) (setq y_inc 0 x_min 0 y_min 0 y_max 0) (draw_conics pnt_a pnt_b pnt_c e_value x_inc y_inc x_min x_max y_min y_max n_pnt) (reset_sysvar) );;;test_conics ;;; ;;; (prompt "\nLoading DRAW_CONICS") ;;;DRAW_CONICS ;;; (defun draw_conics(pnt_a pnt_b pnt_c e_value x_inc y_inc x_min x_max y_min y_max n_pnt / nstep pnt_t ) ;if e < 1 , ellipse ; e = 1 . parabola ; e > 1 . hyperbola ;;;try hyperbola case here (setq nstep 1 pnt_old (conic_formula_x x_start e_value k_val) ) (repeat n_pnt (setq x_t (* nstep x_inc) pnt_new (conic_formula_x x_t e_value k_val) ) (command "_.point" pnt_new) (make_line_1 "0" 2 pnt_old pnt_new) (setq nstep (1+ nstep) pnt_old pnt_new ) ) );;;DRAW_CONICS ;;; ;;;conic_formula_x ;;;conic formula to get Y^2 value form x_value given ;;; Y^2 = e^2*x^2 - (x-k)^2 ;;; (defun conic_formula_x(x_val e_val k_val / pnt_temp) (setq ex (* e_val x_val) x_m_k (- x_val k_val) result (- (* ex ex) (* x_m_k x_m_k)) ) (setq pnt_temp (list x_val (sqrt result))) );;;conic_formula_x ;;; ;;; (prompt "\nLoading setup_test") ;;;SETUP_TEST ;;; (defun setup_test() (setup_sysvar) (setvar "PDMODE" 32) (setvar "PDSIZE" -3) ;;;input parameters (setq pnt_a (getpoint "\nSelect a focus point(def = '(3 0))") pnt_b (getpoint "\nSelect one end of directrix (def = '(0 -3))") pnt_c (getpoint "\nSelect the other end of directrix (def = '(0 3))") e_value (getreal "\nInput eccentricity value (def = 2.0)") ) ;;;default values setting if inputs for Pnt_a,pnt_b, pnt_c, e_value are nil. (if (= pnt_a nil) (setq pnt_a '(3 0)) ) (if (= pnt_b nil) (setq pnt_b '(0 -3)) ) (if (= pnt_c nil) (setq pnt_c '(0 3)) ) (if (= e_value nil) (setq e_value 2.0) ) ;;case for hyperbola (setq k_val (car pnt_a) x_zero (list (car pnt_b) 0) p_start (plt x_zero pnt_a (/ 1. 3)) ) (setq x_inc (getreal "\nInput increment in X-direction (def = 1/100)") ) (if (= x_inc nil) (setq x_inc 0.01)) (setq x_max (getreal "\nInput maximum range for X(def = 2k)") ) (if (= x_max nil) (setq x_max (* 2. k_val)) ) (setq n_pnt (getint "\nHow many points ? (def = 100)") ) (if (= n_pnt nil) (setq n_pnt 100) ) );;;SETUP_TEST (prompt "\nloading concentric_circles") ;;;***************Concentric_Circles************************ ;;;Used in drawing Archimedian Circles ;;; (defun Concentric_Circles( / radius step pnt_org R_base R_inc N_circles) (setq pnt_org (getpoint "\nCenter of circles(def = (0 0)") R_base (getreal "\nRadius of the base circle (def 0.1)") R_inc (getreal "\nIncrement of radius (def = 0.1)") N_circles (getint "\nNumber of circles incl. base circle(def = 10)") ) ;;;default setting so that excution will not stop (if (= pnt_org nil) (setq pnt_org '(0 0)) ) (if (= R_base nil) (setq R_base 0.1) ) (if (= R_inc nil) (setq R_inc 0.1) ) (if (= N_circles nil) (setq N_circles 10) ) (setq step 0) (repeat N_circles (setq radius (+ R_base (* step R_inc))) (make_circle_1 "layer8" 8 pnt_org radius) (setq step (1+ step)) ) );;;CONCENTRIC_CIRCLES ;;; (prompt "\nloading mutiple_rays") ;;;***************Multiple_Rays************************ ;;;Used in drawing Archimedian Circles, Quadratrix ;;; (defun Multiple_Rays( / ray_end step pnt_org Ray_len Ang_inc N_rays) (setq pnt_org (getpoint "\nRays Origin(def = (0 0)") Ray_len (getreal "\nLength of Ray (def 1.0)") Ang_inc (getreal "\nIncrement of angle in deg(def = 9 degrees)") N_rays (getint "\nNumber of rays(def = 21)") ) ;;;default setting so that excution will not stop (if (= pnt_org nil) (setq pnt_org '(0 0)) ) (if (= Ray_len nil) (setq Ray_len 1.0) ) (if (= Ang_inc nil) (setq Ang_inc 9) ) (if (= N_rays nil) (setq N_rays 21) ) (setq step 0) (repeat N_rays (setq ray_end (polar pnt_org (dtr (* step Ang_inc)) Ray_len)) (make_line_1 "layer8" 8 pnt_org ray_end) (setq step (1+ step)) ) );;;Multiple_Rays ;;;