FIT A SPHERE THROUGH DATA POINTS

Engineering Fundamentals

INTRODUCTION

Method to derive a best fit a sphere through number (≥ 4) XYZ data points, where the summed square errors of the data points in relation to the fit-sphere in the direction perpendicular to the surface.

Was this helpful? Please share this with your colleagues and friends:

Share
Equation of a plane

z(x,y)=\sqrt{(R^2-(x-x_c)^2-(y-y_c)^2)}+z_c
(x_c,y_c,z_c) is the location of the center of the sphere, and R is the radius of the sphere.

Data points

\left[\begin{matrix}x_1&y_1&z_1\\x_2&y_2&z_2\\x_3&y_3&z_3\\x_3&y_4&z_4\\{\Box}&{\vdots}&{\Box}\\x_n&y_n&z_n\end{matrix}\right]

Center location and radius of fitted sphere

A = 2\ {\cdot} \left[\begin{matrix} \sum _{i=1}^{i=n}\frac{x_i{\cdot}(x_i-\bar {x}}{n}& \sum _{i=1}^{i=n}\frac{x_i{\cdot}(y_i-\bar {y})}{n}& \sum _{i=1}^{i=n}\frac{x_i{\cdot}(z_i-\bar {z})}{n}\\ \sum _{i=1}^{i=n}\frac{y_i{\cdot}(x_i-\bar {x})}{n}& \sum _{i=1}^{i=n}\frac{y_i{\cdot}(y_i-\bar {y})}{n}& \sum _{i=1}^{i=n}\frac{y_i{\cdot}(z_i-\bar {z})}{n}\\ \sum _{i=1}^{i=n}\frac{z_i{\cdot}(x_i-\bar {x})}{n}& \sum _{i=1}^{i=n}\frac{z_i{\cdot}(y_i-\bar {y})}{n}& \sum _{i=1}^{i=n}\frac{z_i{\cdot}(z_i-\bar {z})}{n}\end{matrix}\right]

B=\left[\begin{matrix} \sum _{i=1}^n\frac{(x_i^2+y_i^2+z_i^2){\cdot}(x_i-\bar {x})}{n}\\ \sum _{i=1}^n\frac{(x_i^2+y_i^2+z_i^2){\cdot}(y_i-\bar {y})}{n}\\ \sum _{i=1}^n\frac{(x_i^2+y_i^2+z_i^2){\cdot}(z_i-\bar {z})}{n} \end{matrix}\right]

\bar {x}=\frac {1}{n} \sum _{i=1}^{i=n}x_i,

\bar {y}=\frac {1}{n} \sum _{i=1}^{i=n}y_i,

\bar {z}=\frac {1}{n}\sum _{i=1}^{i=n}z_i

\left[\begin{matrix}x_c\\y_c\\z_c\end{matrix}\right]=(A^T\ {\cdot}A)^{-1}\ {\cdot}\ A^T\ {\cdot}\ B

R=\sqrt{\frac{\sum _{i=1}^{i=n}((x_i-x_c)^2+(y_i-y_c)^2+(z_i-z_c)^2)}{n}}

Fit quality – Coefficient of determination = R2

R^2=1-\frac {\sum _{i=1}^{i=n}(z_i-z(x_i,y_i))^2} {\sum _{i=1}^{i=n}(z_i-\frac {1}{n}\sum _{i=1}^nz_i)^2}

A value of R^2 which is close to 1 indicates a good fit quality.

Fit sphere through data points

This page uses QuickLaTeX to display formulas.