1
$\begingroup$

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

3 Answers 3

2

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.

  • 0
    @J-M th$a$$n$ks, a$n$d thanks @Ross Millikan. Going to take to me a little while to grok this fully (I only have GCSE Maths, did physics instead after that!)2011-05-04
2

Call the center of the circle $(0,0)$ and the corner of the window, which the line passes through, $(a,b)$. Let $r$ be the radius of the circle. Then just multiply $a$ and $b$ by $\frac{r}{\sqrt{a^2+b^2}}$ and you have the coordinates on the circle.

0

here are some vb codes: 'circle: (x-a)^2+(y-b)^2=r^2 'line: y=mx+c

    m = (y2-y1)/(x2-x1)      c = (-m * x1 + y1)     aprim = (1 + m ^ 2)     bprim = 2 * m * (c - b) - 2 * a     cprim = a ^ 2 + (c - b) ^ 2 - r ^ 2      delta = bprim ^ 2 - 4 * aprim * cprim      x1_e_intersection = (-bprim + Math.Sqrt(delta)) / (2 * aprim)     y1_e_intersection = m * x1_s_intersection + c      x2_e_intersection = (-bprim - Math.Sqrt(delta)) / (2 * aprim)     y2_e_intersection = m * x2_s_intersection + c 
  • 2
    It might be better to present the solution *mathematically*, which will help the user code it in whichever language they deem appropriate.2013-04-26