2014-03-29 78 views
0

我有两个可以相交的圆,如果是这种情况,我会计算最接近该交集区的最大圆的坐标。计算最接近2个圆的交点的圆的坐标

我画了一个草图在SVG代表问题:

<svg width="400" height="400"> 
    <line x1="85" y1="50" x2="140" y2="70" stroke="rgb(50,50,50)" stroke-width="1" /> 
    <circle cx="85" cy="50" r="50" stroke="rgba(50,50,50,0.8)" stroke-width="1" fill="rgba(0,0,150,0.3)" /> 
    <circle cx="140" cy="70" r="40" stroke="rgba(50,50,50,0.8)" stroke-width="1" fill="rgba(150,0,0,0.3)" /> 

    <circle cx="117" cy="62" r="16" stroke="rgba(50,50,50,0.8)" stroke-width="1" fill="rgba(00,150,0,0.3)" /> 
</svg> 

您可以在线尝试在这里:http://www.w3schools.com/svg/tryit.asp?filename=trysvg_line

我的头两个圆圈是第三个圆的中心和半径(在我用手画的例子中)。

+0

您是指“近似”交叉区域的含义? - 您的在线SVG在我的浏览器中不起作用,也许您可​​以为您的问题添加图片。 –

+1

Tryit中的代码与上面的代码不匹配,如果将代码替换为上述代码,您将得到所需的图 – jing3142

+0

@ jing3142:这很有道理,谢谢! –

回答

2

A, r1 = center, radius of first circle 
B, r2 = center, radius of second circle 

在给定的输入数据和

C, r3 = center, radius of third circle 

是装配到所述第一两个圆的交点的最大圆。

表示由

D = intersection point of first with third circle 
E = intersection point of second with third circle 

d和E点就行连接中心A和B. d具有距离r1从 A和E具有从B.距离r2因此

D = A + r1 * (B - A)/dist(A, B) 
E = B - r2 * (B - A)/dist(A, B) 

从下面

C = (D + E)/2 = (A + B + (r1 - r2)*(B - A)/dist(A, B))/2 
r3 = dist(D, E)/2 = (r1 + r2 - dist(A, B))/2 

如果r3 < 0然后吨他的圈子根本不相交。

(上面的计算假设没有一个圆圈完全位于另一个圆圈内。)