дʱҪõ󽻵ĺAutolispֻһǳ򵥵ֱ󽻺INTERSҲһЩһĳƷ󽻺VLISPչXD_APIõARX⡣дһlspͨԸǿĸ󽻺
ý첻ϰ࣬߰˸СʱдһԽԲ,Բ,߶θ󽻵
пܵĻǳһ£ԲߣSPLINEȣܹautolispдʵĽĸӺ
£Ҳԣ


;______________________________________________________________________
;_Բ,Բ,߶θ󽻵__LSP___BY__WKAI__CAD̳____________
;_2003.12.11.15.46_____________________________________________________
;______________________________________________________________________

;_ó__󵽵Ľ㴦һ0,0ֱ߶____________________
(defun c:tt(/ e1 e2 pp ff)
  (princ "\nѡһ:")
  (while (not e1) (setq e1 (car (entsel ))))
  (princ "\nѡڶ:")
  (while (not e2) (setq e2 (car (entsel ))))
  (setq ff (getint "\nڼ岻(0 ,1 һŲ,2 Ų,<3> ȫ):"))
  (if (not ff) (setq ff 3))
(print (setq pp (getint_of_ents e1 e2 ff)))
  (foreach n pp
    (progn (princ "\n") (princ n) (command "line" '(0 0) n ""))
    ) 
  )
;_ж,ѡӦ󽻵_______________________________________
(defun getint_of_ents (en_1 en_2 lim / intersections)
  (setq e1_tp (cdr (assoc 0 (entget en_1))))
  (setq e2_tp (cdr (assoc 0 (entget en_2))))
  (cond
    ((and (= "CIRCLE" e1_tp) (= "CIRCLE" e2_tp))
     (setq intersections (cic en_1 en_2 lim))
     )
    ((and (= "ARC" e1_tp) (= "ARC" e2_tp))
     (setq intersections (aia en_1 en_2 lim))
     )
    ((and (= "LINE" e1_tp) (= "LINE" e2_tp))
     (setq intersections (lil en_1 en_2 lim))
     )

    ((and (= "CIRCLE" e1_tp) (= "ARC" e2_tp))
     (setq intersections (cia en_1 en_2 lim))
     )
    ((and (= "CIRCLE" e1_tp) (= "LINE" e2_tp))
     (setq intersections (cil en_1 en_2 lim))
     )
    ((and (= "ARC" e1_tp) (= "LINE" e2_tp))
     (setq intersections (ail en_1 en_2 lim))
     )

    ((and (= "ARC" e1_tp) (= "CIRCLE" e2_tp))
     (setq intersections (cia en_2 en_1 (change_order lim)))
     )
    ((and (= "LINE" e1_tp) (= "CIRCLE" e2_tp))
     (setq intersections (cil en_2 en_1 (change_order lim)))
     )
    ((and (= "LINE" e1_tp) (= "ARC" e2_tp))
     (setq intersections (ail en_2 en_1 (change_order lim)))
     )
    (T (princ "\nѡԲԲ߶Σ"))
    )
  intersections
  )
;_תӳ־_________________________________________________________
(defun change_order(num)
  (cond
    ((= num 1)(setq num 2))
    ((= num 2)(setq num 1))
    )
  num
  )
;______________________________________________________________________
;______________________________________________________________________
;_________________󽻵Ӧú____BY__WKAI__CAD̳__________
;___________________2003.12.11.14.33___________________________________
;____limited__󽻵ʱǷ_________________________________
;____0 ,1 һŲ,2 Ų,3 ȫ___________________

;_ԲԲ___________________________________________________________
(defun cic (c1 c2 limited / c1_cn c2_cn c1_rd c2_rd ins)
  (setq c1_cn (cdr (assoc 10 (entget c1))))
  (setq c2_cn (cdr (assoc 10 (entget c2))))
  (setq c1_rd (cdr (assoc 40 (entget c1))))
  (setq c2_rd (cdr (assoc 40 (entget c2))))
  (setq ins (c_int_c c1_cn c1_rd c2_cn c2_rd))
  ins
  )
;_ԲԲ_________________________________________________________
(defun cia (c1 c2 limited / ins ins_tmp)
  (setq c1_cn (cdr (assoc 10 (entget c1))))
  (setq c2_cn (cdr (assoc 10 (entget c2))))
  (setq c1_rd (cdr (assoc 40 (entget c1))))
  (setq c2_rd (cdr (assoc 40 (entget c2))))
  (setq c2_an1 (cdr (assoc 50 (entget c2))))
  (setq c2_an2 (cdr (assoc 51 (entget c2))))
  (setq ins (c_int_c c1_cn c1_rd c2_cn c2_rd))
  (if (or (= limited 2) (= limited 3))
    (progn
      (foreach n ins
	(if (p_on_arc n c2_cn c2_an1 c2_an2)
	  (if ins_tmp
	    (setq ins_tmp (append ins_tmp (list n)))
	    (setq ins_tmp (list n))
	    )
	  )
	)
      (setq ins ins_tmp)
      )
    )
  ins
  )
;_ԲԲ________________________________________________________
(defun aia (c1 c2 limited / ins ins_tmp)
  (setq c1_cn (cdr (assoc 10 (entget c1))))
  (setq c2_cn (cdr (assoc 10 (entget c2))))
  (setq c1_rd (cdr (assoc 40 (entget c1))))
  (setq c2_rd (cdr (assoc 40 (entget c2))))
  (setq c1_an1 (cdr (assoc 50 (entget c1))))
  (setq c1_an2 (cdr (assoc 51 (entget c1))))
  (setq c2_an1 (cdr (assoc 50 (entget c2))))
  (setq c2_an2 (cdr (assoc 51 (entget c2))))
  (setq ins (c_int_c c1_cn c1_rd c2_cn c2_rd))
  (if (or (= limited 1) (= limited 3))
    (progn
      (foreach n ins
	(if (p_on_arc n c1_cn c1_an1 c1_an2)
	  (if ins_tmp
	    (setq ins_tmp (append ins_tmp (list n)))
	    (setq ins_tmp (list n))
	    )
	  )
	)
      (setq ins ins_tmp)
      )
    )
  (setq  ins_tmp nil)
  (if (or (= limited 2) (= limited 3))
    (progn
      (foreach n ins
	(if (p_on_arc n c2_cn c2_an1 c2_an2)
	  (if ins_tmp
	    (setq ins_tmp (append ins_tmp (list n)))
	    (setq ins_tmp (list n))
	    )
	  )
	)
      (setq ins ins_tmp)
      )
    )
  ins
  )
;_Բֱ߽______________________________________________________
(defun cil (c l limited /  end1 end2 cen rad ins ins_tmp )
  (setq end1 (cdr (assoc 10 (entget l))))
  (setq end2 (cdr (assoc 11 (entget l))))
  (setq cen (cdr (assoc 10 (entget c))))
  (setq rad (cdr (assoc 40 (entget c))))
  (setq ins (L_INT_C end1 end2 cen rad))
  (if (or (= limited 2) (= limited 3))
    (progn
      (foreach n ins
	(if (p_on_line n end1 end2)
	  (if ins_tmp
	    (setq ins_tmp (append ins_tmp (list n)))
	    (setq ins_tmp (list n))
	    )
	  )
	)
      (setq ins ins_tmp)
      )
    )
  ins
  )
;_Բֱ߽______________________________________________________
(defun ail (c l limited / end1 end2 cen rad ang1 ang2 ins ins_tmp)
  (setq end1 (cdr (assoc 10 (entget l))))
  (setq end2 (cdr (assoc 11 (entget l))))
  (setq cen (cdr (assoc 10 (entget c))))
  (setq rad (cdr (assoc 40 (entget c))))
  (setq ang1 (cdr (assoc 50 (entget c))))
  (setq ang2 (cdr (assoc 51 (entget c))))
  (setq ins (L_INT_C end1 end2 cen rad))
  (if (or (= limited 1) (= limited 3))
    (progn
      (foreach n ins
	(if (p_on_arc n cen ang1 ang2)
	  (if ins_tmp
	    (setq ins_tmp (append ins_tmp (list n)))
	    (setq ins_tmp (list n))
	    )
	  )
	)
      (setq ins ins_tmp)
      )
    )
  (setq ins_tmp nil)
  (if (or (= limited 2) (= limited 3))
    (progn
      (foreach n ins
	(if (p_on_line n end1 end2)
	  (if ins_tmp
	    (setq ins_tmp (append ins_tmp (list n)))
	    (setq ins_tmp (list n))
	    )
	  )
	)
      (setq ins ins_tmp)
      )
    )
  ins
  )
;_ֱߡֱ߽______________________________________________________
(defun lil (l1 l2 limited / pt ins ins_tmp l1_en1 l1_en2 l2_en1 l2_en2)
  (setq l1_en1 (cdr (assoc 10 (entget l1))))
  (setq l1_en2 (cdr (assoc 11 (entget l1))))
  (setq l2_en1 (cdr (assoc 10 (entget l2))))
  (setq l2_en2 (cdr (assoc 11 (entget l2))))
  (setq ins (list (inters l1_en1 l1_en2 l2_en1 l2_en2)))
  (if (or (= limited 1) (= limited 3))
    (progn
      (foreach n ins
	(if (p_on_line n l1_en1 l1_en2)
	  (if ins_tmp
	    (setq ins_tmp (append ins_tmp (list n)))
	    (setq ins_tmp (list n))
	    )
	  )
	)
      (setq ins ins_tmp)
      )
    )
  (setq ins_tmp nil)
  (if (or (= limited 1) (= limited 3))
    (progn
      (foreach n ins
	(if (p_on_line n l1_en1 l1_en2)
	  (if ins_tmp
	    (setq ins_tmp (append ins_tmp (list n)))
	    (setq ins_tmp (list n))
	    )
	  )
	)
      (setq ins ins_tmp)
      )
    )
  ins
  )
;______________________________________________________________________
;______________________________________________________________________
;_________________󽻵ĺ____BY__WKAI__CAD̳__________
;___________________2003.12.11.14.33___________________________________
;______________________________________________________________________
;______________________________________________________________
(setq min_num 0.0000001)
;___________________ԲԲ㺯,ֵԲ1,뾶1,Բ2,뾶2.ֵ
(defun c_int_c (c1_cen	 c1_rad	  c2_cen   c2_rad   /	     c1
		c2	 c1_end	  c2_end   c1_rad   c2_rad   ints
		c1c2_dis
		)
  (setq c1c2_dis (distance c1_cen c2_cen))
  (cond
    ((equal c1c2_dis (+ c1_rad c2_rad) min_num)
     (setq ints (list (polar c1_cen (angle c1_cen c2_cen) c1_rad)))
     )
    ((equal c1c2_dis (abs (- c1_rad c2_rad)) min_num)
     (if (minusp (- c1_rad c2_rad))
       (setq ints (list (polar c2_cen (angle c2_cen c1_cen) c2_rad)))
       (setq ints (list (polar c1_cen (angle c1_cen c2_cen) c1_rad)))
       )
     )
    ((and (> c1c2_dis (abs (- c1_rad c2_rad)))
	  (< c1c2_dis (+ c1_rad c2_rad))
	  )
     (progn
       (princ "\nffff")
       (setq dd	(/ (- (+ (* c1c2_dis c1c2_dis) (* c1_rad c1_rad))
		      (* c2_rad c2_rad)
		      )
		   (* 2 c1c2_dis)
		   )
	     )
       (setq ee (sqrt (- (* c1_rad c1_rad) (* dd dd))))
       (setq
	 ints (list (polar (polar c1_cen (angle c1_cen c2_cen) dd)
			   (+ (angle c1_cen c2_cen) (/ pi 2))
			   ee
			   )
		    )
	 )
       (setq ints
	      (append
		ints
		(list (polar (polar c1_cen (angle c1_cen c2_cen) dd)
			     (- (angle c1_cen c2_cen) (/ pi 2))
			     ee
			     )
		      )
		)
	     )

       )
     )
    )
  ints
  )
 ;___________________ֱԲ㺯,ֱֵ߶˵1,˵2,Բ,뾶.ֵ
(defun L_INT_C (l_end1 l_end2 c_cen c_rad / c l	pedal dist_cen_l int
		int1 int2 ints)
  (setq pedal (pedal_to_line c_cen l_end1 l_end2))
  (setq dist_cen_l (distance pedal c_cen))
  (cond
    ((equal c_rad dist_cen_l min_num) (setq ints (list pedal)))
    ((> c_rad dist_cen_l)
     (progn
       (setq int1
	      (polar pedal
		     (angle l_end1 l_end2)
		     (sqrt (- (* c_rad c_rad) (* dist_cen_l dist_cen_l)))
		     )
	     )
       (setq int2
	      (polar pedal
		     (+ pi (angle l_end1 l_end2))
		     (sqrt (- (* c_rad c_rad) (* dist_cen_l dist_cen_l)))
		     )
	     )
       (setq ints (list int1 int2))
       )
     )
    )
  ints
  )
;______________________________________________________________________
;______________________________________________________________________
;_________________Ժ____BY__WKAI__CAD̳____________
;___________________2003.12.11.14.33___________________________________
;______________________________________________________________________
 ;___________________㵽ֱߵĴĺ,ֵԵ,ֱ߶˵1,˵2.ֵ
(defun pedal_to_line (pt pt1 pt2)
  (inters
    pt
    (polar pt (+ (/ pi 2) (angle pt1 pt2)) 1000)
    pt1
    pt2
    nil
    )
  )
 ;___________________ԵǷ߶,ֵԵ,߶ζ˵1,˵2.ֵTNIL
(defun p_on_line (pt pt1 pt2)
  (equal (+ (distance pt pt1) (distance pt pt2))
	 (distance pt1 pt2)
	 min_num
	 )
  )
 ;___________________ԵǷԲ,ֵԵ,Բ,ʼǶ,ֹǶ.ֵTNIL
(defun p_on_arc	(pt cn an1 an2)
  (or (and (<= (angle cn pt) an1)
	   (>= (angle cn pt) an2)
	   )
      (and (>= (angle cn pt) an1)
	   (<= (angle cn pt) an2)
	   )
      )
  )
 ;_________________________________________________________________________________________
 ;_________________________________________________________________________________________
 ;_________________________________________________________________________________________
 ;_________________________________________________________________________________________
  
