Circle containing three points, maybe all collinear 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?
 A: I am going to assume here that "calculate the triangle" means to construct it.
This should be approached as if the three points make up a triangle; Then this becomes equivalent to trying to find the circumcircle of said triangle, which always exists except in the case where the triangle is degenerate (i.e. the three points are collinear).
What you are trying to construct is the point that is equidistant from the three given points. This point can then be used to construct the circle. This origin of the circle can be found by bisecting the sides of the triangle the three points make.
In the case of the three collinear points, one point is going to be on a line between the two other points. Drawing a circle with these two points on the diameter should provide you with the requested construction.
A: The first case is when these three points are not colinear. In this case you only have to draw two mediatrix of the triangle ABC. The intersection, D, is the center of a circle that will have the points A, B and C on its border.

The second case is when A, B and C are colinear. In this case, the circle will pass through the two extreme points A and B (with C between them). The center of the circle (point D) belongs to the mediatrix of AB. M is the middle point of AB. It means that AD is the hypotenuse of the triangle AMD. The minimum value of the radius (R) is when the points D and M coincide. It means that AB is the diameter of the circle.

A: If the points A, B and C are not collinear then the center of the circle we are being asked for would be the point which lies in the perpendicular bisectors of the sides of triangle ABC, however, it is not evident that this point exists. To prove that this point exists, we consider circles of radius 0 centered at A, B and C. As the centers of these 3 circles are not collinear, we can find the radical center, O. Due to power of a point theorem, this point must satisfy $OA^2 = OB^2 = OC^2$ which implies $OA=OB=OC$. Therefore, A, B and C lie on a circle centered at O. We have now proven that this point exists. To prove that it lies on the perpendicular bisectors of the sides of the triangle, we can notice that the radical axis of the circle centered at A and the circle centered at B would be the perpendicular bisector of AB, and so on. This concludes a construction for this point, the circumcentre. The circle centered at this point with radius AO would be the circumcircle which is the circle we are being asked for.
If the circle passes through 2 points, then the circle's center, O much lie on the perpendicular bisector of AB. For the radius to be minimum, OA must be minimized. This occurs when O lies on AB. Therefore, O must be the midpoint of AB and the required circle must have center O and radius OA.
https://www.maa.org/sites/default/files/pdf/ebooks/pdf/EGMO_chapter2.pdf - includes a proof that the circumcenter exists.
A: So, in 2D, you are looking to determine the circumcircle when the points are not aligned, and
the minimum bounding circlewhen instead the points are aligned.
Then given the three points $A=(A_x,A_y), B=(B_x,B_y), C=(C_x, C_y)$
the points will be aligned when the following two equivalent conditions are verified
$$
\begin{array}{*{20}c}
   {D = \left| {\begin{array}{*{20}c}
   {A_x } & {B_x } & {C_x }  \\
   {A_y } & {B_y } & {C_y }  \\
   1 & 1 & 1  \\
\end{array}} \right| = \left| {\begin{array}{*{20}c}
   {B_x  - A_x } & {C_x  - A_x }  \\
   {B_y  - A_y } & {C_y  - A_y }  \\
\end{array}} \right| = 0,} & {r = rank\left( {\begin{array}{*{20}c}
   {A_x } & {B_x } & {C_x }  \\
   {A_y } & {B_y } & {C_y }  \\
\end{array}} \right) < 2}  \\
\end{array}
$$

*

*case a) the points are not aligned
$$
D \ne 0,\quad r = 2
$$
The circumcenter has coordinates (re. to the abovelinked wikipedia article)
$$
\begin{array}{l}
 U_x  = \frac{1}{{2D}}\left( {\left( {A_x ^{\,2}  + A_y ^{\,2} } \right)\left( {B_y  - C_y } \right) +
 \left( {B_x ^{\,2}  + B_y ^{\,2} } \right)\left( {C_y  - A_y } \right) + \left( {C_x ^{\,2}  + C_y ^{\,2} } \right)\left( {A_y  - B_y } \right)} \right) \\ 
 U_y  =  - \frac{1}{{2D}}\left( {\left( {A_x ^{\,2}  + A_y ^{\,2} } \right)\left( {B_x  - C_x } \right) +
 \left( {B_x ^{\,2}  + B_y ^{\,2} } \right)\left( {C_x  - A_x } \right) + \left( {C_x ^{\,2}  + C_y ^{\,2} } \right)\left( {A_x  - B_x } \right)} \right) \\ 
 \end{array}
$$
and the radius clearly follows
$$
R = \sqrt {\left( {A_x  - U_x } \right)^{\,2}  + \left( {A_y  - U_y } \right)^{\,2} } 
$$

*

*case b) the points are aligned
$$
D = 0,\quad r < 2
$$
Then we can order the points according to their  position along the line, with respect to their $x$ coordinates,
or if they are all null, according to their $y$ coordinate.
We can accomodate the two cases, and also the possible case in which two or all the three points are coincident
by ordering on both coordinates.
Let's denote with $L$ and $H$ the two exteme points, we can put
$$
\begin{array}{l}
 L,H \in \left\{ {A,B,C} \right\}: \\ 
 L_x  = \min \left( {A_x ,B_x ,C_x } \right)\; \wedge \;H_x  = \max \left( {A_x ,B_x ,C_x } \right)\; \wedge  \\ 
 L_y  = \min \left( {A_y ,B_y ,C_y } \right) \wedge H_y  = \max \left( {A_y ,B_y ,C_y } \right) \\ 
 \end{array}
$$
Then clearly the center and the radius of the minimum bounding circle will be given by
$$
U_x  = \frac{{L_x  + H_x }}{2},\quad U_y  = \frac{{L_y  + H_y }}{2},\quad
 R = \frac{1}{2}\sqrt {\left( {H_x  - L_x } \right)^{\,2}  + \left( {H_y  - L_y } \right)^{\,2} } 
$$
