
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


 
sub twoCircles (x1, y1, x2, y2, radio)
	if x1 = x2 and y1 = y2 then //Si los puntos coinciden
		if radio = 0 then       //a no ser que radio=0
			print "Los puntos son los mismos\n"
			return true
		else
			print "Hay cualquier numero de circulos a traves de un solo punto (", x1, ",", y1, ") de radio ", radio : print
			return true
		end if
	end if
	r2 = sqr((x1-x2)^2+(y1-y2)^2) / 2  //distancia media entre puntos
	if radio < r2 then
		print "Los puntos estan demasiado separados (", 2*r2, ") - no hay circulos de radio ", radio : print
		return true
	end if
 
	//si no, calcular dos centros
	cx = (x1+x2) / 2 //punto medio
	cy = (y1+y2) / 2
	//debe moverse desde el punto medio a lo largo de la perpendicular en dd2
	dd2 = sqr(radio^2 - r2^2)   //distancia perpendicular 
	dx1 = x2-cx           //vector al punto medio 
	dy1 = y2-cy
	dx = 0-dy1 / r2*dd2   //perpendicular:
	dy = dx1 / r2*dd2     //rotar y escalar 
	print " -> Circulo 1 (", cx+dy, ", ", cy+dx, ")"     //dos puntos, con (+)
	print " -> Circulo 2 (", cx-dy, ", ", cy-dx, ")\n"   //y (-)
end sub
 
for i = 1 to 5
	read x1, y1, x2, y2, radio
	print "Puntos ", "(", x1, ",", y1, "), (", x2, ",", y2, ")", ", Radio ", radio
	twoCircles (x1, y1, x2, y2, radio)
next
end
 
//p1                p2           radio
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
 
 