
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


 
'[RC] Circles of given radius through two points
for i = 1 to 5
    read x1, y1, x2, y2,r
    print i;") ";x1, y1, x2, y2,r
    call twoCircles x1, y1, x2, y2,r
next
end
 
'p1                p2           r
data 0.1234, 0.9876,    0.8765, 0.2345,    2.0
data 0.0000, 2.0000,    0.0000, 0.0000,    1.0
data 0.1234, 0.9876,    0.1234, 0.9876,    2.0
data 0.1234, 0.9876,    0.8765, 0.2345,    0.5
data 0.1234, 0.9876,    0.1234, 0.9876,    0.0
 
sub  twoCircles  x1, y1, x2, y2,r
 
    if x1=x2 and y1=y2 then '2.If the points are coincident
        if r=0 then ' unless r==0.0
            print "It will be a single point (";x1;",";y1;") of radius 0"
            exit sub
        else
            print "There are any number of circles via single point (";x1;",";y1;") of radius ";r
            exit sub
        end if
    end if
    r2 = sqr((x1-x2)^2+(y1-y2)^2)/2 'half distance between points
    if r<r2 then
        print "Points are too far apart (";2*r2;") - there are no circles of radius ";r
        exit sub
    end if
 
    'else, calculate two centers
    cx=(x1+x2)/2 'middle point
    cy=(y1+y2)/2
    'should move from middle point along perpendicular by dd2
    dd2=sqr(r^2-r2^2)   'perpendicular distance
    dx1=x2-cx   'vector to middle point
    dy1=y2-cy
    dx = 0-dy1/r2*dd2   'perpendicular:
    dy = dx1/r2*dd2     'rotate and scale
    print "(";cx+dy;",";cy+dx;")"   'two points, with (+)
    print "(";cx-dy;",";cy-dx;")"   'and (-)
 
end sub
 