;;; brocard.lsp ;;; Takaya Iwamoto Oct 24,2001 ;;; added Vports Feb 15,2005 ;;; modified for doc June 16,2005 ;;; added ndogs June 17,2005 ;;; use make_polyline API for entmake POLYLINE ;;;*********************************************** ;;; copyright 2006 Takaya Iwamoto ;;;*********************************************** ;;;Test for Brocard angle ;;; (defun c:Brocard () (setup_tri) (pursuit) ) ;;;BROCARD (prompt "BROCARD ") ;;; (defun c:Brocard2_ccw () (setup_tri_ccw) (command "_.point" pnt_br1) (alert "Hit OK to start") (command "_.vports" "2" "_V") (setvar "CVPORT" 3) (command "_.zoom" "_Extent") (setvar "CVPORT" 2) (command "_.zoom" "_Extent") (make_jpg) (pursuit2_ccw) (reset_sysvar) ) ;;;BROCARD (prompt "BROCARD2_CCW ") ;;; ;;; ;;; (defun c:Brocard2_cw () (setup_tri_cw) (command "_.point" pnt_br2) (alert "Hit OK to start") (command "_.vports" "2" "_V") (setvar "CVPORT" 3) (command "_.zoom" "_Extent") (setvar "CVPORT" 2) (command "_.zoom" "_Extent") (make_jpg) (pursuit2_cw) (reset_sysvar) ) ;;;BROCARD (prompt "BROCARD2_CW ") ;;; ;;;Test for 4-dogs ;;; (defun c:4dogs () (setup_sysvar) (setup_square) (pursuit_4dogs) (reset_sysvar) ) ;;;4dogs (prompt "4dogs") ;;; ;;;SETUP_TRI_CCW counter clockwise case setup ;;; (defun setup_tri_ccw () (setup_sysvar) (setvar "PDMODE" 32) (setq pnt_1 '(4.1838 0.382549 0.0) pnt_2 '(20.4652 0.382549 0.0) pnt_3 '(14.6504 13.3892 0.0) len_12 (distance pnt_1 pnt_2) ) (mark_id pnt_1 "1" 4 0.5) (mark_id pnt_2 "2" 4 0.5) (mark_id pnt_3 "3" 3 0.5) (make_line_1 "0" 0 pnt_1 pnt_2) (make_line_1 "0" 1 pnt_1 pnt_2) (setq line_ab (entlast)) (make_line_1 "0" 0 pnt_2 pnt_3) (make_line_1 "0" 2 pnt_2 pnt_3) (setq line_bc (entlast)) (make_line_1 "0" 0 pnt_3 pnt_1) (setq pnt_a pnt_1 pnt_b pnt_2 pnt_c pnt_3 ncount 0 ) (command "_.zoom" "_EXTENT") ;;;compute Brocard angle omega omega_d (in deg) omega_r (in radian) (c:omega) ;;;locate Brocard point (pnt_br1) for CCW rotation using omega value ;;; arc_length is the total travel path for a dog that sits at pnt_1 initially. (c:find_brocard_1) (setq rate 1. ;;;(getreal "\nSpecify distance as % of length AB: ") delta (* (distance pnt_a pnt_b) (/ rate 100.)) delta_bc (* delta ratio_ab) delta_ca (* delta ratio_ac) 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) d_bc (distance pnt_b pnt_c) d_ca (distance pnt_c pnt_a) d_ref (/ d_ab len_12) ) (entdel line_ab) (entdel line_bc) ;;;insert precision_meter ;;;display the value of the minimum distance between apexes = d_ref ;block insert prec_meter.dwg (setq ins_pnt '(7. -3) meter_scale 3.0 m_x (car ins_pnt) m_y (cadr ins_pnt) pm_factor (* 0.25 (/ 1. (log 10.))) ) (my_block_insert "prec_meter" ins_pnt meter_scale) ;display initial bar (my_block_insert "prec_bar" ins_pnt meter_scale) (setq old_bar (entlast)) ;;;prec_bar just created ;;; (move_bar d_ref meter_scale) ) ;;; ;;;(prompt "SETUP_TRI_CW") ;;;SETUP_TR_CW counter clockwise case setup ;;; (defun setup_tri_cw () (setup_sysvar) (setvar "PDMODE" 32) (setq pnt_1 '(4.1838 0.382549 0.0) pnt_2 '(20.4652 0.382549 0.0) pnt_3 '(14.6504 13.3892 0.0) len_12 (distance pnt_1 pnt_2) ) (mark_id pnt_1 "1" 4 0.5) (mark_id pnt_2 "2" 4 0.5) (mark_id pnt_3 "3" 3 0.5) (make_line_1 "0" 0 pnt_1 pnt_2) (make_line_1 "0" 1 pnt_1 pnt_2) (setq line_ab (entlast)) (make_line_1 "0" 0 pnt_2 pnt_3) (make_line_1 "0" 2 pnt_2 pnt_3) (setq line_bc (entlast)) (make_line_1 "0" 0 pnt_3 pnt_1) (setq pnt_a pnt_1 pnt_b pnt_2 pnt_c pnt_3 ncount 0 ) (command "_.zoom" "_EXTENT") ;;;compute Brocard angle omega omega_d(deg) omega_r(radian) (c:omega) ;;;locate Brocard point for Clockwise chase case using omega angle--pnt_br2 ;;;arc_length is the total travel path for a dog taht sits initially at pnt_1 (c:find_brocard_2) (setq rate 1. ;;;(getreal "\nSpecify distance as % of length AB: ") delta (* (distance pnt_a pnt_b) (/ rate 100.)) delta_bc (* delta ratio_ab) delta_ca (* delta ratio_ac) 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) d_bc (distance pnt_b pnt_c) d_ca (distance pnt_c pnt_a) d_ref (/ d_ab len_12) ) (entdel line_ab) (entdel line_bc) ;;;insert precision_meter ;;;display the value of the minimum distance between apexes = d_ref ;block insert prec_meter.dwg (setq ins_pnt '(7. -3) meter_scale 3.0 m_x (car ins_pnt) m_y (cadr ins_pnt) pm_factor (* 0.25 (/ 1. (log 10.))) ) (my_block_insert "prec_meter" ins_pnt meter_scale) ;display initial bar (my_block_insert "prec_bar" ins_pnt meter_scale) (setq old_bar (entlast)) ;;;prec_bar just created ;;; (move_bar d_ref meter_scale) ) ;;; ;;;(prompt "SETUP_SQUARE") ;;; ;;; (defun setup_square () (setq pnt_1 '(-100. -100. 0) pnt_2 '(100. -100. 0) pnt_3 '(100. 100. 0) pnt_4 '(-100. 100. 0) Arc_len 200. ) (command "_.pline" pnt_1 pnt_2 pnt_3 pnt_4 "cl") (mark_id pnt_1 "A" 3 10) (mark_id pnt_2 "B" 1 10) (mark_id pnt_3 "C" 1 10) (mark_id pnt_4 "D" 3 10) (setq side_len (distance pnt_1 pnt_2) pnt_a pnt_1 pnt_b pnt_2 pnt_c pnt_3 pnt_d pnt_4 ncount 0 ) (command "_.zoom" "_EXTENT") (setq rate (getreal "\nSpecify dog's stride as % of length AB:(def=10%)" ) ) (if (= rate nil) (setq rate 10.) ) (setq delta (* side_len (/ rate 100.)) speed (getint "\nSpecify display speed (1-100) 1:veryfast 100:very slow (def = 50)" ) ) (if (= speed nil) (setq speed 50) ) (setq d_ref side_len n_repeat (+ 2 (fix (/ 100 rate))) ) ) ;;; ;;;(prompt "PURSUIT") ;;; ;;;PURSUIT for a Triangle case (defun pursuit () (while (> d_ref delta) ;;(repeat n_repeat (setq pnt_ab (pld pnt_a pnt_b delta) pnt_bc (pld pnt_b pnt_c delta_bc) pnt_ca (pld pnt_c pnt_a delta_ca) ) (slow_line speed "0" 1 pnt_a pnt_ab) (slow_line speed "0" 3 pnt_b pnt_bc) (slow_line speed "0" 5 pnt_c pnt_ca) (command "_.pline" pnt_ab pnt_bc pnt_ca "c") (setq pnt_a pnt_ab pnt_b pnt_bc pnt_c pnt_ca ) (setq d_ab (distance pnt_a pnt_b) d_bc (distance pnt_b pnt_c) d_ca (distance pnt_c pnt_a) d_ref (min d_ab d_bc d_ca) ) (setq ncount (1+ ncount)) ) ;;;end of while(or repeat) loop ) ;;;PURSUIT (prompt "PURSUIT ") ;;; ;;;PURSUIT for a square case (defun pursuit_4dogs () (setvar "CECOLOR" "8") (while (> d_ref delta) ;;(repeat n_repeat (setq pnt_ab (pld pnt_a pnt_b delta) pnt_bc (pld pnt_b pnt_c delta) pnt_cd (pld pnt_c pnt_d delta) pnt_da (pld pnt_d pnt_a delta) ) (slow_line speed "layer1" 1 pnt_a pnt_ab) (slow_line speed "layer2" 2 pnt_b pnt_bc) (slow_line speed "layer3" 3 pnt_c pnt_cd) (slow_line speed "layer5" 5 pnt_d pnt_da) (command "_.pline" pnt_ab pnt_bc pnt_cd pnt_da "c") (setq pnt_a pnt_ab pnt_b pnt_bc pnt_c pnt_cd pnt_d pnt_da ) (setq d_ab (distance pnt_a pnt_b) d_bc (distance pnt_b pnt_c) d_cd (distance pnt_c pnt_d) d_da (distance pnt_d pnt_a) d_ref (min d_ab d_bc d_cd d_da) ) (setq ncount (1+ ncount)) ) ;;;end of while loop (setvar "CECOLOR" "BYLAYER") ) ;;;PURSUIT_4dogs (prompt "PURSUIT_4dogs") ;;; ;;;PURSUIT for a Triangle case (defun pursuit2_ccw () (setq total_count 0 delta (* 0.01 arc_length) delta_bc (* delta ratio_ab) delta_ca (* delta ratio_ac) factor 0.5075 ) (while (> d_ab delta) (setq pnt_ab (pld pnt_a pnt_b delta) pnt_bc (pld pnt_b pnt_c delta_bc) pnt_ca (pld pnt_c pnt_a delta_ca) ) (slow_line speed "0" 1 pnt_a pnt_ab) (slow_line speed "0" 3 pnt_b pnt_bc) (slow_line speed "0" 5 pnt_c pnt_ca) ;(command "_.pline" pnt_ab pnt_bc pnt_ca "c") (if (= (rem total_count 10) 0) (make_jpg)) (setq total_path (* ncount delta)) ;;;total distance traveled (setq pnt_a pnt_ab pnt_b pnt_bc pnt_c pnt_ca ) (setq d_ab (distance pnt_a pnt_b) d_bc (distance pnt_b pnt_c) d_ca (distance pnt_c pnt_a) d_ref (/ d_ab len_12) ) ;;;precision bar display (move_bar d_ref meter_scale) (setq total_count (1+ total_count)) (setq ncount (1+ ncount)) (if (= ncount 50) (progn (zoom_area_brocard) (setq ncount 1) (setq delta (* factor delta)) (setq delta_bc (* factor delta_bc)) (setq delta_ca (* factor delta_ca)) ) ) ) ;;;end of while loop ) ;;;PURSUIT2_ccw (prompt "PURSUIT2_ccw ") ;;; ;;;PURSUIT for a Triangle case (defun pursuit2_cw () (setq total_count 0 delta (* 0.01 arc_length) delta_b (* delta ratio_ab) delta_c (* delta ratio_ac) factor 0.5075 ) (while (> d_ab delta) (setq pnt_ac (pld pnt_a pnt_c delta) pnt_cb (pld pnt_c pnt_b delta_c) pnt_ba (pld pnt_b pnt_a delta_b) ) (slow_line speed "0" 1 pnt_a pnt_ac) (slow_line speed "0" 3 pnt_b pnt_ba) (slow_line speed "0" 5 pnt_c pnt_cb) ;(command "_.pline" pnt_ab pnt_bc pnt_ca "c") (if (= (rem total_count 10) 0) (make_jpg) ) (setq total_path (* ncount delta)) ;;;total distance traveled (setq pnt_a pnt_ac pnt_b pnt_ba pnt_c pnt_cb ) (setq d_ab (distance pnt_a pnt_b) d_bc (distance pnt_b pnt_c) d_ca (distance pnt_c pnt_a) d_ref (/ d_ab len_12) ) ;;;precision bar display (move_bar d_ref meter_scale) (setq total_count (1+ total_count)) (setq ncount (1+ ncount)) (if (= ncount 50) (progn (zoom_area_brocard) (setq ncount 1) (setq delta (* factor delta)) (setq delta_b (* factor delta_b)) (setq delta_c (* factor delta_c)) ) ) ) ;;;end of while loop ) ;;;PURSUIT2_cw (prompt "PURSUIT2_cw ") ;;;COPY_ROTATE (defun C:copy_rotate () ;Copy the entity data points, layer, color (setq base_line (entsel "Select an object") line_list (entget (car base_line)) new_ent (list (assoc 0 line_list) (assoc 8 line_list) (assoc 10 line_list) (assoc 11 line_list) ) ) ;Make a new entity (entmake new_ent) (setq new_obj (entlast)) ;specify a center of rotation (setq rot_pnt (entsel "\nSelect a center of rotation")) (setq rot_angle (getreal "\nInput rotation angle in degrees: ") ) ;use ACAD rotate command to rotate (command "_.rotate" new_obj "" (cadr rot_pnt) rot_angle) ) ;COPY_ROTATE ;(prompt "COPY_ROTATE ") ;;; ;;;Find the angle omega (defun c:omega (/ inv_a inv_b inv_c sum_inv_tan) (setq angle_a (angle_3p pnt_1 pnt_2 pnt_3) angle_b (angle_3p pnt_2 pnt_3 pnt_1) angle_c (angle_3p pnt_3 pnt_1 pnt_2) inv_a (/ 1. (tan angle_a)) inv_b (/ 1. (tan angle_b)) inv_c (/ 1. (tan angle_c)) sum_inv_tan (/ 1. (+ inv_a inv_b inv_c)) omega_r (atan sum_inv_tan) omega_d (rtd omega_r) ) ;(prin1 (rtos omega_d 2 8)) ) ;;;OMEGA ;(prompt "OMEGA ")(terpri) ;;; ;;; Find Brocard points(ccw) ;;; (defun c:find_brocard_1 () (command "_.rotate" line_ab "" pnt_a omega_d) (command "_.rotate" line_bc "" pnt_b omega_d) ;(copy_rotate line_ab pnt_a omega_d) ;(copy_rotate line_bc pnt_b omega_d) ;;;find intersection of these 2 lines pnt_br1 (setq pnt_b_1 (cdr (assoc 11 (entget line_ab))) pnt_c_1 (cdr (assoc 11 (entget line_bc))) pnt_br1 (inters pnt_a pnt_b_1 pnt_b pnt_c_1 nil) ) ;;;get distance from the apexes to this point (setq d_a_br (distance pnt_a pnt_br1) d_b_br (distance pnt_b pnt_br1) d_c_br (distance pnt_c pnt_br1) ) ;;;compute the ratios of these line lengths w.r.t. d_a_br ;;;These values will be used to set the speed ;;;arc_length is the actual distance traveled from A to BR_pnt (setq ratio_ab (/ d_b_br d_a_br) ratio_ac (/ d_c_br d_a_br) arc_length (/ d_a_br (cos omega_r)) ) ) ;;; ;;; ;;; Find Brocard points(cw) ;(prompt "c:find_brocard_1 ") ;;; (defun c:find_brocard_2 () (command "_.rotate" line_ab "" pnt_b (- omega_d)) (command "_.rotate" line_bc "" pnt_c (- omega_d)) ;(copy_rotate line_ab pnt_a omega_d) ;(copy_rotate line_bc pnt_b omega_d) ;;;find intersection of these 2 lines pnt_br2 (setq pnt_a_2 (cdr (assoc 10 (entget line_ab))) pnt_b_2 (cdr (assoc 10 (entget line_bc))) pnt_br2 (inters pnt_b pnt_a_2 pnt_c pnt_b_2 nil) ) ;;;get distance from the apexes to this point (setq d_a_br (distance pnt_a pnt_br2) d_b_br (distance pnt_b pnt_br2) d_c_br (distance pnt_c pnt_br2) ) ;;;compute the ratios of these line lengths w.r.t. d_a_br ;;;These values will be used to set the speed ;;;arc_length is the actual distance traveled from A to BR_pnt (setq ratio_ab (/ d_b_br d_a_br) ratio_ac (/ d_c_br d_a_br) arc_length (/ d_a_br (cos omega_r)) ) ) ;;; ;(prompt "c:find_brocard_2 ") ;;;COPY_ROTATE (defun copy_rotate (base_line rot_center rot_angle / line_list new_ent) ;Copy the entity data points, layer, color (setq line_list (entget base_line) new_ent (list (assoc 0 line_list) (assoc 8 line_list) (assoc 62 line_list) (assoc 10 line_list) (assoc 11 line_list) ) ) ;;;;;;Make a new entity (entmake new_ent) (setq new_obj (entlast)) ;;;;;;specify a center of rotation ;;;;;;use ACAD rotate command to rotate (command "_.rotate" new_obj "" rot_center rot_angle) ) ;COPY_ROTATE ;;; ;(prompt "COPY_ROTATE ") ;;; ;;; (defun c:brocard_demo1 () (setq line_ab_t nil line_bc_t nil line_ca_t nil ) (make_line_1 "0" 1 pnt_1 pnt_2) (setq line_ab (entlast)) (make_line_1 "0" 2 pnt_2 pnt_3) (setq line_bc (entlast)) (make_line_1 "0" 3 pnt_3 pnt_1) (setq line_ca (entlast)) (command "_.block" "line_ab" pnt_1 line_ab "") (command "_.block" "line_bc" pnt_2 line_bc "") (command "_.block" "line_ca" pnt_3 line_ca "") (alert "Pick the end of red line to rotate") (while (setq pnt_temp (cadr (grread))) (setq rot_deg (rtd (angle_3p pnt_1 pnt_2 pnt_temp))) (if (/= line_ab_t nil) (entdel line_ab_t) ) (if (/= line_bc_t nil) (entdel line_bc_t) ) (if (/= line_ca_t nil) (entdel line_ca_t) ) (command "_.insert" "line_ab" pnt_1 "" "" rot_deg) (setq line_ab_t (entlast)) (command "_.insert" "line_bc" pnt_2 "" "" rot_deg) (setq line_bc_t (entlast)) (command "_.insert" "line_ca" pnt_3 "" "" rot_deg) (setq line_ca_t (entlast)) ) ;;end of while loop (setq line_ab_t nil line_bc_t nil line_ca_t nil ) ) ;;; (prompt "c:brocard_demo1 ") ;;; ;;; ;;; (defun c:brocard_demo2 () (setq line_ab_t nil line_bc_t nil line_ca_t nil ) (make_line_1 "0" 1 pnt_1 pnt_2) (setq line_ab (entlast)) (make_line_1 "0" 2 pnt_2 pnt_3) (setq line_bc (entlast)) (make_line_1 "0" 3 pnt_3 pnt_1) (setq line_ca (entlast)) (command "_.block" "line_ab" pnt_1 line_ab "") (command "_.block" "line_bc" pnt_2 line_bc "") (command "_.block" "line_ca" pnt_3 line_ca "") (alert "Pick the end of red line to rotate") (while (setq pnt_temp (cadr (grread T))) (setq rot_deg (rtd (angle_3p pnt_1 pnt_2 pnt_temp))) (if (/= line_ab_t nil) (entdel line_ab_t) ) (if (/= line_bc_t nil) (entdel line_bc_t) ) (if (/= line_ca_t nil) (entdel line_ca_t) ) (command "_.insert" "line_ab" pnt_1 "" "" rot_deg) (setq line_ab_t (entlast)) (command "_.insert" "line_bc" pnt_2 "" "" rot_deg) (setq line_bc_t (entlast)) (command "_.insert" "line_ca" pnt_3 "" "" rot_deg) (setq line_ca_t (entlast)) ) ;;end of while loop (setq line_ab_t nil line_bc_t nil line_ca_t nil ) ) ;;; (prompt "c:brocard_demo2 ") ;;; ;;; (defun c:brocard_demo3 () (setq line_ab_t nil line_bc_t nil line_ca_t nil status_change nil ) (make_line_1 "0" 1 pnt_1 pnt_2) (setq line_ab (entlast)) (make_line_1 "0" 2 pnt_2 pnt_3) (setq line_bc (entlast)) (make_line_1 "0" 3 pnt_3 pnt_1) (setq line_ca (entlast)) (command "_.block" "line_ab" pnt_1 line_ab "") (command "_.block" "line_bc" pnt_2 line_bc "") (command "_.block" "line_ca" pnt_3 line_ca "") (alert "Pick the end of red line to rotate") (while (and (setq key (grread T)) (= (car key) 5)) (setq pnt_temp (cadr key)) ;(while (setq pnt_temp (cadr (grread T))) (setq rot_deg (rtd (angle_3p pnt_1 pnt_2 pnt_temp))) (if (/= line_ab_t nil) (entdel line_ab_t) ) (if (/= line_bc_t nil) (entdel line_bc_t) ) (if (/= line_ca_t nil) (entdel line_ca_t) ) (command "_.insert" "line_ab" pnt_1 "" "" rot_deg) (setq line_ab_t (entlast)) (command "_.insert" "line_bc" pnt_2 "" "" rot_deg) (setq line_bc_t (entlast)) (command "_.insert" "line_ca" pnt_3 "" "" rot_deg) (setq line_ca_t (entlast)) (if (= status_change T) (zoom_area_brocard) ) ;zoom for easy picking ) ;;end of while loop (setq line_ab_t nil line_bc_t nil line_ca_t nil ) ) ;;; (prompt "c:brocard_demo3 ") ;;; ;;;ZOOM_AREA ;;;zoom the transition area for detail search ;;; (defun ZOOM_AREA_brocard (/ x_a x_b x_c y_a y_b y_c lower_left upper_right) (setq x_a (car pnt_a) y_a (cadr pnt_a) x_b (car pnt_b) y_b (cadr pnt_b) x_c (car pnt_c) y_c (cadr pnt_c) min_x (min x_a x_b x_c) min_y (min y_a y_b y_c) max_x (max x_a x_b x_c) max_y (max y_a y_b y_c) lower_left (list min_x min_y) upper_right (list max_x max_y) ) (command "_.zoom" "_w" lower_left upper_right) (command "_.regen") ) ;ZOOM_AREA_brocard ;;; ;;;Test for n-dogs ;;; (defun c:ndogs () (setup_sysvar) (setup_npolygon) (if (= JPG_YES 1) (command "_.jpgout" (strcat "6dogs_" (itoa 0)) "") ) ;(setq new_list apex_list) ;;copy apex_list (pursuit_ndogs) (reset_sysvar) ) ;;;Ndogs (prompt "ndogs") ;;; ;;;PURSUIT for n-polygon case (defun pursuit_ndogs () (setvar "CECOLOR" "8") (while (<= total_path (- arc_len tol_val)) ;(while (> d_ref delta) ;;;old criteria (setq n_apex 0 pnt_a_old (nth 0 new_list) ncol 1 ) (repeat n_poly (setq pnt_start (nth n_apex new_list) pnt_dest (nth (1+ n_apex) new_list) pnt_s_old pnt_start pnt_s_new (pld pnt_start pnt_dest delta) color_id ncol ) (slow_line speed "0" color_id pnt_start pnt_s_new) (setq new_list (repl_nth new_list n_poly n_apex pnt_s_new)) (setq n_apex (1+ n_apex) ncol (1+ ncol) ) ) (setq pnt_a_new (nth 0 new_list) pnt_b_new (nth 1 new_list) new_list (repl_nth new_list n_poly n_apex pnt_a_new) d_ref (distance pnt_a_new pnt_b_new) ) ;(princ new_list)(terpri) (make_polyline "layer8" 8 "Continuous" new_list 0) (if (and (= (rem ncount 10) 0) (= JPG_YES 1)) (command "_.jpgout" (strcat "6dogs_" (itoa ncount)) "") ) ;;;end of if loop (setq ncount (1+ ncount)) (setq total_path (* ncount delta)) ;;;total distance traveled ;(princ "total_path =")(princ total_path)(terpri) ) ;;;end of while loop (setvar "CECOLOR" "BYLAYER") (princ "total_path =") (princ total_path) (terpri) ) ;;;PURSUIT_ndogs (prompt "PURSUIT_ndogs") ;;; ;;;SETUP for N-polygon case ;;; (defun setup_npolygon () (setq rad 1.0) (setq N_poly (getint "\nNumber of sides in polygon")) (if (= n_poly nil) (setq n_poly 4) ) (setq theta (/ pi n_poly) sine (sin theta) cosine (cos theta) height (* rad cosine) half_base (* rad sine) arc_len (/ rad sine) ;;;S = rad/(cos (pi/2 -theta) )=rad/sin(theta) pnt_1 (list (- half_base) (- height)) pnt_2 (list half_base (- height)) side_len (* 2 half_base) ncount 0 tol_val 1.e-6 ) (command "_.polygon" N_poly "_Edge" pnt_1 pnt_2) (setq apex_list (pl_vertices (entlast))) ;;list of apex data ;(setq apex_list (append apex_list (list (nth 0 apex_list))) ) (mark_id pnt_1 "A" 3 0.1) (mark_id pnt_2 "B" 1 0.1) ;(make_polyline "0" 5 "_Continuous" apex_list 1) ;;closed polyline (command "_.zoom" "_EXTENT") (setq apex_list (append apex_list (list (nth 0 apex_list)))) (setq new_list apex_list) ;;copy apex_list (princ new_list) (terpri) (setq rate (getreal "\nSpecify dog's stride as % of side length AB:(def=1%)" ) ) (if (= rate nil) (setq rate 1.) ) (setq delta (* side_len (/ rate 100.)) speed (getint "\nSpecify display speed (1-100) 1:veryfast 100:very slow (def = 50)" ) ) (if (= speed nil) (setq speed 50) ) (setq d_ref side_len total_path 0. n_repeat (+ 2 (fix (/ 100 rate))) ) ) ;;; (prompt "SETUP_NPLOYGON") ;;; ;;;Replace the n-th element in the list by the user given element ;;; (defun repl_nth (list_in list_size n_th new_elem / new_list npos) (setq new_list nil npos 0 ) (repeat (1+ list_size) (if (= npos n_th) (setq elem new_elem) (setq elem (nth npos list_in)) ) ;;;end_if loop (setq npos (1+ npos)) (setq new_list (append new_list (list elem))) ) ;;;end of repeat loop ) ;;;repl_nth ;;; ;;;Equiangular curve parameters ;;; (defun c:equi_angular() (setup_equi_angular) (alert "\nCopy , move and rotate two colored sets") (copy_move_rot) (alert "\nScale two sets to see if they match the curve.") (scale_sets) );;; ;;; (defun setup_equi_angular() (setq qtr_pi (/ pi 4.) th_d (* 3 qtr_pi) th_c qtr_pi th_a (- th_d) th_b (- th_c) k_a (/ 1. (exp th_a)) k_b (/ 1. (exp th_b)) k_c (/ 1. (exp th_c)) k_d (/ 1. (exp th_d)) pnt_org '(0 0) pnt_org_2 '(-0.5 0) pnt_cr11 '(-0.001 0.1) pnt_cr12 '(-0.1 0.001) pnt_cr21 '(0.1 0.1) pnt_cr22 '(0.001 0.001) pnt_cr31 '(0.3 0) pnt_cr32 '(0 -0.5) pnt_cr41 '(-0.48 -0.0001) pnt_cr42 '(-0.49999 -0.05) pnt_cr51 '(-0.45 -0.0001) pnt_cr52 '(-0.49999 -0.1) ss1 (ssadd) ss2 (ssadd) ss3 (ssadd) ss1a (ssadd) ss2a (ssadd) ) (make_pt "0" 0 pnt_org_2) (alert "\nChange colors of the first and second sets") ;;change the color of the first and second sets (setq ss1 (ssget "_C" pnt_cr11 pnt_cr12)) (command "_.chprop" ss1 "" "c" "yellow" "") (setq ss2 (ssget "_C" pnt_cr21 pnt_cr22)) (command "_.chprop" ss2 "" "_C" "green" "") );;; ;;; ;;; (defun copy_move_rot() (alert "\nCopy , move and rotate two colored sets") ;;copy.move and rotate the first set(yellow) (command "_.copy" ss1 "" pnt_org pnt_org) (command "_.move" ss1 "" pnt_org pnt_org_2) (command "_.rotate" ss1 "" pnt_org_2 -180.) (setq ss1a (ssget "C" pnt_cr41 pnt_cr42)) (command "_.copy" ss1a "" pnt_org_2 pnt_org_2) ;;copy,move and rotate the second set(cyan) (command "_.copy" ss2 "" pnt_org pnt_org) (command "_.move" ss2 "" pnt_org pnt_org_2) (command "_.rotate" ss2 "" pnt_org_2 -90.) (setq ss2a (ssget "C" pnt_cr51 pnt_cr52)) (command "_.copy" ss2a "" pnt_org_2 pnt_org_2) ;;copy and move the third set(red) (setq ss3 (ssget "_C" pnt_cr31 pnt_cr32)) (command "_.copy" ss3 "" pnt_org pnt_org) (command "_.move" ss3 "" pnt_org pnt_org_2) );;; ;;; ;;; (defun scale_sets() (command "_.scale" ss1a ss2a "" pnt_org_2 4.8) ) ;;; ;;;DRAW equiangular spiral corresponding to square chase case. ;;; ;;; (defun c:draw_equiangular_spiral() (setq theta_0 (* 0.75 pi) sqrt_2 (sqrt 2.) inv_sqrt_2 (/ 1. sqrt_2) theta_s 0. theta_e (* 2. pi) del_theta (/ theta_e 100.) nth_turn 1 nstep 0 pnt_old (list (- inv_sqrt_2) (- inv_sqrt_2)) col_id 1 pnt_org '(0 0) scale_factor 0.075 cur_scale 1.0 ) (make_line_1 "0" 8 '(0 -0.7) '(0 0.1)) (make_line_1 "0" 8 '(-0.1 0) '(0.1 0)) (command "_.zoom" "_E") (while (= (Yes_or_No "Go to next step ?") "_Y") (setq nstep 0 ) (repeat 100 (setq theta (+ theta_s (* del_theta nstep)) m_theta (- theta) f_val (exp m_theta) theta2 (- theta theta_0) x_val (* f_val (cos theta2)) y_val (* f_val (sin theta2)) pnt_new (list x_val y_val) ) (make_line_1 "0" col_id pnt_old pnt_new) (setq pnt_old pnt_new nstep (1+ nstep) ) );;;inner loop (setq cur_scale (* cur_scale scale_factor)) (if (= col_id 1) (command "_.zoom" "_E") (command "_.zoom" "_C" pnt_org cur_scale) ) (setq theta_s (+ theta_s theta_e) col_id (1+ col_id)) (make_jpg) (command "_.delay" 500) );;while loop );;; ;;; ;;;How the brocard points are defined. ;;; ;;;BROCARD_DEF (prompt "brocard_def") ;;; (defun C:brocard_def() (setup_brocard_def) (command "_.zoom" "_E") ;;copy line segment (copy_line_seg) ;;rotate line segment inward by 10 degrees (alert "\nRotate line segments inward by a given angle") (setq rot_ang 0.5) (while (> dist_bc min_dist) (rot_lineseg_in rot_ang) ;;compute 3 intersecting points & draw a triangle (draw_temp_triangle) (command "_.delay" 100) );;while loop ;(alert "\nRotate line segmnets outward by the same given angle") ; (rot_lineseg_out rot_ang) (reset_sysvar) );; ;;;BROCARD_DEF ;;; (prompt "brocard_defa") ;;;BROCARD_DEFA ;;; (defun C:brocard_defa() (setup_brocard_def) (command "_.zoom" "_W" lower_left upper_right) ;;copy line segment (copy_line_seg) ;;rotate line segment inward by 10 degrees (alert "\nRotate line segments inward by a given angle") (setq rot_ang 1.0) (setvar "CECOLOR" "8") (repeat 180 (rot_lineseg_in rot_ang) ;;compute 3 intersecting points & draw a triangle (draw_temp_triangle) (make_jpg) (command "_.delay" 100) );;while loop (command "_.draworder" line_ab line_bc line_ca text_a text_b text_c "" "_F") ;(alert "\nRotate line segmnets outward by the same given angle") ; (rot_lineseg_out rot_ang) (reset_sysvar) );; ;;;BROCARD_DEFA ;;;BROCARD_DEFB (prompt "brocard_defb") ;;; (defun C:brocard_defb() (setup_brocard_def) (command "_.zoom" "_E") ;;copy line segment (copy_line_seg) ;;rotate line segment inward by 10 degrees (alert "\nRotate line segments inward by a given angle") (setq rot_ang 1.0) (while (> dist_bc min_criteria) (while (> dist_bc half_bc) (rot_lineseg_in rot_ang) ;;compute 3 intersecting points & draw a triangle (draw_temp_triangle) (command "_.delay" 100) );;while loop (setq half_bc (* 0.5 dist_bc) rot_ang (* 0.5 rot_ang) ) );;outer while loop (command "_.draworder" line_ab line_bc line_ca text_a text_b text_c "" "_F") (reset_sysvar) );; ;;;BROCARD_DEFB ;;; ;;;SETUP_BROCARD_DEF (prompt "setup_brocard_def") ;;; (defun setup_brocard_def() (setup_sysvar) (command "_.zoom" "_C" '(0 0) 1.0) (setq pnt_a (getpoint "\nLocate point A of triangle ABC")) (if (= pnt_a nil) (setq pnt_a '(0.03125 0.39125 0.0)) ) (textdisplay "A" (shift_pnt pnt_a '(0.02 0.02)) 0.1 0.) (setq text_a (entlast)) (setq pnt_b (getpoint pnt_a "\nLocate point B of triangle ABC")) (if (= pnt_b nil) (setq pnt_b '(-0.44625 -0.02875 0.0)) ) (textdisplay "B" (shift_pnt pnt_b '(-0.1 0.)) 0.1 0.) (setq text_b (entlast)) (make_line_1 "0" 0 pnt_a pnt_b) (setq line_ab (entlast)) (setq pnt_c (getpoint pnt_b "\nLocate point C of triangle ABC")) (if (= pnt_c nil) (setq pnt_c '(0.28125 -0.02875 0.0)) ) (textdisplay "C" pnt_c 0.1 0.) (setq text_c (entlast)) (make_line_1 "0" 0 pnt_b pnt_c) (setq line_bc (entlast)) (make_line_1 "0" 0 pnt_c pnt_a) (setq line_ca (entlast)) (setq dist_ab (distance pnt_a pnt_b) dist_bc (distance pnt_b pnt_c) dist_ca (distance pnt_c pnt_a) half_bc (* 0.5 dist_bc) len_max (max dist_ab dist_bc dist_ca) min_dist (* len_max 0.05) min_criteria (* 0.0001 len_max) mlen_max (- len_max) ) (setq lower_left (shift_pnt pnt_b (list mlen_max mlen_max) ) upper_right (shift_pnt pnt_a (list len_max len_max) ) ) ) ;;;SETUP_BROCARD_DEF ;;; ;;;copy line segment for rotation ;;; (prompt "copy_line_seg") ;;;COPY_LINE_SEG ;;; (defun copy_line_seg() (command "_.copy" line_ab "" pnt_a pnt_a "") (setq line_ab_copy (entlast)) (command "_.copy" line_bc "" pnt_b pnt_b "") (setq line_bc_copy (entlast)) (command "_.copy" line_ca "" pnt_c pnt_c "") (setq line_ca_copy (entlast)) ) ;;;COPY_LINE_SEG ;;; ;;;Rotate 3 line segments inward (counter clockwise) ;;;ROT_LINESEG_IN (prompt "rot_lineseg_in") ;;; (defun rot_lineseg_in(rot_ang) (command "_.rotate" line_ab_copy "" pnt_a rot_ang) (command "_.rotate" line_bc_copy "" pnt_b rot_ang) (command "_.rotate" line_ca_copy "" pnt_c rot_ang) ) ;;;ROT_LINESEG_IN ;;; ;;; ;;;Rotate 3 line segments outward ( clockwise) ;;;ROT_LINESEG_IN (prompt "rot_lineseg_out") ;;; (defun rot_lineseg_out(rot_ang) ;(command "_.copy" line_ab "" pnt_a pnt_a "") ;(setq line_ab_copy2 (entlast)) ;(command "_.copy" line_bc "" pnt_b pnt_b "") ;(setq line_bc_copy2 (entlast)) ;(command "_.copy" line_ca "" pnt_c pnt_c "") ;(setq line_ca_copy2 (entlast)) ;(command "_.rotate" line_ab_copy2 "" pnt_a (- rot_ang)) ;(command "_.rotate" line_bc_copy2 "" pnt_b (- rot_ang)) ;(command "_.rotate" line_ca_copy2 "" pnt_c (- rot_ang)) (command "_.rotate" line_ab_copy "" pnt_a (- rot_ang)) (command "_.rotate" line_bc_copy "" pnt_b (- rot_ang)) (command "_.rotate" line_ca_copy "" pnt_c (- rot_ang)) ) ;;;ROT_LINESEG_out (prompt "draw_temp_triangle") ;;; ;;;DRAW_TEMP_TRIANGLE ;;;compute the 3 intersecting points and draw a triangle ;;; (defun draw_temp_triangle() ;;compute the other ends of 3 line segments (setq pnt_ab_b (cdr (assoc 11 (entget line_ab_copy))) pnt_bc_c (cdr (assoc 11 (entget line_bc_copy))) pnt_ca_a (cdr (assoc 11 (entget line_ca_copy))) ) ;;compute the intersecting points (setq pnt_bc (inters pnt_a pnt_ab_b pnt_b pnt_bc_c nil) pnt_ca (inters pnt_b pnt_bc_c pnt_c pnt_ca_a nil) pnt_ab (inters pnt_c pnt_ca_a pnt_a pnt_ab_b nil) ) (make_line_1 "0" 1 pnt_bc pnt_ca) (make_line_1 "0" 3 pnt_ca pnt_ab) (make_line_1 "0" 5 pnt_ab pnt_bc) ;(command "_.pline" pnt_bc pnt_ca pnt_ab "cl") (setq dist_bc (distance pnt_bc pnt_ca)) ) ;;;DRAW_TEMP_TRIANGLE