gpt4 book ai didi

How to find how much of a circle hangs out of a rectangle(如何找出长方形外有多少圆?)

转载 作者:bug小助手 更新时间:2023-10-24 21:42:23 31 4
gpt4 key购买 nike



What is the area of this circle that hangs out of the rectangle (imagine the rectangle stretches out to (infinity, infinity) on both ends), and how can I generalize this to any circle of any radius as well as any rectangle of any dimensions.

这个圆在矩形之外的面积是多少(想象这个矩形在两端延伸到(无穷大,无穷大)),我如何将它推广到任何半径的圆以及任何维度的矩形。


Circle of radius 7, origin at (3,2), partly hanging out of a rectangle that has a corner at (0,0), stretching out infinitely in both positive directions1


I have a coding problem in which I need to calculate what percentage of the circle is in the rectangle for a number of different circles, I am struggling with the code when the corner of the rectangle is covered. Without the corner issue, I could simply see how far away each protruding edge is, then use some circle/trig math to find the area of each outside bit. But once the corner is covered, the code overcounts the corner bit: in the extreme case where the circle is at (0,0) it counts the left half as out and the top half as out, and concludes that the whole circle is out. I've drawn diagrams but I've failed to find a way to discover the overcounted area. I originally tried finding the dimensions of the outer triangle, but I can't figure out that either.

我有一个编码问题,在这个问题中,我需要计算一些不同的圆在矩形中的百分比,当矩形的角被覆盖时,我正在与代码作斗争。没有角的问题,我可以简单地看到每个突出的边缘有多远,然后使用一些圆/三角数学来找到每个外部位的面积。但是,一旦角被覆盖,代码就会过多地计算角位:在圆位于(0,0)的极端情况下,它将左半部分计为out,上半部分计为out,并得出整个圆为out的结论。我画了图表,但找不到发现多算面积的方法。我最初试着找出外三角形的尺寸,但我也想不出来。


I know there is an answer, because there's enough information for only one possibility, but I can't figure out how.

我知道答案是有的,因为只有一种可能性有足够的信息,但我不知道如何解决。


This is the code I have so far, it just counts how much area that the segments perpendicular to the axes cover, thus overcounts when these segments overlap.
xbounds is a tuple (low, high) for the width of the rectangle and ybounds1 (low, high) is a tuple for the height of the rectangle these just say where the rectangle starts and ends on the x and y axes, in practice, the first value is 0 because the rectangle starts at zero and the second values are very large numbers.
Range is the radius of the circle.
Pos is an imaginary number representing the origin where real is the x coord and imag is the y coord.

这是我到目前为止的代码,它只计算垂直于轴的线段覆盖的面积,因此当这些线段重叠时会过多计算。Xbound是矩形宽度的元组(低,高),yrangs1(低,高)是矩形高度的元组,它们只表示矩形在x轴和y轴上的开始和结束位置,在实践中,第一个值是0,因为矩形从零开始,第二个值是非常大的数字。范围是圆的半径。POS是代表原点的虚数,其中REAL是x坐标,IMAG是Y坐标。


r2 = range*range
outarea = 0

if (b:= -pos.real+range+xbounds[0])>0:
theta = 2*acos(1-b/range)
outarea=0.5*r2*(theta-sin(theta))

if (b:= pos.real+range-xbounds[1])>0:
theta = 2*acos(1-b/range)
outarea+=0.5*r2*(theta-sin(theta))

if (b:= -pos.imag+range+ybounds[0])>0:
theta = 2*acos(1-b/range)
outarea+=0.5*r2*(theta-sin(theta))

if (b:= pos.imag+range-ybounds[1])>0:
theta = 2*acos(1-b/range)
outarea+=0.5*r2*(theta-sin(theta))

更多回答

This is a math problem, not a programming problem.

这是一道数学题,不是编程题。

I considered posting on mathoverflow, but all the posts i saw there were highly theoretical and abstract, which made my geometry problem feel out of place. I felt that this forum was better suited for trying to find a good answer, as i was looking for a python code snippet i could use to compute the area.

我考虑在MathOverflow上发帖,但我在那里看到的所有帖子都是高度理论性和抽象的,这让我的几何问题感觉格格不入。我觉得这个论坛更适合试图找到一个好的答案,因为我正在寻找一个可以用来计算面积的Python代码片段。

Mathoverflow is not appropriate, that's true, but there is also math.stackexchange.com. See math.meta.stackexchange.com/questions/41/…).

MathOverflow是不合适的,这是真的,但也有math.stackexchange.com。参见math.meta.stackexchange.com/Questions/41/…)。

Thank you for the info, I'll keep that in mind

谢谢你的信息,我会记住的

优秀答案推荐

If the corner (I'll call it O) is in the interior of the circle, you can

如果角(我称它为O)在圆的内部,您可以



  • Draw a line between the two intersections A and B.

    在两个交叉点A和B之间画一条线。



  • Get the area of the right triangle ABO (green below).

    获取直角三角形ABO的面积(下图为绿色)。



  • Get the area of the sector between A and B, centered at the center of the circle C (yellow plus blue below). This should just be pi*r*r*percentage, where percentage can be computed using the formula theta = arccos((CA dot product CB) / (|CA| |CB|)), then percentage = theta / twopi.

    获取A和B之间的扇区区域,以圆圈C的中心为中心(下面是黄色加蓝色)。这应该只是pi*r*r*百分比,其中百分比可以使用公式theta=ARccOS((CA点积Cb)/(|CA||Cb|))计算,然后百分比=theta/twopi。



  • Compute the area of the triangle ABC (blue below). Might need Heron's formula.

    计算三角形ABC(下图蓝色)的面积。可能需要海伦的配方。



  • The area (yellow below) between the chord AB and the circle is Area(sector) - Area(triangle ABC).

    弦AB和圆之间的区域(下图为黄色)是区域(扇区)-区域(三角形ABC)。



  • The area of the intersection of the circle and the rectangle is (Area between chord and circle) + Area(triangle ABC). This is Green plus yellow below.

    圆和矩形相交的面积是(弦和圆的面积)+面积(三角形ABC)。下面是绿色加黄色。



  • The area of circle outside of the rectangle is the area of the circle minus their intersection.

    矩形外的圆的面积等于该圆的面积减去它们的交点。




enter image description here


更多回答

Thank you so much, especially for including little code snippets, i cant believe i had been looking at the wrong place (outside) the whole time, this is a really clever solution!

非常感谢你,特别是包括一些小代码片段,我不敢相信我一直在看错误的地方(外面),这是一个真正聪明的解决方案!

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