# Portion of square area within a circle

I have a circle of center $(x_c, y_c)$ and radius $r$, and a square of center $(x_s, y_s)$ and width $w$:

The square will always be oriented such that its sides are parallel to the x,y axis of a system such as the one shown in the figure, centered at $(x_c, y_c)$.

How can I obtain the area of the square that is within the limit defined by the radius of the circle (ie: the red portion)? This portion will be 1 if the entire square is inside the radius $r$, and zero if the entire square is outside.

• What orientation is the square to the circle? The will also be a required piece of information. Or equivalently we need one (just one) of the corners. – fleablood Sep 5 '17 at 15:42
• Sorry, I forgot to mention that. I'll add it to my question. – Gabriel Sep 5 '17 at 15:42
• Do you need an exact or approximate evaluation ? – user65203 Sep 5 '17 at 15:47
• @fleablood: assuming an axis-aligned square causes no loss of generality. – user65203 Sep 5 '17 at 15:48
• There are tons of special case for the value. see this answer for details. – achille hui Sep 5 '17 at 16:14

Hint:

You can derive the area inside the square from the area inside an infinite "corner" ($x\ge x_c,y\ge y_c$), by summing algebraically contributions from the four vertices of the square.

The area covered by a corner is obtained by integrating $\sqrt{1-x^2}-y_c$ from $x_c$ to the solution of $\sqrt{1-x^2}-y_c=0$ (WLOG, $r=1$).

And

$$\int\sqrt{1-x^2}dx=\frac{x\sqrt{1-x^2}}2-\frac{\arcsin x}2.$$

You need to discuss a little further for the four quadrants.

• I'm sorry, I don't quite understand this answer. What is an infinite "corner"? Where are $x_s, y_s$? What do you mean buy "discuss a little further for the four quadrants"? – Gabriel Sep 5 '17 at 16:09
• @Gabriel: hope the figure will make it a little clearer. A corner is formed by two perpendicular half-lines. – user65203 Sep 5 '17 at 16:09
• Sorry, still lost :( – Gabriel Sep 5 '17 at 16:11
• @Gabriel: sorry, I have no more time now. – user65203 Sep 5 '17 at 16:12
• No worries I'll look into it with more detail. Thank you for your answer! – Gabriel Sep 5 '17 at 16:13