Determining intersecting points between square and circle I unfortunately have spent too much time trying to solve this question, and have turned to you for help. The corner of my square has intersected some circle, and I need to move it out. I only know one side of the intersecting corner, and I need to know the other side of the corner in order to push it out of the circle. Can you help me?

I know the side ("a"), I know the point ("P1"), and I need to find the length of side ("b").
I also know the center points and radius of the circle (cx, cy, rad)
So far, I can find the point ("P2") and ("P3) quite easily.
---P2(x, y) = P1(x, y - a)
Now, to find ("@")
---@ = atan2(P2y - cy, P2x - cx)
Now, we can find P3:
---P3x = cx + rad * cos(@)
---P3y = cy + rad * sin(@)
But even with all of this, I can't seem to find the length of ("b")! I would assume that if you knew the angle to the corner of the intersecting square's corner and the length of one side of that corner, you could find the other side!(confusing...) Can you? Please help!
 A: The simplest approach is to keep track of which coordinates we're at. We start at some point $P_1 = (-x,-y)$ on a circle of radius $r$. (I'm taking $x,y$ to both be positive.) . We move vertically a virtical distance $+a$, so that we land at point $P_2=(-x,-y+a)$. We then move a horizontal distance $-b$ to land at the point $(-x-b,-y+a)$ where the circle meets the square.
At this point, we don't know $b$. But we know that this point should lie on the circle. From the Pythagorean theorem we then have that the two points on the circle must satisfy $$ r^2 = x^2+ y^2=(-x-b)^2+(y-a)^2$$ If we multiply the last term out and cancel terms, we have 
$$ b^2+2b x +(a^2-2a y)=0$$ which is a quadratic equation in $b$. Solving this yields the final result
$$ \boxed{b = -x + \sqrt{x^2+2ay-a^2}}$$ As a check on this, note that if $a=0$ then one gets $b=0$ as it must (if the square has no length, you don't need to push it out). If $(x,y)=(0,a)$ (the bottom of the circle) then this gives $b=a$ (which again makes sense---the square occupies the entire quadrant of the circle.)
