[Math] Determine coordinate of intersection between a line and a circle

circles

I'm putting together a simple script in processing to visualise layout possibilities within the fluid environment of a web page.

I need some help calculating a point on a circle:

The circle is as big as it can be, limited by the width or the visible height of the web browser viewport, whichever is less. A line intersects the circle through its centre from one corner of the viewport/rectangle to the opposite corner.

My question is how can I calculate the x & y coordinates of the line's intersections on the circle's circumference?

[edit]
Forgot the link: http://hascanvas.com/tschichold

Best Answer

If the line and circle are specified in standard form $(x-a)^2+(y-b)^2=r^2$ and $y=mx+c$, you have two equations with two unknowns. Just plug the expression for $y$ from the line into the circle equation and you have a quadratic in $x$ which will give the (up to) two solutions. If your line and circle are specified differently, a similar technique will probably work, but you need to define how they are specified.