lookiassist.blogg.se

Two circles in rectangle compute angle puzzle
Two circles in rectangle compute angle puzzle












two circles in rectangle compute angle puzzle

Now we can calculate area of intersection of a half-circle and an infinitely tall box, standing on the x axis (the center of the circle also lies on the the x axis) by integrating over y: f(x): integral(sqrt(1 - x * x) * dx) = (sqrt(1 - x * x) * x + asin(x)) / 2 + C // *x%29Īrea(x0, x1) = f(max(-1, min(1, x1))) - f(max(-1, min(1, x0))) // the integral is not defined outside but we want it to be zero out there This function indeed has an integral of pi/2, since it is an upper half of a unit circle (the area of half a circle is pi * r^2 / 2 and we already said unit, which means r = 1). Y = sqrt(1 - x * x) // the same thing, arguably faster to compute Let's assume unit circle for simplicity, we can always plug the center and radius back later on: y = sin(acos(x)) // x in This only holds for x in (other values will cause imaginary outputs) but we know that the area outside that range is zero, so that is handled easily. Now given the range of x, I can integrate over y, to get an area of the upper half of a circle. Y = center.y + sin(acos((x - center.x) / radius)) * radius // substitute to the 2nd equation Theta = acos((x - center.x) / radius) // value of theta from the 1st equation Let's try to change the arguments: (x - center.x) / radius = cos(theta) // the 1st equation I can only integrate over the angle theta, yielding areas of pizza slices. This is nice, but I'm unable to integrate the area of that circle over x or y those are different quantities. Let's start with writing an obvious formula for plotting a circle: x = center.x + cos(theta) * radius I want to use integration - that seems like a good idea. Note that if your boxes are not axis-aligned (but still boxes with right angles, rather than general quads), you can take advantage of the circles being round, rotate the coordinates of everything so that the box ends up axis-aligned and then use this code. The solution below is completely general, and will work for any number of intersections (not only two). Note that my boxes are axis aligned, this is not quite specified by the OP.

two circles in rectangle compute angle puzzle

I realize this was answered a while ago but I'm solving the same problem and I couldn't find an out-of-the box workable solution I could use. You can determine if a vertex is inside the circle by calculating if its distance from the center is less than the radius. The areas you need to compute can be found by computing the area of a circular segment and computing the area of a triangle. Most of the points you'll need to use can be found by finding the intersection of a line and a circle

#Two circles in rectangle compute angle puzzle plus

XXXXX XXXXXXXXXģ vertices are inside the circle: The area of the rectangle minus the area of a triangle plus the area of a circular segment XXXXX 0 vertices is inside the circle: The area of a circular segment XXXXX -ġ vertex is inside the circle: The sum of the areas of a circular segment and a triangle.














Two circles in rectangle compute angle puzzle