Circle containing three points, maybe all collinear

We all know that a circle is exactly defined by three distinct non-collinear points. But I need a way to solve the following problem (all in 2D):

Given three points, calculate a circle with all three points on its border if it exists, else calculate a circle with minimum radius which has two points on its border, and containing the third. The latter should happen when the three points are collinear.

I tried to draw all cases that can exist, but I do not come up with something elegant as a solution. Has somebody an easy way for it?

• "when at least two of the are collinear"? Two points are always collinear, three points are always coplanar. The exceptional case is when all three points are collinear (which includes as special case that some points may coincide) – Hagen von Eitzen Dec 2 '13 at 21:44
• I'm afraid the use of the word collinear in "two points of them are collinear to each other (two of them have same x- logic or y-coordinates)" is utter gibberish. – Will Jagy Dec 2 '13 at 21:44
• It is, and I apologize. Hope it is now better. – reindeer Dec 2 '13 at 21:47

• Better said: if it is not parallel to the $x$ axis, it is the one with median $y$ value. You can always use one median or the other to find the central point. – Ross Millikan Dec 2 '13 at 21:58