This question already has answers here:

Finding the smallest circle that encompasses other circles?
(9个答案)
我试图找到一种算法来计算中心的坐标和覆盖两个较小圆的最小圆的半径。我知道两个小圆心的半径和x,y坐标。
我尝试了下面的算法,即使两个圆圈重叠或相距很远,它也能工作,但是只有当圆环1和圆环2在同一个X轴或Y轴上时才有效。
设c1,c2为圆1和圆2;
r be半径:
    if c1x >= c2x:
        if c1y >= c2y:
            c = ((c1x + c1r) + (c2x - c2r))/2, ((c1y + c1r) + (c2y - c2r))/2
            r = max(((c1x + c1r) - (c2x - c2r))/2,
                     ((c1y + c1r) - (c2y - c2r))/2)
        elif c1y < c2y:
            c = ((c1x + c1r) + (c2x - c2r))/2, ((c2y + c2r) + (c1y - c1r))/2
            r = max(((c1x + c1r) - (c2x - c2r))/2,
                     ((c2y + c2r) - (c1y - c1r))/2)
    elif if c1x < c2x:
        if c1y >= c2y:
            c = ((c2x + c2r) + (c1x - c1r))/2, ((c1y + c1r) + (c2y - c2r))/2
            r = max(((c2x + c2r) - (c1x - c1r))/2,
                     ((c1y + c1r) - (c2y - c2r))/2)
        elif c1y < c2y:
            c = ((c2x + c2r) + (c1x - c1r))/2, ((c2y + c2r) + (c1y - c1r))/2
            r = max(((c2x + c2r) - (c1x - c1r))/2,
                     ((c2y + c2r) - (c1y - c1r))/2)

最佳答案

覆盖圆参数(伪码):

dx = c2x - c1x
dy = c2y - c1y
//center-center distance
dc = Sqrt(dx**2 + dy**2)
rmin = Min(r1, r2)
rmax = Max(r1, r2)
if rmin + dc < rmax then
    covercenter = center of larger circle
    R = rmax
else
    R = 0.5 * (r1 + r2 + dc)
    x = c1x + (R - r1) * dx / dc
    y = c1y + (R - r1) * dy / dc

工作示例(蓝色表示覆盖):
python - 计算包含两个较小圆的最小圆的中心和半径-LMLPHP

关于python - 计算包含两个较小圆的最小圆的中心和半径,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36735383/

10-11 17:53