0
$\begingroup$

I'm trying to determine 'how much' (as a percentage) a 2D rectangle fills a 2D circle.

Actual Application:

I was comparing the accuracy of some computer game weapons by calculating the max possible dispersion from the weapon's shell origion at a given range. After that, I added a player stand in to help visualize the possible dispersion vs size of the target. Of course I can eyeball the values, but I don't know how to calculate this geometry (as the player's head and feet would not actually be inside the dispersion area, so a basic area calculation is not accurate).

Any guidance is appreciated.

UPDATE:

I'm sorry that the question was not more clear, I'll try to elaborate:

In the case of the smaller circle, if you did a basic area calculation of the circle (1.828) and the rectangle (1.6), the result would say that the rectangle fills ~87% of the circle. However, the person cannot be compacted, and their upper body and lower body do not fall within the circle, and therefore the result is not accurate.

Now I think all I need to do is to subtract the difference of the circle's diameter from the max extents of the rectangle (so 2m - 1.526 = 0.474, or in other words, just make the rectangle as tall as the circle's diameter) making the rectangle's new area 1.526 * 0.8. Making the new percentage ~69%, which should be much more accurate. Am I on the right track?

Image:

enter image description here

Actual Values from the Test:

Player: 2m tall, 0.8m wide.

Weapon Dispersion Circle A (green): radius = 0.763.

Weapon Dispersion Circle B (red): radius = 1.05.

$\endgroup$
  • $\begingroup$ If the rectangle falls entirely inside the circle, then the answer may be found by taking a ratio of the rectangle's area to the circle's area. Othewise some specifics of how the rectangle overlaps the circle are needed. $\endgroup$ – hardmath Jun 5 '15 at 3:11
  • $\begingroup$ It is one the right track, the correct ratio should be around $\frac{1.1623128}{\pi (0.763)^2} \approx 63.55\%$. However, instead of setting the height of the rectangle as the diameter $d = 1.526$ of circle, I will set it to a number between $d$ and the side length of the intersection $\ell = 2 \sqrt{0.763^2 - 0.4^2} \approx 1.29949$. Let's say we approximate the height of the rectangle as $\frac{2d+\ell}{3} \approx 1.45050$, the ratio becomes $\frac{1.45050\times 0.8}{\pi (0.763)^2} \approx 63.45\%$. Accurate to within $1%$ of the correct value. $\endgroup$ – achille hui Jun 5 '15 at 12:14
  • $\begingroup$ @achille hui: Very interesting. If you don't mind, I do have some followup questions: 1) Why did you decide to use (2d+L)/3 to find the ratio? 2) You mentioned the correct ratio 'should be around a number' and that your estimate was close to the "correct value". So how did you determine what the correct value is in the first place? Did you use a more sophisticated series of steps? At any rate, thank you for the help, I really appreciate it. $\endgroup$ – Joe Jun 5 '15 at 19:07
  • $\begingroup$ 1) When the width of the rectangle is not too big, one can approximate the top/bottom of the circle by a quadratic polynomial, If you compute the average height of the circle within the rectangle, you will obtain the expression $(2d+L)/3$ as the width tends to $0$. 2) The correct value is computed by the function given in my answer. It covers all the possible ways ( there are tons of them) a circle can intersect with a rectangle and give you the actual area (up to machine accuracy). $\endgroup$ – achille hui Jun 5 '15 at 19:27
  • $\begingroup$ @achille hui: I see, thank you very much for the clarification! $\endgroup$ – Joe Jun 6 '15 at 5:01
0
$\begingroup$

This is not an answer but a long comment to present some code to compute the numbers.

For a more human readable description about the math behind the screen, please consult this answer instead. It is pointless to repeat the description here.


The numerical values of the two areas are

1.162312801155704 // ar_area(0.763,0,0,-0.4,-1,0.4,1)
                  // ~ 72.64455% of rectangle, 63.55125% of circle

1.59553612458975  // ar_area(1.050,0,0,-0.4,-1,0.4,1)
                  // ~ 99.72101% of rectangle, 46.06575% of circle

Computing using an user-defined function ar_area(r,xc,yc,x0,y0,x1,y1). The r is the radius of the circle, (xc,yc) its center. The (x0,y0) and (x1,y1) specify the lower-left and upper-right corner of the rectangles.

Following are the actual code in maxima I used to compute these numbers. I think it should be obvious how to translate it to other languages.

ar_h(u) := if( u >= 1 ) then 
               %pi 
           else if( u > -1 ) then 
               %pi - acos(u) + u*sqrt(1-u^2) 
           else 
                0;

ar_quad(u,v) := 
    if( u^2 + v^2 <= 1) then 
        (ar_h(u)+ar_h(v))/2 - %pi/4 + u*v 
    else if( u <= -1 or v <= -1) then
        0
    else if( u >= 1 and v >= 1 ) then 
        %pi
    else if( u >= 1 )then 
        ar_h(v)
    else if( v >= 1 ) then 
        ar_h(u)
    else if( u >= 0 and v >= 0 ) then
        ar_h(u)+ar_h(v) - %pi
    else if( u >= 0 and v <= 0 ) then 
        ar_h(v)
    else if( u <= 0 and v >= 0 ) then
        ar_h(u)
    else
        0;

ar_rect(x0,y0,x1,y1) := ar_quad(x0,y0) + ar_quad(x1,y1) - ar_quad(x0,y1) - ar_quad(x1,y0);
ar_area(r,xc,yc,x0,y0,x1,y1) := r^2 * ar_rect((x0-xc)/r,(y0-yc)/r,(x1-xc)/r,(y1-yc)/r);
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.