How to find the center of a circle and its radius in a 3D space given 3 points I'm working on writing a code in Octave (C++) for a helical spring. I need to figure out the center line of this spring in an effort to find any trends between different spring platforms as the geometry changes throughout the manufacturing processes.
I have a file with the center line of the wire, which is made up of 2000 or so points. Since I learned that you need 3 points to make a circle, I'm figuring i will be able to approach it that way (but haven't figured out how) so....
Given 3 points in 3 Dimensional space, how could I find the center and the radius of a circle in a code friendly manor.
Thanks


Let $A = (A_1, A_2, A_3)^T, \,\, B = (B_1, B_2, B_3)^T, \,\, C = (C_1, C_2, C_3)^T$ be the three points and $X = (x,y,z)^T$ be the center we are looking for. The point $X$ lies on the two planes passing through the midpoints of the segments $AB$ and $AC$. In fact $X$ also lies on the plane passing through the midpoint of segment $BC$, the three planes intersecting at the common line passing trough the center of the circle through $A, B, C$ and orthogonal to the plane defined by the three points. Also, $X$ lies on the plane through $A, B, C$. Thus, $X$is the unique intersection point of three planes, which constitute a system of three linear equations with three unknown variables $X = (x, y, z)^T$. Let us write the equations of the three planes:
\begin{align}
\overrightarrow{AB} \cdot \left(X - \frac{1}{2}(B+A)\right) &= 0\\
\overrightarrow{AC} \cdot \left(X - \frac{1}{2}(C+A)\right) &= 0\\
\Big(\overrightarrow{AB} \times \overrightarrow{AC}\Big) \cdot \left(X - A\right) &= 0
\end{align}
which turn into
\begin{align}
(B - A)^T  \left(X - \frac{1}{2}(B+A)\right) &= 0\\
(C - A)^T \left(X - \frac{1}{2}(C+A)\right) &= 0\\
\Big(\overrightarrow{AB} \times \overrightarrow{AC}\Big) \cdot \left(X - A\right) &= 0
\end{align}   
and as a linear system it looks like this:
\begin{align}
2(B - A)^T X &= (B - A)^T (B+A) \\
2 (C - A)^T X &= (C - A)^T (C+A) \\
\Big(\overrightarrow{AB} \times \overrightarrow{AC}\Big)^T X &= \Big(\overrightarrow{AB} \times \overrightarrow{AC}\Big)^T A
\end{align}
So if we put the vectors multiplying $X$ in as rows in the $3 \times 3$ matrix
\begin{align}
   M=
  \left[ {\begin{array}{c}
    2 (B - A)^T \\
    2 (C - A)^T \\
\Big(\overrightarrow{AB} \times \overrightarrow{AC}\Big)^T
   \end{array} } \right] = \left[ {\begin{array}{c c c}
    2 B_1 - 2 A_1 &   2 B_2 - 2 A_2 &  2 B_3 - 2 A_3\\
    2 C_1 - 2 A_1 &   2 C_2 - 2 A_2 &  2 C_3 - 2 A_3 \\
\Big(\overrightarrow{AB} \times \overrightarrow{AC}\Big)_1 & \Big(\overrightarrow{AB} \times \overrightarrow{AC}\Big)_2 & \Big(\overrightarrow{AB} \times \overrightarrow{AC}\Big)_3
   \end{array} } \right]
\end{align} 
and the numbers in the right hand side of the equations into a $3 \times 1$ row vector 
\begin{align}
   K&=
  \left[ {\begin{array}{c}
    (B - A)^T (B+A) \\
   (C - A)^T (C+A) \\
\Big(\overrightarrow{AB} \times \overrightarrow{AC}\Big)^T A
   \end{array} } \right] =  \left[ {\begin{array}{c}
    B^TB - A^TA\\
    C^TC - A^TA \\
\det \Big|\overrightarrow{AB} \,\,   \overrightarrow{AC} \,\, A \Big|
   \end{array} } \right] \\ &=  \left[ {\begin{array}{c}
    B_1^2 + B_2^2 + B_3^2 - A_1^2 - A_2^2 - A_3^2\\
    C_1^2 + C_2^2 + C_3^2 - A_1^2 - A_2^2 - A_3^2\\
\Big(\overrightarrow{AB} \times \overrightarrow{AC}\Big)_1 A_1 + \Big(\overrightarrow{AB} \times \overrightarrow{AC}\Big)_2 A_2 + \Big(\overrightarrow{AB} \times \overrightarrow{AC}\Big)_3
 A_3  \end{array} } \right]
\end{align}
Then the center of the circle is $$X = M^{-1}K$$ and the radius is $$R = \sqrt{(X - A)^T(X-A)} = \sqrt{(x-A_1)^2 + (y-A_2)^2 + (z-A_3)^2}$$
