# 3D coordinates of circle center given three point on the circle.

Given the three coordinates $(x_1, y_1, z_1)$, $(x_2, y_2, z_2)$, $(x_3, y_3, z_3)$ defining a circle in 3D space, how to find the coordinates of the center of the circle $(x_0, y_0, z_0)$?

• @Behaviour I don't think this is an exact duplicate because the answers to the previous question only work in 2D. – user856 Dec 21 '14 at 2:36

There are plenty of online articles for the 2D case. A simple google search will show that this link provides a good explanation about how this is done in 2D. It also shows how to construct the circle center geometrically. So, what you need to do is

1) Find a plane from the 3 points and create a 2D coordinate system on that plane.
2) Convert all 3 points to that 2D coordinate system.
3) Find the circle center using the link above.
4) Convert the circle center (in 2D) back to 3D.

Edit 1: I added the steps for creating a local coordinate system (CS) on a plane defined by 3 points

1) Compute unit vector n1 from P1 and P2. Use this as the x-axis for the local CS.
2) Compute unit vector n2 from P1 and P3.
3) Use n1 x n2 (where 'x' means the cross product) as the z-axis of the local CS.
4) Use (n1 x n2) x n1 as the y-axis of the local CS.
5) Now, you have a local coordinate system, I hope that you know how to convert P1, P2 and P3 to this local CS. After the conversion, the new coordinates for these 3 points should all have their z values = 0.0. You can then use their (x, y) values to find the center of the circle.

If you have all 3 points collinear, you cannot create a local CS and you cannot find a circle from 3 collinear points either.

• Can you demonstrate how to convert from a 3D system to a 2D system? – Dylan Dec 21 '14 at 22:38
• I added more details to my answer. Hope it helps. – fang Dec 22 '14 at 4:16
• That's an interesting method. I still prefer my own method, which is exactly the same but without the change of coordinates. – Dylan Dec 22 '14 at 8:22
• @Dylan: Your method creates bisecting planes. My method converst 3D coordinates to 2D coordinates and create bisecting lines. So, yes they are theoretically the same. But working in 2D is easier to visualize the picture for most people. – fang Dec 22 '14 at 18:24

In fact, we have to solve the following system

$\cases{(x_0-x_1)^2+(y_0-y_1)^2+(z_0-z_1)^2=R^2\\ (x_0-x_2)^2+(y_0-y_2)^2+(z_0-z_2)^2=R^2\\ (x_0-x_3)^2+(y_0-y_3)^2+(z_0-z_3)^2=R^2\\ \left|\begin{array}{} x_0 & y_0 & z_0 & 1\\ x_1 & y_1 & z_1 & 1\\ x_2 & y_2 & z_2 & 1\\ x_3 & y_3 & z_3 & 1\\ \end{array}\right|=0}$

But I hope that somebody will write a nicer way.

Update. It seems the following.

Put $r_i=(x_i,y_i,z_i)$. Then the problem transformes to the following

$$\|r_1\|^2-2(r_0,r_1)= \|r_2\|^2-2(r_0,r_2)= \|r_3\|^2-2(r_0,r_3).$$

There exist real numbers $\mu_1, \mu_2, \mu_3$ such that $\mu_1+\mu_2+\mu_3=1$ and $r_0=\mu_1 r_1+\mu_2 r_2+\mu_3 r_3.$ We can find these numbers from a system of linear equations:

$$\mu_1+\mu_2+\mu_3=1$$

$$(1-2\mu_1) (r_1,r_1)-2\mu_2 (r_2,r_1)-2\mu_3 (r_3,r_1)=$$ $$-2\mu_1 (r_1,r_2)+(1-2\mu_2)(r_2,r_2)-2\mu_3 (r_2,r_3)=$$ $$-2\mu_1 (r_1,r_3)-2\mu_2(r_2,r_3)+(1-2\mu_3) (r_3,r_3).$$

• The problem is you don't know R at this moment. – fang Dec 21 '14 at 20:54
• @fang This is the smallest problem, :-) because we can easily eliminate $R$ and reduce the first three equations to two. – Alex Ravsky Dec 21 '14 at 20:59
• That is true. But it is not immediately clear to non-math-savy developers.:-) – fang Dec 21 '14 at 21:13
• @fang 4 equations in 4 unknowns - hard to be more clear. +1 – Mark McClure Dec 21 '14 at 21:27
• Not so clear for nonlinear equations. At least to me. :-) – fang Dec 21 '14 at 21:30

I think using a projection into 2D might be the easiest way to actually calculate. If the points are $A, B, C$ then find

\begin{align} \mathbf{u_1} & = B-A \\ \mathbf{w_1} &= (C-A) \times \mathbf{u_1} \\ \mathbf{u} & = \mathbf{u_1} / | \mathbf{u_1} | \\ \mathbf{w} & = \mathbf{w_1} / | \mathbf{w_1} | \\ \mathbf{v} & = \mathbf{w} \times \mathbf{u} \\ \end{align}

This gives three orthogonal unit vectors with $\mathbf{u}$ and $\mathbf{v}$ spanning the plane.

Get 2D coordinated by taking the dot products of $(B-A)$ and $(C-A)$ with $\mathbf{u}$ and $\mathbf{v}$. Let

\begin{align} b & = (b_x,0) = ( (B-A) \cdot \mathbf{u} , 0 ) \\ c &= (c_x,c_y) = ( (C-A) \cdot \mathbf{u}, (C-A)\cdot \mathbf{v} ) \\ \end{align}

We know the center must lie on the line $x= b_x/2$. Let this point be $(b_x/2,h)$. The distance from c must be the same as the distance from the origin $$(c_x-b_x/2)^2 + (c_y - h)^2 = (b_x/2)^2 + h^2$$ So $$h = \frac{(c_x-b_x/2)^2 + c_y^2 - (b_x/2)^2}{ 2 c_y }$$

The actual center can then be recovered by taking $A + (b_x/2)\mathbf{u} + h \mathbf{v}$.

This is a nice explicit calculation.

Another possible way.

The equation of a sphere in 3D space can be written as: $$x^2+y^2+z^2-2\alpha x -2\beta y -2\gamma z +d=0$$ where $$(\alpha,\beta,\gamma)$$ are the coordinate of the center $$O$$ and $$d=\alpha^2+\beta^2+\gamma^2-R^2$$

Given three points $$A=(x_A,y_A,z_A)$$, $$B=(x_B,y_B,z_B)$$, $$C=(x_C,y_C,z_C)$$, substituting in this equation we find three linear equations in $$\alpha$$,$$\beta$$, $$\gamma$$ and $$d$$ that we can write in the form: $$x_A\alpha+y_A\beta+z_A\gamma=\dfrac{d-|A|^2}{2}$$ $$x_B\alpha+y_B\beta+z_B\gamma=\dfrac{d-|B|^2}{2}$$ $$x_C\alpha+y_C\beta+z_C\gamma=\dfrac{d-|C|^2}{2}$$ where $$|A|^2=x_A^2+y_A^2+z_A^2$$, $$|B|^2=x_B^2+y_B^2+z_B^2$$ and $$|C|^2=x_C^2+y_C^2+z_C^2$$.

From these equations, we can find $$\alpha$$, $$\beta$$ and $$\gamma$$ as functions of $$d$$ and this corresponds to the fact that there are infinite spheres passing through the given points.

Now, the circle that we want is the maximum circle of the sphere that has the center on the plane that contain the three points and this menas that the three vectors $$OA$$,$$OB$$ and $$OC$$ are linearly dependent, so we must have:

$$\det \begin{bmatrix} \alpha-x_A &\beta-y_A &\gamma-z_A\\ \alpha-x_B &\beta-y_B &\gamma-z_B\\ \alpha-x_C &\beta-y_C &\gamma-z_C\\ \end{bmatrix}=0$$ with abit of calculus we can see that this reduces to: $$\alpha \det \begin{bmatrix} 1 &y_A &z_A\\ 1 &y_B &z_B\\ 1 &y_C &z_C\\ \end{bmatrix}+ \beta \det \begin{bmatrix} x_A &1 &z_A\\ x_B &1 &z_B\\ x_C &1 &z_C\\ \end{bmatrix}+ \gamma \det \begin{bmatrix} x_A &y_A &1\\ x_B &y_B &1\\ x_C &y_C &1\\ \end{bmatrix}- \det \begin{bmatrix} x_A &y_A &z_A\\ x_B &y_B &z_B\\ x_C &y_C &z_C\\ \end{bmatrix}=0$$

That is another linear equation from which we can find the coordinates of the center and the radius.

Let the known points be $A(x_1, y_1, z_1)$, $B(x_2, y_2, z_2)$ and $C(x_3, y_3, z_3)$. We want to find $I(x,y,z)$ so that $I$ is coplanar with $A,B,C$ and equidistant from $A,B,C$.

There is a geometric way to solve this. I assume you know how to find the equation of plane from a point and a normal vector? If not, look here.

Based on that, you can think of $I$ as the intersection of 3 planes:

1. Since $IA = IB$, $I$ must lie on the perpendicular bisecting plane of line segment $AB$. This is a plane that passes the midpoint $M\left(\frac{x_1+x_2}{2},\frac{y_1+y_2}{2},\frac{z_1+z_2}{2}\right)$ of $AB$, and is perpendicular to $AB$ (its normal vector is $\overrightarrow{AB}$).

2. Similar to plane 1 but with line segment $AC$ or $BC$ instead of $AB$

3. Finally, $I$ must lie on the plane containing the points $A,B,C$. Its normal vector is $\overrightarrow{AB} \times \overrightarrow{AC}$.

Once you have the equations for the above planes, you end up with a linear system of equations, which should be easy to solve. The solution to the system is the coordinate of $I$.

I think this is one of the simplest solution:

Given three points of a circle:
$p1~(p1_x, p1_y, p1_z)^T$
$p2~(p2_x, p2_y, p2_z)^T$
$p3~(p3_x, p3_y, p3_z)^T$

Estimate the circle center:
$p0~(p0_x, p0_y, p0_z)^T$

1. Estimate vectors $v1$ and $v2$:

$v1 = p2-p1 = (v1_x, v1_y, v1_z)^T$
$v2 = p3-p1 = (v2_x, v2_y, v2_z)^T$

1. Estimate dot products:

$v11 = v1^T·v1$
$v22 = v2^T·v2$
$v12 = v1^T·v2$

1. Estimate scalars $k_1$ and $k_2$:

$k_1 = b·v22·(v11 - v12)$

$k_2 = b·v11·(v22 - v12)$

$b = \frac{1}{2·(v11·v22-v12^2)}$

1. Estimate circle center p0:

$p0 = p1 + k_1·v1 + k_2·v2$

==>

$p0_x = p1_x + k_1·v1_x + k_2·v2_x$
$p0_y = p1_y + k_1·v1_y + k_2·v2_y$
$p0_z = p1_z + k_1·v1_z + k_2·v2_z$

Full derivation and code here: https://github.com/sergarrido/random/tree/master/circle3d

Let the three points in space are $$P_1$$, $$P_2$$ and $$P_3$$ and the center of the circle passing through them is $$C$$. In space, the geometric locus of the points equidistant to these three points forms a line and this line intersects $$P_1P_2P_3$$ plane at $$C$$.

Let $$S$$ be a point whose distance from the three points is $$R$$ (See Fig.1. Schematic). Then Cartesian coordinates of $$S$$ should satisfy the following three equations.

$$(S_x-P_{1x})^2+(S_y-P_{1y})^2+(S_z-P_{1z})^2 = R^2 \qquad\qquad\qquad (1) \\(S_x-P_{2x})^2+(S_y-P_{2y})^2+(S_z-P_{2z})^2 = R^2 \qquad\qquad\qquad (2) \\(S_x-P_{3x})^2+(S_y-P_{3y})^2+(S_z-P_{3z})^2 = R^2 \qquad\qquad\qquad (3)$$

Subtracting Eq.(1) from Eq.(2) and Eq.(3) and after simplifications,

$$D_{21y}S_y+D_{21z}S_z = F_{21}-D_{21x}S_x \qquad\qquad\qquad\qquad\qquad\quad\,\,\, (4) \\D_{31y}S_y+D_{31z}S_z = F_{31}-D_{31x}S_x \qquad\qquad\qquad\qquad\qquad\quad\,\,\, (5)$$

where

$$D_{21x} = P_{2x}-P_{1x} \qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\, (6) \\D_{21y} = P_{2y}-P_{1y} \qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\,\, (7) \\D_{21z} = P_{2z}-P_{1z} \qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\,\, (8) \\D_{31x} = P_{3x}-P_{1x} \qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\, (9) \\D_{31y} = P_{3y}-P_{1y} \qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\quad\,\,\,\,\,\, (10) \\D_{31z} = P_{3z}-P_{1z} \qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\, (11) \\F_{21} = \cfrac{1}{2}(P_{2x}^2+P_{2y}^2+P_{2z}^2-P_{1x}^2-P_{1y}^2-P_{1z}^2) \qquad\qquad\qquad\,\, (12) \\F_{31} = \cfrac{1}{2}(P_{3x}^2+P_{3y}^2+P_{3z}^2-P_{1x}^2-P_{1y}^2-P_{1z}^2) \qquad\qquad\qquad\,\, (13)$$

Eq.(4) and Eq.(5) are linear in terms of $$S_y$$ and $$S_z$$. Solving them yields,

$$S_y = \cfrac{F_{23z}+M_{23xz}S_x}{M_{23yz}} \qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\, (14) \\S_z = \cfrac{F_{23y}+M_{23xy}S_x}{M_{23yz}} \qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\, (15)$$

where

$$M_{23xy} = D_{21x}D_{31y}-D_{21y}D_{31x} \qquad\qquad\qquad\qquad\qquad\qquad\,\,\, (16) \\M_{23yz} = D_{21y}D_{31z}-D_{21z}D_{31y} \qquad\qquad\qquad\qquad\qquad\qquad\,\,\,\, (17) \\M_{23xz} = D_{21z}D_{31x}-D_{21x}D_{31z} \qquad\qquad\qquad\qquad\qquad\qquad\,\,\, (18) \\F_{23y} = F_{31}D_{21y}-F_{21}D_{31y} \qquad\qquad\qquad\qquad\qquad\qquad\qquad\,\, (19) \\F_{23z} = F_{21}D_{31z}-F_{31}D_{21z} \qquad\qquad\qquad\qquad\qquad\qquad\qquad\,\,\, (20)$$

Putting Eq.(14) and (15) into Eq.(1), it simplifies to the following equation form,

$$AA \cdot S_x^2+BB \cdot S_x+CC = 0 \qquad\qquad\qquad\qquad\qquad\qquad\,\,\,\,\,\, (21)$$

where

$$AA = 1+\cfrac{M_{23xy}^2+M_{23xz}^2}{M_{23yz}^2} \qquad\qquad\qquad\qquad\qquad\qquad\qquad\,\, (22) \\BB = 2 \cfrac{M_{23xz}F_{23z}}{M_{23yz}^2}+2\cfrac{M_{23xy}F_{23y}}{M_{23yz}^2} \\ \qquad -2P_{1x}-2P_{1y}\cfrac{M_{23xz}}{M_{23yz}}-2P_{1z}\cfrac{M_{23xy}}{M_{23yz}} \qquad\qquad\qquad\qquad\,\, (23)$$

Eq.(21) is quadratic in terms of $$S_x$$ and has two roots. So there are two points in space whose distance is $$R$$ from the points $$P_1$$, $$P_2$$ and $$P_3$$. Let these points be $$S_1$$ and $$S_2$$. The key observation here is that $$S_1$$ and $$S_2$$ are symmetric with respect to $$P_1P_2P_3$$ plane. Then, point $$C$$ is the midpoint of the line connecting $$S_1$$ and $$S_2$$. $$C_x$$ can be calculated with the following formula.

$$C_x = \cfrac{S_{1x}+S_{2x}}{2} = -\cfrac{BB}{2 \cdot AA} \\C_x = \cfrac{M_{23yz}(P_{1x}M_{23yz}+P_{1y}M_{23xz}+P_{1z}M_{23xy}) -M_{23xy}F_{23y}-M_{23xz}F_{23z}}{M_{23xy}^2+M_{23yz}^2+M_{23xz}^2} \qquad (24)$$

Similar to point $$S$$, point $$C$$ is equidistant to the three points. So $$C$$ also satisfies Eq.(14) and (15). Then,

$$C_y = \cfrac{F_{23z}+M_{23xz}C_x}{M_{23yz}} \qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\,\, (25) \\C_z = \cfrac{F_{23y}+M_{23xy}C_x}{M_{23yz}} \qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\,\, (26)$$

For coding purposes, find the full set of equations in text form below.

D21x = P2x-P1x
D21y = P2y-P1y
D21z = P2z-P1z
D31x = P3x-P1x
D31y = P3y-P1y
D31z = P3z-P1z
F21 = 1/2*(P2x**2+P2y**2+P2z**2-P1x**2-P1y**2-P1z**2)
F31 = 1/2*(P3x**2+P3y**2+P3z**2-P1x**2-P1y**2-P1z**2)
M23xy = D21x*D31y-D21y*D31x
M23yz = D21y*D31z-D21z*D31y
M23xz = D21z*D31x-D21x*D31z
F23y = F31*D21y-F21*D31y
F23z = F21*D31z-F31*D21z
Cx = (M23yz*(P1x*M23yz+P1y*M23xz+P1z*M23xy)-M23xy*F23y-M23xz*F23z)
/(M23xy**2+M23yz**2+M23xz**2)
Cy = (F23z+M23xz*Cx)/M23yz
Cz = (F23y+M23xy*Cx)/M23yz

Let's assume the circle is defined by the 3 points a, b and c, and that the center is denoted d. Following the hints in the answers above the coordinates of points a, b and c can be plugged into the equation of a circle. 3 circle equations and 4 unknowns (3 coordinates of the center c plus the radius) means that we have 2 remaining unknowns for one equation. This equation in fact represents the line passing through the center of the circle, having equal distance to points a, b and c. Intersecting this line with the plane spanned by a, b and c gives the point c. The rest is algebra, making use of some smart substitution of variables:

Cx = bx-ax
Cy = by-ay
Cz = bz-az
Bx = cx-ax
By = cy-ay
Bz = cz-az
B2 = ax**2-cx**2+ay**2-cy**2+az**2-cz**2
C2 = ax**2-bx**2+ay**2-by**2+az**2-bz**2

CByz = Cy*Bz-Cz*By
CBxz = Cx*Bz-Cz*Bx
CBxy = Cx*By-Cy*Bx
ZZ1 = -(Bz-Cz*Bx/Cx)/(By-Cy*Bx/Cx)
Z01 = -(B2-Bx/Cx*C2)/(2*(By-Cy*Bx/Cx))
ZZ2 = -(ZZ1*Cy+Cz)/Cx
Z02 = -(2*Z01*Cy+C2)/(2*Cx)

and finally the coordinates of the center:

dz = -((Z02-ax)*CByz-(Z01-ay)*CBxz-az*CBxy)/(ZZ2*CByz-ZZ1*CBxz+CBxy)
dx = ZZ2*dz + Z02
dy = ZZ1*dz + Z01
• Perhaps a little explanation of your logic would be helpful to the asker? – The Count Nov 11 '16 at 15:50
• An explanation would still be nice, even a year and a half later. People are still finding this post when looking for how to fit a circle through three points in 3D =) – Mike 'Pomax' Kamermans Jul 7 '18 at 17:41

I know this is late but hopefully this can help someone else. I will write it down in steps without explaining too much as I believe the steps are simple enough. Let the points be P1 P2 and P3.

1. Calculate the plane containing the three points.
2. Calculate the perpendicular bisectors of the line segments [P1 P2] and [P1 P3] , or any other combination that you want, such that this perpendicular bisector also lies in the plane containing P1,P2 and P3.
3. The intersection of these 2 perpendicular bisectors should be the center of the cricle.

I can elaborate more if anyone wishes so :-)

• this answer just describes, in far less detail, the exact answer @fang already gave in 2014 – Mike 'Pomax' Kamermans Jul 7 '18 at 17:38