       Re: Sphere formula

• To: mathgroup at smc.vnet.net
• Subject: [mg109476] Re: Sphere formula
• From: Ray Koopman <koopman at sfu.ca>
• Date: Wed, 28 Apr 2010 07:00:29 -0400 (EDT)
• References: <hr65rj\$jq6\$1@smc.vnet.net>

```On Apr 27, 1:05 am, "S. B. Gray" <stev... at ROADRUNNER.COM> wrote:
> 1. The center of a sphere through 4 points has a very nice determinant
> form. (http://mathworld.wolfram.com/Sphere.html) What I want is a nice
> formula for the center of a sphere through 3 points, where the center is
> in the plane of the three points. I have a formula but it's a horrible
> mess of hundreds of lines, even after FullSimplify.
>
> 2. (Unlikely) Is there a way to get Mathematica to put a long formula into a
> matrix/determinant form if there is a nice one?
>
> Any tips will be appreciated.
>
> Steve Gray

If x, Dimensions[x] = {n,m}, contains the coordinates of n points
in m dimensions, findcenter[x] will return the coordinates of the
center of the best-fitting hypersphere (minimum variance of the
distances of the points from the center).

findcenter[x_] := Block[{m = Mean@x},
Total[#^2].PseudoInverse[#] & [Transpose@x - m]/2 + m]

Here is an example with 3 points in 3 dimensions.

r = (* radius * random rotation *)
5 Orthogonalize@RandomReal[NormalDistribution[0,1],{3,3}]

{{-4.15687, -2.74134, -0.453282},
{1.72438, -1.9056, -4.28897},
{2.17875, -3.72206, 2.52968}}

c = {1, 2, 3}; (* center *)

x = (* coordinates of 3 random points with known center & radius *)
Table[{Cos@#, Sin@#, 0}& @ RandomReal[{-Pi,Pi}].r + c, {3}]

{{0.018473, -1.1359, -0.768653},
{2.51514, 5.25315,  6.48158},
{0.818313, -0.881007, -1.0825}}

findcenter[x]                   (* find the center and the   *)
Sqrt@Total[(Transpose@x - %)^2] (* distances from the center *)

{1., 2., 3.}
{5., 5., 5.}

```

• Prev by Date: NDSolve: ..numerically ill-conditioned...
• Next by Date: Re: Pade Approximation (further generalizations?---feature request)
• Previous by thread: Re: Sphere formula
• Next by thread: Re: Sphere formula