gpt4 book ai didi

algorithm - 圆-圆交点

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:12:43 30 4
gpt4 key购买 nike

如何计算两个圆的交点。我希望在所有情况下都有两个、一个或没有交点。

我有中心点的 x 和 y 坐标,以及每个圆的半径。

Python 中的答案是首选,但任何可用的算法都是可以接受的。

最佳答案

Intersection of two circles

作者:保罗·伯克

The following note describes how to find the intersection point(s) between two circles on a plane, the following notation is used. The aim is to find the two points P3 = (x3, y3) if they exist.

Intersection of 2 circles

First calculate the distance d between the center of the circles. d = ||P1 - P0||.

  • If d > r0 + r1 then there are no solutions, the circles are separate.

  • If d < |r0 - r1| then there are no solutions because one circle is contained within the other.

  • If d = 0 and r0 = r1 then the circles are coincident and there are an infinite number of solutions.

Considering the two triangles P0P2P3 and P1P2P3 we can write

a2 + h2 = r02 and b2 + h2 = r12

Using d = a + b we can solve for a,

a = (r02 - r12 + d2 ) / (2 d)

It can be readily shown that this reduces to r 0 when the two circles touch at one point, ie: d = r 0 + r 1

Solve for h by substituting a into the first equation, h 2 = r 0 2 - a 2

So

P2 = P0 + a ( P1 - P0 ) / d

And finally, P3 = (x3,y3) in terms of P0 = (x0,y0), P1 = (x1,y1) and P2 = (x2,y2), is

x3 = x2 +- h ( y1 - y0 ) / d

y3 = y2 -+ h ( x1 - x0 ) / d

来源:http://paulbourke.net/geometry/circlesphere/

关于algorithm - 圆-圆交点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3349125/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com