Author Topic: -={ Challenge }=- 3-Point Circle Tangent to Two Circles, with given Point.  (Read 19699 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
This was a question posed at the AUGI forums, the user wanted to automate the process of creating a circle tangent to two other circles, given a point on the circumference.

I posted a solution involving a command call to the 'tan' snap, but was disappointed that I could not construct a geometric solution and so thought it would be a good challenge to post here.

The Challenge:

Given circles A & B and a point P, construct a circle C tangent to both A & B, such that P lies on the circumference:



I believe there are four possible solutions...


Ketxu

  • Newt
  • Posts: 109
Re: -={ Challenge }=- 3-Point Circle Tangent to Two Circles, with given Point.
« Reply #1 on: September 25, 2011, 12:48:36 PM »
I'm not good in geometric, can this link be useful to you :(

http://whistleralley.com/tangents/tangents.htm

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: -={ Challenge }=- 3-Point Circle Tangent to Two Circles, with given Point.
« Reply #2 on: September 25, 2011, 02:47:19 PM »
Well, the general equation for the solution is the intersection of three circles:



The intersection is the solution(s) of the following three simultaneous equations, solved for x, y, r:


(x - Ax)2 + (y - Ay)2 = (r + Ar)2
(x - Bx)2 + (y - By)2 = (r + Br)2
(x - Px)2 + (y - Py)2 = r2


Where:

Centre of circle A is (Ax, Ay), with radius Ar
Centre of circle B is (Bx, By), with radius Br
Point P has coordinates (Px, Py)

Resultant Circle has centre (x,y) and radius r.

It just remains to rearrange the equations into a closed expression...

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: -={ Challenge }=- 3-Point Circle Tangent to Two Circles, with given Point.
« Reply #3 on: September 26, 2011, 05:19:25 AM »
I've studied posted link and find it vary useful for those that wants to work with constructions... Based on explanations of constructions, I did what was explained - draw circles that tangents three other circles... I know this topic is about tan+tan+pt, but precise drawings may also satisfy someones needs...

M.R.

Lee, for constructing your example you must firstly calculate radius of solution circle, and when obtained radius routine may find intersections of 3 given circles, but unfortunately that's not construction you search for...

Regards, Marko Ribar, d.i.a. (architect)
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: -={ Challenge }=- 3-Point Circle Tangent to Two Circles, with given Point.
« Reply #4 on: September 26, 2011, 06:45:33 AM »
Maybe this can be of some help... DWG shows all relations between 2 circles (dilatation points, radical axis, poles on circles from radical axis). I've drawn yellow circles that passes through 2 points on direction cent1 - cent2 and that have various centers along radical axis...
As an example for tangent circles I used 2 dilatation lines (2 tangent circles solutions for each line - 4 circles (2 green) (2 cyan))...

Regards, M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

highflyingbird

  • Bull Frog
  • Posts: 415
  • Later equals never.
Re: -={ Challenge }=- 3-Point Circle Tangent to Two Circles, with given Point.
« Reply #5 on: September 26, 2011, 07:03:52 AM »
here is my code.
Actually , a few months ago, I wanted to find a lisp to replace the command "circle  3P".so I made it.I finished most of cases. I will show my stuff  a few days later.

Code: [Select]
;;; for test
(defun c:PCC(/ cir1 cir2 pnt dxf1 dxf2 rad1 rad2 cen1 cen2 ret)
  (setq cir1 (car (entsel "\nPick a circle:")))
  (setq cir2 (car (entsel "\nPick another circle:")))
  (setq pnt  (getpoint "\nPick a point:"))
  (if (not (and cir1 cir2 pnt))
    (exit)
  )
  (setq dxf1 (entget cir1))
  (setq dxf2 (entget cir2))
  (setq rad1 (cdr (assoc 40 dxf1)))
  (setq rad2 (cdr (assoc 40 dxf2)))
  (setq cen1 (cdr (assoc 10 dxf1)))
  (setq cen2 (cdr (assoc 10 dxf2)))


  (setq ret (PCC_Circle pnt rad1 cen1 rad2 cen2))
  (makePoint pnt)
  (if (car ret)
    (progn
      (makecircle (caadr ret) (cadadr ret))
      (makecircle (caar ret) (cadar ret))
    )
  )
)

;;;直线的方程
(defun Coefficient_Equation (p1 p2)
  (list (- (cadr p1) (cadr p2))
(- (car  p2) (car  p1))
(- (* (car p1) (cadr p2))
   (* (cadr p1) (car p2))
)
  )
)

;;;位似中心
(defun Homothetic_center (rad1 cen1 rad2 cen2 / r1 c1 r2 c2 l d)
  (if (< rad1 rad2)
    (setq r1 rad1
  c1 cen1
  r2 rad2
  c2 cen2
    )
    (setq r1 rad2
  c1 cen2
  r2 rad1
  c2 cen1
    )
  )
  (setq l (distance c1 c2))
  (setq d (- r2 r1))
  (cond
    ( (or (< l d) (= l 0.0)) nil)
    ( (equal l d 1e-8) (list nil (polar c1 (angle c2 c1) r1)))
    ( (equal r1 r2 1e-14)
      (if (>= l (+ r1 r2))
        (list nil (mtp c1 c2))
      )
    )
    (t
      (if (< l (+ r1 r2))
(list (polar c1 (angle c2 c1) (/ (* r1 l) (- r2 r1))) nil)
(list (polar c1 (angle c2 c1) (/ (* r1 l) (- r2 r1)))
      (polar c1 (angle c1 c2) (/ (* r1 l) (+ r2 r1)))
)
      )
    )
  )
)

;;;点对圆的反演
(defun Point_Inversion (rad cen p)
  (setq d (distance p cen))
  (if (/= d 0)
    (polar cen (angle cen p) (/ (* rad rad) d))
  )
)

;;;线段对圆的反演
(defun Line_Inversion (Rad Cen P1 P2 /)
  (if (equal (det cen p1 p2) 0.0 1e-8)
    (list p1 p2)
    (PPP_Circle cen (Point_Inversion rad cen p1) (Point_Inversion rad cen p2))
  )
)

;;;圆对圆的反演
(defun Circle_Inversion (Rad Cen R C / an p1 p2)
  (setq an (angle C Cen))
  (setq p1 (polar C an R))
  (setq p2 (polar C an (- R)))
 
  (setq p1 (Point_Inversion Rad Cen P1))
  (setq p2 (Point_Inversion Rad Cen P2))
  (cond
    ( (and p1 p2)
      (list (mtp p1 p2) (/ (distance p1 p2) 2))
    )
    ( p1
      (list p1 (mapcar '+ p1 (rot90 (mapcar '- p1 Cen))))
    )
    ( p2
      (list p2 (mapcar '+ P2 (rot90 (mapcar '- P2 Cen))))
    )
  )
)

;;;圆外的一点对圆形的切点OK
(defun Tangent_Point (rad cen pt / d l a b p q r)
  (setq d (distance cen pt))
  (if (> d rad)
    (setq l (sqrt (- (* d d) (* rad rad)))
  a (atan l rad)
  b (angle cen pt)
  p (polar cen (+ b a) rad)
  q (polar cen (- b a) rad)
  r (list p q)
    )
    (if (= d rad)
      pt
    )
  )
)

;;; 三点圆函数OK
(defun PPP_Circle(P0 P1 P2 / X0 Y0 X1 Y1 X2 Y2 DX1 DY1 DX2 DY2 D 2D C1 C2 CE)
  (setq X0  (car  P0)
Y0  (cadr P0)
X1  (car  P1)
Y1  (cadr P1)
X2  (car  P2)
Y2  (cadr P2)
DX1 (- X1 X0)
DY1 (- Y1 Y0)
DX2 (- X2 X0)
DY2 (- Y2 Y0)
  )
  (setq D (- (* DX1 DY2) (* DX2 DY1)))
  (if (/= D 0.0)
    (progn
      (setq 2D (+ D D)
    C1 (+ (* DX1 (+ X0 X1)) (* DY1 (+ Y0 Y1)))
    C2 (+ (* DX2 (+ X0 X2)) (* DY2 (+ Y0 Y2)))
    CE (List (/ (- (* C1 DY2) (* C2 DY1)) 2D)
     (/ (- (* C2 DX1) (* C1 DX2)) 2D)
       )
      )
      (list CE (distance CE P0))
    )
  )
)

;;;三点圆
(defun PPP_Circle_1(p1 p2 p3 / m1 m2 m3 v1 v2 v3 r1 r2 r3)
  (setq m1 (mtp p2 p3))
  (setq m2 (mtp p3 p1))
  (setq m3 (mtp p1 p2))
  (setq v1 (mapcar '- p3 p2))
  (setq v2 (mapcar '- p1 p3))
  (setq v3 (mapcar '- p2 p1))
  (setq r1 (mapcar '+ m1 (rot90 v1)))
  (setq r2 (mapcar '+ m2 (rot90 v2)))
  (setq r3 (mapcar '+ m3 (rot90 v3)))
  (setq c  (inters m1 r1 m2 r2 nil))
  (if c
    (list c (distance c p3))
  )
)

;;;点点切的圆(不相同的点)
(defun PPC_Circle(p1 p2 rad cen / InvP1 InvP2 IntPt Pair Tan1 Tan2 ret an HalfPi PA PB dd hh)
  (cond
    ( (equal p1 p2 1e-8) nil)
    ( (or (equal p1 cen 1e-8)
  (equal p2 cen 1e-8)
      )
      (if (equal p1 cen 1e-8)
        (setq pA p1 pB p2)
        (setq pA p2 pB p1)
      )
      (setq an (+ (angle p1 p2) (/ pi 2)))
      (setq dd (distance p1 p2))
      (setq HH (sqrt (- (* rad rad) (* dd dd))))
      (setq tan1 (polar pB an HH))
      (setq tan2 (polar pB an (- HH)))
      (list (list (mtp cen tan1) (/ rad 2))
    (list (mtp cen tan2) (/ rad 2))
      )
    )
    (t   
      (setq InvP1 (Point_Inversion rad cen p1))
      (setq InvP2 (Point_Inversion rad cen p2))
      (setq IntPt (inters invP1 invP2 p1 p2 nil))
      (if IntPt
        (if (setq pair (Tangent_Point rad cen intPt))
          (setq tan1 (car pair)
        tan2 (cadr pair)
        ret  (list (PPP_Circle p1 p2 tan1)
           (ppp_circle p1 p2 tan2)
             )
          )
        )
        (setq an     (angle p1 p2)
      HalfPi (/ pi 2)
      tan1   (polar cen (+ an HalfPi) rad)
      tan2   (polar cen (- an HalfPi) rad)
      ret    (list (PPP_Circle p1 p2 tan1)
           (ppp_circle p1 p2 tan2)
             )
        )
      )
    )
  )
)
;;;点切切的圆
(defun PCC_Circle(pt rad1 cen1 rad2 cen2 / hc an p1 p2 d1 d2 dp p3 rt aa)
  (setq HC (car (Homothetic_center rad1 cen1 rad2 cen2)))
  (if HC
    (setq an (angle cen1 cen2)
  p1 (polar cen1 (angle cen1 cen2) rad1)
  p2 (polar cen2 (angle cen2 cen1) rad2)
  d1 (distance hc p1)
  d2 (distance hc p2)
  dp (distance hc pt)
  dq (/ (* d1 d2) dp)
  p3 (polar hc (angle hc pt) dq)
  rt (PPC_Circle pt p3 rad1 cen1)
    )
    (if (equal rad1 rad2 1e-8)
      (progn
        (setq an (angle cen1 cen2)
      aa (angle cen1 pt)
      aa (- aa an)
      dp (distance pt cen1)
      p3 (polar cen2 (- (angle cen2 cen1) aa) dp)
        )
(if (equal p3 pt 1e-8)
  (list (list pt (distance p)))
  (setq rt (PPC_Circle pt p3 rad1 cen1))
)
      )
    )
  )
)

;;;make a point
(defun makepoint (p)
  (entmakex (list '(0 . "POINT") (cons 10 p)))
)

;;;make a circle
(defun makeCircle (p r)
  (entmakex (list '(0 . "CIRCLE") (cons 10 p) (cons 40 r)))
)

;;;make a line
(defun makeline (p q)
  (entmakex (list '(0 . "LINE") (cons 10 p) (cons 11 q)))
)
« Last Edit: September 26, 2011, 07:14:14 AM by HighflyingBird »
I am a bilingualist,Chinese and Chinglish.

highflyingbird

  • Bull Frog
  • Posts: 415
  • Later equals never.
Re: -={ Challenge }=- 3-Point Circle Tangent to Two Circles, with given Point.
« Reply #6 on: September 26, 2011, 07:18:49 AM »
here is how to draw it. Left is the case of point ,point,circle(PPC), Right is the case of point,circle,circle(PCC),Red circles are the solutions.
« Last Edit: September 26, 2011, 07:22:27 AM by HighflyingBird »
I am a bilingualist,Chinese and Chinglish.

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: -={ Challenge }=- 3-Point Circle Tangent to Two Circles, with given Point.
« Reply #7 on: September 26, 2011, 08:23:32 AM »
Brilliant Highflyingbird...
I've zipped 10 steps from start to the end of construction...

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: -={ Challenge }=- 3-Point Circle Tangent to Two Circles, with given Point.
« Reply #8 on: September 27, 2011, 12:57:11 PM »
I haven't had time to look at this recently, but I shall have to spend some time studying your code Highflyingbird.  :-)

highflyingbird

  • Bull Frog
  • Posts: 415
  • Later equals never.
Re: -={ Challenge }=- 3-Point Circle Tangent to Two Circles, with given Point.
« Reply #9 on: September 27, 2011, 01:42:52 PM »
here are  the other cases.

then  LCC, and LLC  can be derived from   PLC  question and PLL question.
« Last Edit: September 27, 2011, 01:50:48 PM by HighflyingBird »
I am a bilingualist,Chinese and Chinglish.

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: -={ Challenge }=- 3-Point Circle Tangent to Two Circles, with given Point.
« Reply #10 on: September 28, 2011, 09:19:41 AM »
I've constructed all cases - step by step... Only lack is that I haven't included all tangent circles solutions, but I think and this is fine... So check my *.zip

Regards, M.R.
« Last Edit: September 28, 2011, 05:08:20 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: -={ Challenge }=- 3-Point Circle Tangent to Two Circles, with given Point.
« Reply #11 on: September 28, 2011, 05:13:34 PM »
Just updated *.zip to include CCC (step 04, step 05)... BTW, there is little discord in step 05 circle tan,tan,tan is not exactly matching the construction, but error is minor...

ENJOY, M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: -={ Challenge }=- 3-Point Circle Tangent to Two Circles, with given Point.
« Reply #12 on: September 29, 2011, 03:37:27 AM »
CCC step 05 is now revised...

M.R.
 8-)
« Last Edit: September 30, 2011, 11:45:58 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: -={ Challenge }=- 3-Point Circle Tangent to Two Circles, with given Point.
« Reply #13 on: September 29, 2011, 06:05:52 PM »
In addition to my last post, I've wrote short routine for drawing radical circle :

Code: [Select]
(defun c:radical-circle ( / SCI1 SCI2 SCI3 C1 C2 C3 CI1 CI2 CI3 D12 D13 D23 N12 N13 N23 O O1 O2 O3 OSM P12 P13 P23 PP12 PP13 PP23 R1 R2 R3 RRAD X12 X13 X23)
(arxload "geomcal.arx")
(vl-cmdf "ucs" "w")
(setq osm (getvar 'osmode))
(setvar 'osmode 0)
(while (null sci1)
(prompt "\nPick first circle")
(setq sci1 (ssget "_+.:E:S" (list (cons 0 "CIRCLE") (cons 210 (list 0.0 0.0 1.0)))))
)
(setq ci1 (ssname sci1 0))
(setq sci2 sci1)
(while (or (null sci2) (equal (ssname sci2 0) ci1))
(prompt "\nPick second circle")
(setq sci2 (ssget "_+.:E:S" (list (cons 0 "CIRCLE") (cons 210 (list 0.0 0.0 1.0)))))
)
(setq ci2 (ssname sci2 0))
(setq sci3 sci2)
(while (or (null sci3) (or (equal (ssname sci3 0) ci1) (equal (ssname sci3 0) ci2)))
(prompt "\nPick third circle")
(setq sci3 (ssget "_+.:E:S" (list (cons 0 "CIRCLE") (cons 210 (list 0.0 0.0 1.0)))))
)
(setq ci3 (ssname sci3 0))
(setq c1 (cdr (assoc 10 (entget ci1))))
(setq c2 (cdr (assoc 10 (entget ci2))))
(setq c3 (cdr (assoc 10 (entget ci3))))
(setq r1 (cdr (assoc 40 (entget ci1))))
(setq r2 (cdr (assoc 40 (entget ci2))))
(setq r3 (cdr (assoc 40 (entget ci3))))
(setq d12 (distance c1 c2))
(setq d13 (distance c1 c3))
(setq d23 (distance c2 c3))
(if (>= r1 r2) (setq x12 (/ (+ d12 (/ (abs (- (expt r1 2) (expt r2 2))) d12)) 2)) (setq x12 (/ (- d12 (/ (abs (- (expt r1 2) (expt r2 2))) d12)) 2)) )
(setq p12 (polar c1 (angle c1 c2) x12))
(setq n12 (cal "nor(c1,c2)"))
(setq pp12 (cal "p12+n12"))
(if (>= r1 r3) (setq x13 (/ (+ d13 (/ (abs (- (expt r1 2) (expt r3 2))) d13)) 2)) (setq x13 (/ (- d13 (/ (abs (- (expt r1 2) (expt r3 2))) d13)) 2)) )
(setq p13 (polar c1 (angle c1 c3) x13))
(setq n13 (cal "nor(c1,c3)"))
(setq pp13 (cal "p13+n13"))
(if (>= r2 r3) (setq x23 (/ (+ d23 (/ (abs (- (expt r2 2) (expt r3 2))) d23)) 2)) (setq x23 (/ (- d23 (/ (abs (- (expt r2 2) (expt r3 2))) d23)) 2)) )
(setq p23 (polar c2 (angle c2 c3) x23))
(setq n23 (cal "nor(c2,c3)"))
(setq pp23 (cal "p23+n23"))
(setq o1 (inters p12 pp12 p13 pp13 nil))
(setq o2 (inters p12 pp12 p23 pp23 nil))
(setq o3 (inters p13 pp13 p23 pp23 nil))
(if (and (equal o1 o2 0.00000001) (equal o2 o3 0.00000001) (equal o1 o3 0.00000001)) (setq o o1))
(setq rrad (sqrt (- (expt (distance c1 o) 2) (expt r1 2))))
(entmakex (list (cons 0 "CIRCLE") (cons 10 o) (cons 40 rrad)))
(setvar 'osmode osm)
(princ)
)

M.R.
« Last Edit: September 30, 2011, 01:07:39 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

chlh_jd

  • Guest
Re: -={ Challenge }=- 3-Point Circle Tangent to Two Circles, with given Point.
« Reply #14 on: September 30, 2011, 10:59:56 AM »
hi , all
Highfly's method  is Efficient , until now , I still can not understand .
Following code is using  Asymptotic method .
Just for test , when the point is close the line (cen1 cen2) , it return the wrong result .
Code: [Select]

(defun c:test (/ foo cir1 cir2 pnt dxf1 dxf2 rad1 rad2 cen1 cen2 cr1)
  (defun foo (mode / is_go pl1 pl2 mp1 mp2)
    ;; Using  Asymptotic method
    ;; mode 1 -- outside 2 circles ; 2 -- include 2 circles
    ;;      3 -- include circle-1  ; 4 -- include circle-2
    ;;
  (if (setq cr1 (3PCirCle pnt cen1 cen2)) (setq is_go T))
  (while is_go
    (setq pl1 (C_INT_C (car cr1) (cadr cr1) cen1 rad1)
  pl2 (C_INT_C (car cr1) (cadr cr1) cen2 rad2)  
  )
     (cond ((and pl1 (cadr pl1))
            (setq mp1 (midpt (car pl1) (cadr pl1)))
   )
  (pl1 (setq mp1 (car pl1)))
  (t)
  )
    (cond ((and pl2 (cadr pl2))
            (setq mp2 (midpt (car pl2) (cadr pl2)))
   )
  (pl1 (setq mp2 (car pl2)))
  (t)
  ) 
    (if (or (and (not pl1) (not pl2)) (and (not (cadr pl1)) (not (cadr pl2))) (and (equal (car pl1) (cadr pl1) 1e-3) (equal (car pl2) (cadr pl2) 1e-3 )))
      (setq is_go nil)
      (setq cr1 (3PCirCle pnt (polar cen1 (cond ((or (= mode 1) (= mode 4))(angle cen1 mp1))
((or (= mode 2) (= mode 3)) (if (ss-ostp mp1 pnt cen1 cen2) (angle cen1 mp1) (angle mp1 cen1)))
)
rad1) (polar cen2
      (cond ((or (= mode 1) (= mode 3))(angle cen2 mp2))
((or (= mode 2) (= mode 4)) (if (ss-ostp mp2 pnt cen1 cen2) (angle cen2 mp2) (angle mp2 cen2)))
) rad2)))
      )
    )
  (if cr1 (entmake (list (cons 0 "CIRCLE") (cons 10 (car cr1)) (cons 40 (cadr cr1)) (cons 62 mode))))
    )
  (setq cir1 (car (entsel "\nPick a circle:")))
  (setq cir2 (car (entsel "\nPick another circle:")))
  (setq pnt (getpoint "\nPick a point:"))
  (if (not (and cir1 cir2 pnt))
    (exit)
  )
  (setq dxf1 (entget cir1))
  (setq dxf2 (entget cir2))
  (setq rad1 (cdr (assoc 40 dxf1)))
  (setq rad2 (cdr (assoc 40 dxf2)))
  (setq cen1 (cdr (assoc 10 dxf1)))
  (setq cen2 (cdr (assoc 10 dxf2)))
  ;;
  (foo 1)
  ;;; 
  (foo 2)
  ;;;include circle-1 , outside circle-2
  (foo 3)
  ;;;include circle-2 , outside circle-1
  (foo 4)
  (princ) 
  )
(defun midpt (pta ptb)
  (mapcar (function (lambda (x y)
      (/ (+ x y) 2.0)
    )
  )
  pta
  ptb
  )
)
;;;is outside of triangle
(defun ss-ostp (p p1 p2 p3)
      ;;Gile & Lee Mac
      ((lambda (a b c)
(not
   (or
     (and (< 1e-6 a) (< 1e-6 b) (< 1e-6 c))
     (and (< a -1e-6) (< b -1e-6) (< c -1e-6))
   ) ;_if at triangle edge, so add tolerance
)
       )
(sin (- (angle p1 p) (angle p1 p2)))
(sin (- (angle p2 p) (angle p2 p3)))
(sin (- (angle p3 p) (angle p3 p1)))
      )   
  )
;;;circle intersect with circle
(defun C_Int_C    (ce1 r1 ce2 r2 / dis a b)
  ;;by w_kai
  (setq dis (distance ce1 ce2))
  (cond
    ((equal dis (+ r1 r2))
     (list (polar ce1 (angle ce1 ce2) r1))
    )
    ((equal dis (abs (- r1 r2)))
     (if (minusp (- r1 r2))
       (list (polar ce2 (angle ce2 ce1) r2))
       (list (polar ce1 (angle ce1 ce2) r1))
     )
    )
    ((and (> dis (abs (- r1 r2)))
  (< dis (+ r1 r2))
     )
     (setq a (/ (- (+ (* dis dis) (* r1 r1))
    (* r2 r2)
)
(* 2. dis)
      )
     )
     (setq b (sqrt (- (* r1 r1) (* a a))))
     (list (polar (polar ce1 (angle ce1 ce2) a)
  (+ (angle ce1 ce2) (/ pi 2))
  b
   )
   (polar (polar ce1 (angle ce1 ce2) a)
  (- (angle ce1 ce2) (/ pi 2))
  b
   )
     )
    )
  )
)
;;;
;;; 三点圆函数
  (defun 3PCirCle
(P0 P1 P2 / X0 Y0 X1 Y1 X2 Y2 DX1 DY1 DX2 DY2 D 2D C1 C2 CE)
    ;;by highflybird
    (setq X0  (car P0)
  Y0  (cadr P0)
  X1  (car P1)
  Y1  (cadr P1)
  X2  (car P2)
  Y2  (cadr P2)
  DX1 (- X1 X0)
  DY1 (- Y1 Y0)
  DX2 (- X2 X0)
  DY2 (- Y2 Y0)
    )
    (setq D (- (* DX1 DY2) (* DX2 DY1)))
    (if (/= D 0.0)
      (progn
(setq 2D (+ D D)
      C1 (+ (* DX1 (+ X0 X1)) (* DY1 (+ Y0 Y1)))
      C2 (+ (* DX2 (+ X0 X2)) (* DY2 (+ Y0 Y2)))
      CE (List (/ (- (* C1 DY2) (* C2 DY1)) 2D)
       (/ (- (* C2 DX1) (* C1 DX2)) 2D)
)
)
(list CE (distance CE P0) (list p0 p1 p2))
      )
    )
  )
« Last Edit: September 30, 2011, 11:15:16 AM by chlh_jd »