
Given two points on a plane and a radius, usually two circles of given radius can be drawn through the points.

Exceptions

 r==0.0 should be treated as never describing circles (except in the case where the points are coincident).
 If the points are coincident then an infinite number of circles with the point on their circumference can be drawn, unless r==0.0 as well which then collapses the circles to a point.
 If the points form a diameter then return two identical circles or return a single circle, according to which is the most natural mechanism for the implementation language.
 If the points are too far apart then no circles can be drawn.


Task detail

 Write a function/subroutine/method/... that takes two points and a radius and returns the two circles through those points, or some indication of special cases where two, possibly equal, circles cannot be returned.
 Show here the output for the following inputs:
      p1                p2           r
0.1234, 0.9876    0.8765, 0.2345    2.0
0.0000, 2.0000    0.0000, 0.0000    1.0
0.1234, 0.9876    0.1234, 0.9876    2.0
0.1234, 0.9876    0.8765, 0.2345    0.5
0.1234, 0.9876    0.1234, 0.9876    0.0



Related task

   Total circles area.


See also

   Finding the Center of a Circle from 2 Points and Radius from Math forum @ Drexel


with javascript_semantics
constant tests = {{0.1234, 0.9876, 0.8765, 0.2345, 2.0},
                  {0.0000, 2.0000, 0.0000, 0.0000, 1.0},
                  {0.1234, 0.9876, 0.1234, 0.9876, 2.0},
                  {0.1234, 0.9876, 0.8765, 0.2345, 0.5},
                  {0.1234, 0.9876, 0.1234, 0.9876, 0.0}}
for i=1 to length(tests) do
    atom {x1,y1,x2,y2,r} = tests[i],
         xd = x2-x1, yd = y1-y2,
         s2 = xd*xd+yd*yd, sep = sqrt(s2),
         xh = (x1+x2)/2, yh = (y1+y2)/2
    string txt
    if sep=0 then
        txt = "same points/"&iff(r=0?"radius is zero":"infinite solutions")
    elsif sep=2*r then
        txt = sprintf("opposite ends of diameter with centre {%.4f,%.4f}",{xh,yh})
    elsif sep>2*r then
        txt = sprintf("too far apart (%.4f > %.4f)",{sep,2*r})
    else
        atom md = sqrt(r*r-s2/4), xs = md*xd/sep, ys = md*yd/sep
        txt = sprintf("{%.4f,%.4f} and {%.4f,%.4f}",{xh+ys,yh+xs,xh-ys,yh-xs})
    end if
    printf(1,"points {%.4f,%.4f}, {%.4f,%.4f} with radius %.1f ==> %s\n",{x1,y1,x2,y2,r,txt})
end for
