计算最接近2个圆之间交点的圆的坐标

时间:2014-03-29 09:47:39

标签: math svg language-agnostic geometry

我有两个可以相交的圆圈,如果是这样的话,我会计算出近似于该交叉区域的最大圆的坐标。

我在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

在前两个圆圈中,我想要的是第三个圆心的中心和半径(在我手工绘制的例子中)。

1 个答案:

答案 0 :(得分: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则圈子根本不相交。

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

相关问题