;;; pursuit_curve.lsp ;;; Takaya Iwamoto Nov 24,2002 ;;; Feb 9, 2005 modified input sequence ;;; Jun 5, 2005 added pursuit_3 case (ellipse) ;;; Aug 2, 2005 added JPG_YES flag for jpgout option ;;;Test for Pursuit curve ;;; ;;; Pursuit_linear The simple case The target runs along y-axis ;;; Pursuit_circle Target moves in a circle ;;; pursuit_ellipse Ellipse case isoclinal trajectories ;;; (defun c:Pursuit_linear() (setup_sysvar) (setup_pursuit_1) (make_jpg) (pursuit_1) (setq a_value (car pnt_a)) (if (= (Yes_or_No "Draw exact curve ?") "_Y") (draw_pursuit_curve rel_speed a_value)) (make_jpg) (command "_.redraw") (make_jpg) (reset_sysvar) );;;PURSUIT_LINEAR ;;; ;(prompt "loading pursuit_11") ;;; (defun c:Pursuit_11() (setup_sysvar) (setup_pursuit_1) (pursuit_1) (setq a_value (car pnt_a)) (if (= (Yes_or_No "Draw exact curve ?") "_Y") (draw_pursuit_curve2 x0 y0)) (reset_sysvar) );;;PURSUIT_11 ;;; ;(prompt "loading pursuit_circle") ;;; (defun c:Pursuit_circle() (setup_sysvar) (setup_pursuit_2) (make_jpg) (pursuit_2) (make_jpg) (command "_.delay" 1000) (command "_.redraw") (command "_.layer" "_Off" "layer8" "") (make_jpg) (reset_sysvar) );;;PURSUIT_CIRCLE ;;; ;;;PURSUIT_ELLIPSE Ellipse case isoclinal trajectories ;;; (defun C:PURSUIT_ellipse() (setup_sysvar) (setvar "OSMODE" 512) (setup_pursuit_3) (make_jpg) (pursuit_3) (make_jpg) (command "_.delay" 1000) (command "_.redraw") (command "_.layer" "_Off" "layer8" "") (make_jpg) ;;recover layer8 for display (command "_.layer" "_On" "layer8" "") (while (= (Yes_or_No "Want to start from another point on the same ellipse ? ") "_Y") (setq ncount 1) (entdel red_arrow) (entdel blue_arrow) (command "_.point" (setq pnt_c(getpoint "\nGet starting point of the dog(def = 0,1)"))) (if (= pnt_c nil) (setq pnt_c '(0 1)) ) (setq d_ref 1.e10 d_ab (distance pnt_a pnt_b) ) ;;; set arrow at the starting points (command "_.insert" "red_arrow" pnt_a 0.5 0.5 -90.) (setq red_arrow (entlast)) (command "_.insert" "blue_arrow" pnt_c 0.5 0.5 (setq theta_0 (rtd (angle pnt_a pnt_c))) ) (setq blue_arrow (entlast)) (setq theta_old theta_0) (pursuit_3) ) ;;;end of while loop (reset_sysvar) (setvar "OSMODE" 0) );;;PURSUIT_ELLIPSE ;;; ;;;SETUP_PURSUIT_1 ;;; (defun setup_pursuit_1() (setvar "PDMODE" 32) (setq pnt_o '(0 0) pnt_xr '(8 0) pnt_1 '(0 -5) pnt_2 '(0 5) pnt_y1 '(0 -5.25) pnt_y2 '(0 5) pnt_low '(5 -5) pnt_up '(5 10) pnt_mid '(5 0) ncount 0 ) (make_line_1 "0" 8 pnt_low pnt_up) (make_line_1 "0" 8 pnt_o pnt_xr) (make_line_1 "0" 8 pnt_y1 pnt_y2) (make_pt "0" 8 pnt_low) (make_pt "0" 8 pnt_mid) (make_pt "0" 8 pnt_up) (make_pt "0" 8 pnt_o) (command "_.zoom" "_EXTENT") (command "_.regen") (command "_.point" (setq pnt_1 (getpoint "\nGet starting point of the rabbit(def = 5,0)"))) (if (= pnt_1 nil) (setq pnt_1 pnt_mid)) (command "_.point" (setq pnt_2 (getpoint "\nGet target point of the rabbit(def = 5,10)"))) (if (= pnt_2 nil) (setq pnt_2 pnt_up)) (command "_.point" (setq pnt_3 (getpoint "\nGet starting point of the dog(def = 0,0)"))) (if (= pnt_3 nil) (setq pnt_3 pnt_o)) (setq rel_speed (getreal "\nRelative speed of the dog(def 2.0) ")) (if (= rel_speed nil) (setq rel_speed 2.0) ) (setq pnt_a pnt_1 pnt_b pnt_2 pnt_c pnt_3 d_ref 1.e10 ) (make_line_1 "0" 8 pnt_3 pnt_1) (setq rate (getreal "\nSpecify speed as a distance % of length AB:(def 0.5)")) (if (= rate nil) (setq rate 0.5)) (setq delta (* (distance pnt_a pnt_b) (/ rate 100.))) (setq speed (getint "\nSpecify speed (1-100) 1:veryfast 100:very slow(def 50)")) (if (= speed nil) (setq speed 50)) (setq d_ab (distance pnt_a pnt_b)) ;;;make two arrow blocks ;set arrow at the starting points (command "_.insert" "red_arrow" pnt_a 0.5 0.5 -90.) (setq red_arrow (entlast)) (command "_.insert" "blue_arrow" pnt_c 0.5 0.5 (setq theta_0 (rtd (angle pnt_a pnt_c))) ) (setq blue_arrow (entlast)) (setq theta_old theta_0) );;; ;;;PURSUIT for a straight line case (defun pursuit_1() (setup_sysvar) (initget 1 "Yes No yes no y n") (setq x (getkword "Ready to go ? (Yes or No)") ) (while (> d_ref delta) ;(while (> d_ca delta) (setq pnt_ab (pld pnt_a pnt_b delta) pnt_ca (pld pnt_c pnt_a (* rel_speed delta)) ) (slow_line speed "0" 1 pnt_a pnt_ab) (slow_line speed "0" 5 pnt_c pnt_ca) (setq theta_new (rtd (angle pnt_a pnt_c)) del_theta (- theta_new theta_old)) (grdraw pnt_ab pnt_ca 8 ) (command "_.move" red_arrow "" pnt_a pnt_ab) (command "_.move" blue_arrow "" pnt_c pnt_ca ) (command "_.rotate" blue_arrow "" pnt_ca del_theta) (setq pnt_a pnt_ab pnt_c pnt_ca theta_old theta_new ) (setq d_ab (distance pnt_a pnt_b) d_ca (distance pnt_c pnt_a) d_ref (min d_ab d_ca) ) (if (and (= (rem ncount 10) 0) (= JPG_YES 1)) (command "_.jpgout" (strcat "linear_pursuit_2_" (itoa ncount)) "") );;;end of if loop (setq ncount (1+ ncount)) ;;increment counter );;;end of while loop );;;PURSUIT_1 ;;; ;;;CIRCLE_CASE (defun setup_pursuit_2() (setvar "PDMODE" 32) (setq pnt_o '(0 0) pnt_xr '(16 0) pnt_xl '(-4 0) pnt_y1 '(0 -2.5) pnt_y2 '(0 2.5) ncount 0) (make_line_1 "0" 8 pnt_xl pnt_xr) (make_line_1 "0" 8 pnt_y1 pnt_y2) (command "_.zoom" "_EXTENT") (command "_.regen") (setq ref_rad (getreal "\nRadius of the circle (def 2.5)?")) (if (= ref_rad nil) (setq ref_rad 2.5)) (setq pnt_a (list ref_rad 0)) (make_circle_1 "0" 8 pnt_o ref_rad) ;set arrow at the starting points (command "_.insert" "red_arrow" pnt_a 0.5 0.5 -90.) (setq red_arrow (entlast)) ;(alert "This is the point where a rabit sits now.") ;(alert "Pick a point where a dog is now.") (command "_.point" (setq pnt_3 (getpoint "\nSet the position of the dog:(def 10,0)"))) (if (= pnt_3 nil) (setq pnt_3 '(10 0))) (setq pnt_c pnt_3) (make_pt "0" 1 pnt_a) (make_pt "0" 5 pnt_c) (command "_.insert" "blue_arrow" pnt_c 0.5 0.5 (setq theta_0 (rtd (angle pnt_a pnt_c))) ) (setq blue_arrow (entlast)) (command "_.zoom" "_EXTENT") (command "_.regen") (setq d_ref 1.e10 half_pi (* 0.5 pi) two_pi (* 2. pi) ) (setq rate (getreal "\nSpecify the speed of the rabbit on the circle path in radian:(def 0.05)")) (if (= rate nil) (setq rate 0.05)) (setq rel_speed (getreal "\nRelative speed of the pursuing dog(def 1.25)")) (if (= rel_speed nil) (setq rel_speed 1.25)) (setq speed (getint "\nSpecify speed (1-100) 1:veryfast 100:very slow (def 50)")) (if (= speed nil) (setq speed 50)) (setq delta (* rate rel_speed ref_rad) theta_old theta_0 th_old 0. rot_old (- half_pi) ) (make_jpg) );;;SETUP_PURSUIT_2 ;;; ;;;PURSUIT for a circle case (defun pursuit_2() (initget 1 "Yes No Y N yes no") (setq x (getkword "Ready to go ? (Yes or No)") ) (setq d_ca 1.e10) (while (> d_ca (* rate ref_rad)) (setq th_new (+ th_old rate)) (if (>= th_new two_pi) (setq th_new (- th_new two_pi))) (setq pnt_ab (list (* ref_rad (cos th_new)) (* ref_rad (sin th_new)) ) pnt_ca (pld pnt_c pnt_a delta) ) (slow_line speed "0" 1 pnt_a pnt_ab) (slow_line speed "0" 5 pnt_c pnt_ca) (setq theta_new (rtd (angle pnt_a pnt_c)) del_theta (- theta_new theta_old) del_th (rtd (- th_new th_old)) ) ;(grdraw pnt_ab pnt_ca 8 ) (make_line_1 "layer8" 8 pnt_ab pnt_ca) (command "_.move" red_arrow "" pnt_a pnt_ab) (command "_.rotate" red_arrow "" pnt_ab del_th) (command "_.move" blue_arrow "" pnt_c pnt_ca ) (command "_.rotate" blue_arrow "" pnt_ca del_theta) (setq pnt_a pnt_ab pnt_c pnt_ca theta_old theta_new th_old th_new ) (setq d_ca (distance pnt_c pnt_a)) (if (and (= (rem ncount 10) 0) (= JPG_YES 1)) (make_jpg) );;;end of if loop (setq ncount (1+ ncount)) ;;increment counter );;;end of while loop );;;PURSUIT_2 ;;; ;;; ARROW_BLOCK (used for defining red_arrow, blue_arrow) ;;; But once the definition is done, it is not used anymore. (defun arrow_block() (command "_.color" 1) (command "_.pline" '(0 0) '(0.433 0.25 ) '(0.433 -0.25 ) '(0 0) '(1 0) "") (setq red_pl (entlast)) (command "_.hatch" "_solid" red_pl "") (setq temp_arrow (entlast)) (command "_.block" "red_arrow" '(0 0) temp_arrow red_pl "") (command "_.color" 5) (command "_.pline" '(0 0) '(0.433 0.25 ) '(0.433 -0.25 ) '(0 0) '(1 0) "") (setq blue_pl (entlast)) (command "_.hatch" "_solid" blue_pl "") (setq temp_arrow (entlast)) (command "_.bock" "blue_arrow" '(0 0) temp_arrow blue_pl"") );;;arrow_block ;; (defun draw_pursuit_curve(k_value a_value) (setq x_start 0.0 x_end a_value x_inc 0.001 a (float a_value) k (float k_value) pow_1 (/ (- k 1.) k) pow_2 (/ (+ k 1.) k) const1 (/ (expt a (/ 1. k)) (- 1. k)) const2 (/ (expt a (- (/ 1. k))) (+ 1. k) ) const3 (- (/ (* 2 a) (* (- 1. k) (+ k 1.)))) ) (setq pnt_start (list x_start 0.0) pnt_end (list x_end 0.0) ) (setq del_x (- x_end x_start) n_step (/ del_x x_inc) ) (setq step 0) (setq pnt_old (list x_start (f_x x_start))) (while (<= (setq x_t (+ x_start (* step x_inc))) x_end) (setq x_t (+ x_start (* step x_inc)) y_t (f_x x_t) ) (setq pnt_new (list x_t y_t)) (command "_.line" pnt_old pnt_new "") (setq pnt_old pnt_new) (setq step (+ 1 step)) ) );;;DRAW_PURSUIT_CURVE ;(prompt "loading f_x") ;;; (defun f_x(x_value ) (setq amx (- a x_value) x1 (* 0.5 k const1 (expt amx pow_1)) x2 (* 0.5 k const2 (expt amx pow_2)) x3 (* 0.5 k const3) result (+ x1 x2 x3) ) );;;F_X ;(prompt "loading curve2") ;; (defun draw_pursuit_curve2(x0 y0) (setq x0 (car pnt_3) y0 (cadr pnt_3) r0 (sqrt (+ (* x0 x0) (* y0 y0)) ) c1 (+ y0 r0) c2 (- y0 r0) c3 (- (* 3. y0) r0) x_start x0 x_end 0.0 x_inc 0.001 ) (setq pnt_start pnt_3 pnt_end (list x_end 0.0) ) (setq del_x (- x_end x_start)) (setq step 0) (setq pnt_old (list x_start (f2_x x_start))) (while (>= (setq x_t (- x_start (* step x_inc))) x_end) (setq x_t (- x_start (* step x_inc)) y_t (f2_x x_t) ) (setq pnt_new (list x_t y_t)) (command "_.line" pnt_old pnt_new "") (setq pnt_old pnt_new) (setq step (+ 1 step)) ) );;;DRAW_PURSUIT_CURVE ;(prompt "loading f2_x") ;;; (defun f2_x(x_value ) (setq eta (* (/ x_value x0) (/ x_value x0) ) x1 (* 0.25 c1 eta) x2 (* 0.25 c2 (log eta)) x3 (* 0.25 c3 ) result (+ x1 x2 x3) ) );;;F2_X ;;;SETUP_PURSUIT_3 ;;; (defun setup_pursuit_3() (setvar "PDMODE" 32) (command "_.viewres" "_Y" 20000) (setq pnt_o '(0 0) pnt_xr '(1.6 0) pnt_xl '(-1.6 0) pnt_ylow '(0 -1.05) pnt_yup '(0 1.3) ncount 1 ) (make_line_1 "0" 8 pnt_xl pnt_xr) (make_line_1 "0" 8 pnt_ylow pnt_yup) (command "_.zoom" "_EXTENT") (command "_.regen") (setq major_axis (getreal "\nMajor axis radius ( a ) =")) (if (= major_axis nil) (setq major_axis 2.0)) (setq minor_axis (getreal "\nMinor axis radius ( b ) =")) (if (= minor_axis nil) (setq minor_axis 1.0)) (setq pnt_pa (list major_axis 0) pnt_ma (list (- major_axis) 0) pnt_pb (list 0 minor_axis) ) (command "_.ellipse" pnt_ma pnt_pa pnt_pb) (setq base_ellipse (entlast)) (make_pt "0" 0 pnt_pa ) (make_pt "0" 0 pnt_ma ) (make_pt "0" 0 pnt_pb ) (command "_.zoom" "_E") (setq c_val (sqrt (- (* major_axis major_axis) (* minor_axis minor_axis)) ) pnt_f1 (list (- c_val) 0) pnt_f2 (list c_val 0) def_target '(1 0) def_speed (/ major_axis c_val) ) (make_pt "0" 8 pnt_f1 ) (make_pt "0" 8 pnt_f2 ) (command "_.point" (setq pnt_1 (getpoint "\nGet starting point of the rabbit(def=focus)"))) (if (= pnt_1 nil) (setq pnt_1 pnt_f1)) (command "_.point" (setq pnt_2 (getpoint "\nGet target point of the rabbit(def = 0,0)"))) (if (= pnt_2 nil) (setq pnt_2 '(1 0)) ) (command "_.point" (setq pnt_3 (getpoint "\nGet starting point of the dog(def = 0,1)"))) (if (= pnt_3 nil) (setq pnt_3 '(0 1)) ) (setq rel_speed (getreal "\nRelative speed of the dog(def= a/c) ")) (if (= rel_speed nil) (setq rel_speed def_speed) ) (setq pnt_a pnt_1 pnt_b pnt_2 pnt_c pnt_3 d_ref 1.e10 ) (make_line_1 "0" 8 pnt_a pnt_c) ;;;initial chase direction (setq delta (getreal "\nSpecify a unit length of stride for a rabbit(def 0.01)")) (if (= delta nil) (setq delta 0.01)) (setq speed (getint "\nSpecify speed (1-100) 1:veryfast 100:very slow(def 50)")) (if (= speed nil) (setq speed 50)) (setq d_ab (distance pnt_a pnt_b)) ;set arrow at the starting points (command "_.insert" "red_arrow" pnt_a 0.5 0.5 -90.) (setq red_arrow (entlast)) (command "_.insert" "blue_arrow" pnt_c 0.5 0.5 (setq theta_0 (rtd (angle pnt_a pnt_c))) ) (setq blue_arrow (entlast)) (setq theta_old theta_0) ;;;jpgout option case (make_jpg) );;; ;;;PURSUIT for multiple pursuit case. (defun pursuit_3( ; / pnt_as pnt_cs pnt_newa pnt_newc theta_new theta_old ;d_ab d_ca ) (initget 1 "Yes No yes no y n") (setq x (getkword "Ready to go ? (Yes or No)") ) (setq pnt_as pnt_a pnt_cs pnt_c delta_0 delta) (while (> d_ref delta_0) (setq pnt_newa (pld pnt_as pnt_b delta) pnt_newc (pld pnt_cs pnt_as (* rel_speed delta)) ) (slow_line speed "0" 1 pnt_as pnt_newa) (slow_line speed "0" 5 pnt_cs pnt_newc) (setq theta_new (rtd (angle pnt_as pnt_cs)) del_theta (- theta_new theta_old)) ;(grdraw pnt_newa pnt_newc 8 ) (make_line_1 "layer8" 8 pnt_newa pnt_newc) (command "_.move" red_arrow "" pnt_as pnt_newa) (command "_.move" blue_arrow "" pnt_cs pnt_newc ) (command "_.rotate" blue_arrow "" pnt_newc del_theta) (setq pnt_as pnt_newa pnt_cs pnt_newc theta_old theta_new ) (setq d_ab (distance pnt_as pnt_b) d_ca (distance pnt_newc pnt_newa) d_ref (min d_ab d_ca) ) ( if (< d_ca 0.5) (setq delta_0 (* 0.5 delta)));;;improves accuracy ??? (if (= (rem ncount 20) 0) (make_pt "0" 0 pnt_newc) ) (if (and (= (rem ncount 10) 0) (= JPG_YES 1)) (make_jpg) );;;end of if loop (setq ncount (1+ ncount)) ;;increment counter );;;end of while loop (make_pt "0" 0 pnt_as) (make_pt "0" 0 pnt_cs) );;;PURSUIT_3 ;;; ;;; ;(prompt "loading curve4") ;; (defun draw_pursuit_curve4(x0 y0) (setq x0 (car pnt_3) y0 (cadr pnt_3) r0 (sqrt (+ (* x0 x0) (* y0 y0)) ) c1 (+ y0 r0) c2 (- y0 r0) c3 (- (* 3. y0) r0) x_start x0 x_end 0.0 x_inc 0.001 ) (setq pnt_start pnt_3 pnt_end (list x_end 0.0) ) (setq del_x (- x_end x_start)) (setq step 0) (setq pnt_old (list x_start (f4_x x_start))) (while (>= (setq x_t (- x_start (* step x_inc))) x_end) (setq x_t (- x_start (* step x_inc)) y_t (f4_x x_t) ) (setq pnt_new (list x_t y_t)) (command "_.line" pnt_old pnt_new "") (setq pnt_old pnt_new) (setq step (+ 1 step)) ) );;;DRAW_PURSUIT_CURVE4 ;(prompt "loading f4_x") ;;; (defun f4_x(x_value ) (setq x1 (* C1 (expt (/ x_value a_val) (+ K 1))) x2 (* C2 (expt (/ x_value a_val) (- 1 K))) result (+ x1 x2 Const) ) );;;F4_X ;;;Test case for ellipse ;;;SETUP_PURSUIT_4 ;;; (defun setup_pursuit_4() (setvar "PDMODE" 32) (command "_.viewres" "_Y" 20000) (setq pnt_o '(0 0) pnt_xr '(2 0) pnt_xl '(-2 0) pnt_ylow '(0 -2.5) pnt_yup '(0 2.5) ) (make_line_1 "0" 8 pnt_xl pnt_xr) (make_line_1 "0" 8 pnt_ylow pnt_yup) (command "_.zoom" "_EXTENT") (command "_.regen") (setq major_axis (getreal "\nMajor axis radius ( a ) =")) (if (= major_axis nil) (setq major_axis 1.0)) (setq minor_axis (getreal "\nMinor axis radius ( b ) =")) (if (= minor_axis nil) (setq minor_axis 2.0)) (setq pnt_pa (list major_axis 0) pnt_ma (list (- major_axis) 0) pnt_pb (list 0 minor_axis) ) (command "_.ellipse" pnt_ma pnt_pa pnt_pb) (setq base_ellipse (entlast)) (make_pt "0" 0 pnt_pa ) (make_pt "0" 0 pnt_ma ) (make_pt "0" 0 pnt_pb ) (setq c_val (sqrt (- (* minor_axis minor_axis) (* major_axis major_axis) ) ) pnt_f1 (list 0 (- c_val) ) def_target '(1 0) def_speed (/ minor_axis c_val) a_val major_axis b_val minor_axis k (/ c_val b_val) alpha (/ (+ b_val c_val) a_val) C1 (* 0.5 alpha (/ a_val (+ K 1.))) C2 (- (* 0.5 (/ a_val (* alpha (- 1. K))) )) Const (- (+ C1 C2)) ) (make_pt "0" 0 pnt_f1 ) ;(command "_.point" (setq pnt_1 (getpoint "\nGet starting point of the rabbit(def=focus)"))) ; (if (= pnt_1 nil) (setq pnt_1 pnt_f1)) ;(command "_.point" (setq pnt_2 (getpoint "\nGet target point of the rabbit(def = 1,0)"))) ; (if (= pnt_2 nil) (setq pnt_2 '(1 0)) ) ;(command "_.point" (setq pnt_3 (getpoint "\nGet starting point of the dog(def = 0,1)"))) ; (if (= pnt_3 nil) (setq pnt_3 '(0 1)) ) ;(setq rel_speed (getreal "\nRelative speed of the dog(def= 1.15470) ")) ; (if (= rel_speed nil) (setq rel_speed def_speed) ) ;(setq pnt_a pnt_1 ; pnt_b pnt_2 ; pnt_c pnt_3 ; d_ref 1.e10 ;) ;(setq delta (getreal "\nSpecify a unit length of stride for a rabbit(def 0.01)")) ; (if (= delta nil) (setq delta 0.01)) ;(setq speed (getint "\nSpecify speed (1-100) 1:veryfast 100:very slow(def 50)")) ; (if (= speed nil) (setq speed 50)) ;(setq d_ab (distance pnt_a pnt_b)) ;;set arrow at the starting points ;(command "_.insert" "red_arrow" pnt_a 0.5 0.5 -90.) ; (setq red_arrow (entlast)) ;(command "_.insert" "blue_arrow" pnt_c 0.5 0.5 (setq theta_0 (rtd (angle pnt_a pnt_c))) ) ; (setq blue_arrow (entlast)) ;(setq theta_old theta_0) );;; ;;; ;;;COPY_SCALE copy and then scale the copied entity ;;; (defun copy_scale(ent_base base_pnt scale_f / copy_ent ) (command "_.copy" ent_base "" base_pnt "") (setq copy_ent (entlast)) (command "_.scale" copy_ent "" base_pnt scale_f ) );;;COPY_SCALE ;;; ;;;Draw scaled ellipses based on the base_ellipse ;;; (defun scale_ellipse(ent_base) (setq pnt_0 '(0 0)) (while (setq pnt_x (getpoint "\nSelect a point to define half major_axis length")) (setq ref_len (abs (car pnt_x)) base_len (abs (car pnt_ma)) scale_f (/ ref_len base_len) ) (copy_scale ent_base pnt_0 scale_f) );end of while loop );;;SCALE_ELLIPSE ;;;