求两个圆之间的距离

发布于 2024-10-28 08:37:59 字数 162 浏览 1 评论 0原文

我试图弄清楚如何获得两个圆相对于其方形容器盒的角的距离。我需要一些数学方面的帮助。

查找两个圆之间的距离

如何计算出标有问号的线的像素数?

一如既往地感谢帮助。

I'm trying to figure out how to get the distance from two circles relative to the corners of their square container boxes. I need some help with the maths here.

Finding distance between two circles

How can I work out the number of pixels for the line marked with a question mark?

Appreciate the help as always.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

笛声青案梦长安 2024-11-04 08:37:59

tldr:计算每个圆中心点之间的距离,然后从中减去每个圆的半径。

为了演示的目的,我们将假设如下:

  • 直径为 200 像素 (r1 = 100) 的圆位于 (x, y) 坐标 (0, 0)
  • 直径为 100 像素 (r2 = 50) 的圆位于 (150, -150) 的 (x, y) 坐标处。

假设它们的中心之间的距离是: Distance

要找到它们边界之间的距离,我们减去半径< /strong> 每个圆的中心之间的距离。

这给我们留下了等式:

sqrt((x2 − x1)^2 + (y2 − y1)^2) − (r2 + r1)

将您的值插入上面给出:

sqrt((150 − 0)^2 + (-150 − 0)^2) − (100 + 50) = 62.132034356px

tldr: Calculate the distance between each circles center point, then subtract the radius' of each circle from that.

For the purpose of a demonstration, we will assume the following:

  • The 200px diameter (r1 = 100) circle is at the (x, y) coordinates of (0, 0), and
  • the 100px diameter (r2 = 50) circle is at (x, y) coordinates of (150, -150).

Given that the distance between their centers is: Distance

To find the distance between their boundaries, we subtract the radius of each circle from the distance between their centers.

This leaves us with the equation:

sqrt((x2 − x1)^2 + (y2 − y1)^2) − (r2 + r1)

Inserting your values into the above gives:

sqrt((150 − 0)^2 + (-150 − 0)^2) − (100 + 50) = 62.132034356px
无需解释 2024-11-04 08:37:59

你有每个圆圈的中点吗?如果这样做,首先计算距圆心的距离。

distance² = center1² + center2²

然后,您需要减去两个圆的半径。在您的情况下,它将是 150 (100 + 50)

Do you have the middle point of each circles? If you do, first calculate the distance from the centre of circles.

distance² = center1² + center2²

Then, you will need to minus the radius of both circles. In your case, it will be 150 (100 + 50)

喜爱皱眉﹌ 2024-11-04 08:37:59

让我们看看......每个半径都是每条边长的一半,从中心之间的距离减去半径之和即可得到剩下的量。

希望有帮助吗?

Let's see... each radius is half each side length, and subtracting the sum of the radii from the distance between the center gives you the amount that's left.

Hope that helps?

冷…雨湿花 2024-11-04 08:37:59

Daniel 答案的代数简化版本是

  (r1 + r2) * (sqrt(2) - 1) 
= (s1 + s2) * (sqrt(2) - 1)/2

其中 r1,r2 是两个半径,s1,s2 是两个正方形边。通过单独查看每个正方形并注意从圆/正方​​形中心到正方形角的距离 d1 是 sqrt(2) * r,并且该正方形内所需的距离是 d1 - 圆半径 r,很容易看出这一点。

The algebraically simplified version of Daniel's answer is

  (r1 + r2) * (sqrt(2) - 1) 
= (s1 + s2) * (sqrt(2) - 1)/2

where r1,r2 are the two radii and s1,s2 are the two square sides. This is easily seen by looking at each square individually and noticing that the distance d1 from the circle/square center to the square corner is sqrt(2) * r, and the desired distance within that square is d1 - the circle radius r.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文