简体   繁体   English

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

[英]Calculate coordinates of circle that best approximates intersection between 2 circles

I have two circles that could intersect, and if is it the case, I would calculate the coordinates of the largest circle that approximates that intersection area. 我有两个可以交叉的圆圈,如果是这样的话,我会计算出近似于交叉区域的最大圆的坐标。

I drew a sketch in svg to represent the problem: 我在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>

you can try it online here: http://www.w3schools.com/svg/tryit.asp?filename=trysvg_line . 你可以在网上试试: http//www.w3schools.com/svg/tryit.asp?filename = trysvg_line

What I would, having the first two circles, is the center and the radius of third one (that in the example I drew by hand). 在前两个圆圈中,我想要的是第三个圆心的中心和半径(在我用手绘制的例子中)。

Let

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

be the given input data and 是给定的输入数据和

C, r3 = center, radius of third circle

be the largest circle that fits into the intersection of the first two circles. 是适合前两个圆的交叉点的最大圆。

Denote by 表示

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

D and E are points on the line connecting the centers A and B. D has distance r1 from A and E has distance r2 from B. Therefore D和E是连接中心A和B的线上的点.D与A的距离为r1,E与B的距离为r2。因此

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

from which follows 从下面

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

If r3 < 0 then the circles do not intersect at all. 如果r3 < 0那么圆圈根本不相交。

(The above calculation assumes that none of the circles lies completely within the other circle.) (上面的计算假设没有圆圈完全位于另一个圆圈内。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM