This Java Script calculator finds the center and radius of a sphere given four points in Cartesian coordinates. To operate the calculator, enter the x-y-z coordinates for four points. Press the Compute button to obtain the solution. On invalid entries, a popup window will display an error message.
Return to Contents
The Java Script source code for this program can be viewed by using the View|Source command of your web browser.
You may use or modify this source code in any way you find useful, provided that you agree that the author has no warranty, obligations or liability. You must determine the suitability of this source code for your use.
Return to Contents
From analytic geometry, we know that there is a unique sphere that passes through four non-coplanar points if, and only if, they are not on the same plane. If they are on the same plane, either there are no spheres through the 4 points, or an infinite number of them if the 4 points are on a circle. Given 4 points,
{x1, y1, z1}, {x2, y2, z2}, {x3, y3, z3}, {x4, y4, z4}
how does one find the center and radius of a sphere exactly fitting those points?
They can be found by solving the following determinant equation:
x2 + y2 + z2 x y z 1 x12 + y12 + z12 x1 y1 z1 1 x22 + y22 + z22 x2 y2 z2 1 x32 + y32 + z32 x3 y3 z3 1 x42 + y42 + z42 x4 y4 z4 1 = 0
Evaluating the cofactors for the first row of the determinant can give us a solution. The determinant equation can be written as an equation of these cofactors:
This can be converted to the canonical form of the equation of a sphere:(x2 + y2 + z2)·M11 - x·M12 + y·M13 - z·M14 + M15 = 0
Completing the squares in x and y and z gives:x2 + y2 + z2 - (M12/M11)·x + (M13/M11)·y - (M14/M11)·z + M15/M11 = 0
x0 = 0.5·M12/M11 y0 = -0.5·M13/M11 z0 = 0.5·M14/M11 r02 = x02 + y02 + z02 - M15/M11
Note that there is no solution when M11 is equal to zero. In this case, the points are not on a sphere; they may all be on a plane or three points may be on a straight line.
Reference/u>
Elementary Mathematical Analysis
Return to Contents
AbCd Classics - free on-line books