
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


INCLUDE "H6:REALMATH.ACT"
 
PROC Circles(CHAR ARRAY sx1,sy1,sx2,sy2,sr)
  REAL x1,y1,x2,y2,r,x,y,bx,by,pb,cb,xx,yy
  REAL two,tmp1,tmp2,tmp3
 
  ValR(sx1,x1) ValR(sy1,y1)
  ValR(sx2,x2) ValR(sy2,y2)
  ValR(sr,r)   IntToReal(2,two)
 
  Print("p1=(") PrintR(x1) Put(32)
  PrintR(y1) Print(") p2=(")
  PrintR(x2) Put(32) PrintR(y2)
  Print(") r=") PrintR(r) Print(" -> ")
 
  IF RealEqual(r,rzero) THEN
    PrintE("Radius is zero, no circles") PutE()
    RETURN
  FI
 
  RealSub(x2,x1,tmp1) ;tmp1=x2-x1
  RealDiv(tmp1,two,x) ;x=(x2-x1)/2
 
  RealSub(y2,y1,tmp1) ;tmp1=y2-y1
  RealDiv(tmp1,two,y) ;y=(y2-y1)/2
 
  RealAdd(x1,x,bx) ;bx=x1+x
  RealAdd(y1,y,by) ;bx=x1+x
 
  RealMult(x,x,tmp1)      ;tmp1=x^2
  RealMult(y,y,tmp2)      ;tmp2=y^2
  RealAdd(tmp1,tmp2,tmp3) ;tmp3=x^2+y^2
  Sqrt(tmp3,pb)           ;pb=sqrt(x^2+y^2)
 
  IF RealEqual(pb,rzero) THEN
    PrintE("Infinite circles")
  ELSEIF RealGreater(pb,r) THEN
    PrintE("Points are too far, no circles")
  ELSE
    RealMult(r,r,tmp1)      ;tmp1=r^2
    RealMult(pb,pb,tmp2)    ;tmp2=pb^2
    RealSub(tmp1,tmp2,tmp3) ;tmp3=r^2-pb^2
    Sqrt(tmp3,cb)           ;cb=sqrt(r^2-pb^2)
 
    RealMult(y,cb,tmp1) ;tmp1=y*cb
    RealDiv(tmp1,pb,xx) ;xx=y*cb/pb
 
    RealMult(x,cb,tmp1) ;tmp1=x*cb
    RealDiv(tmp1,pb,yy) ;yy=x*cb/pb
 
    RealSub(bx,xx,tmp1) ;tmp1=bx-xx
    Print("c1=(") PrintR(tmp1) Put(32)
 
    RealAdd(by,yy,tmp1) ;tmp1=by+yy
    PrintR(tmp1) Print(") c2=(")
 
    RealAdd(bx,xx,tmp1) ;tmp1=bx+xx
    PrintR(tmp1) Put(32)
 
    RealSub(by,yy,tmp1) ;tmp1=by-yy
    PrintR(tmp1) PrintE(")")
  FI
  PutE()
RETURN
 
PROC Main()
  Put(125) PutE() ;clear the screen
  MathInit()
  Circles("0.1234","0.9876","0.8765","0.2345","2.0")
  Circles("0.0000","2.0000","0.0000","0.0000","1.0")
  Circles("0.1234","0.9876","0.1234","0.9876","2.0")
  Circles("0.1234","0.9876","0.8765","0.2345","0.5")
  Circles("0.1234","0.9876","0.1234","0.9876","0.0")
RETURN