圆与圆的交点
如何计算两个圆的交点。我希望在所有情况下都会有两个、一个或没有交叉点。
我有中心点的 x 和 y 坐标以及每个圆的半径。
python 中的答案是首选,但任何工作算法都是可以接受的。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何计算两个圆的交点。我希望在所有情况下都会有两个、一个或没有交叉点。
我有中心点的 x 和 y 坐标以及每个圆的半径。
python 中的答案是首选,但任何工作算法都是可以接受的。
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(6)
两个圆的交点
作者:Paul Bourke
来源:http://paulbourke.net/geometry/circlesphere/
Intersection of two circles
Written by Paul Bourke
Source: http://paulbourke.net/geometry/circlesphere/
为什么不直接使用您最喜欢的程序语言(或可编程计算器!)的 7 行代码,如下所示。
假设给定 P0 坐标 (x0,y0)、P1 坐标 (x1,y1)、r0 和 r1,并且您想要找到 P3 坐标 (x3,y3):
Why not just use 7 lines of your favorite procedural language (or programmable calculator!) as below.
Assuming you are given P0 coords (x0,y0), P1 coords (x1,y1), r0 and r1 and you want to find P3 coords (x3,y3):
这是我基于 Paul Bourke 的文章 的 C++ 实现。它仅在有两个交集时才有效,否则它可能返回 NaN NAN NAN NAN。
Here is my C++ implementation based on Paul Bourke's article. It only works if there are two intersections, otherwise it probably returns NaN NAN NAN NAN.
这是使用向量的 Javascript 实现。该代码有详细记录,您应该能够遵循它。这是原始来源
查看现场演示此处:
Here's an implementation in Javascript using vectors. The code is well documented, you should be able to follow it. Here's the original source
See live demo here:
试试这个;
Try this;
确定交点 P1 和 P2 的快速方法是获取圆心 A 和 B 之间的向量 w。
现在想象一个由点 A 和 P1 之间的两个向量 a 和 b 组成的矩形,我们可以说
唯一剩下的问题是,向量 a 和 b 有多长:
我们知道
|a|^2 + |b|^2 = r_A^2
和(|w| - |a|)^2 + |b|^2 = r_B^2
,将它们设置为相等并求解 < code>|a| 产生现在向量的长度可用于通过使用归一化向量 w 来构造实际向量 a 和 b。
当实现这个想法时,解决方案非常简单
A quick way to determine the intersection points P1 and P2 is to take the vector w between the center points A and B of the circles.
When now imagining a rectangle that is spanned by two vectors a and b between point A and P1, we can say
The only remaining question is, how long the vectors a and b are:
We know that
|a|^2 + |b|^2 = r_A^2
and(|w| - |a|)^2 + |b|^2 = r_B^2
, setting them equal and solving for|a|
yieldsNow the lengths of the vectors can be used to construct the actual vectors a and b by using the normalized vector w.
When implementing this idea, the solution is pretty straightforward