Re: Re: Re: Sphere through 4 points
- To: mathgroup at smc.vnet.net
- Subject: [mg85605] Re: [mg85539] Re: [mg85415] Re: [mg85401] Sphere through 4 points
- From: Daniel Lichtblau <danl at wolfram.com>
- Date: Thu, 14 Feb 2008 18:50:29 -0500 (EST)
- References: <200802090915.EAA16803@smc.vnet.net> <200802101010.FAA17539@smc.vnet.net> <200802130926.EAA22001@smc.vnet.net>
Daniel Lichtblau wrote:
> danl at wolfram.com wrote:
>
>>> Given 4 points in 3-space not lying in a plane, I want the
>>>center and radius of the incident sphere. I know about the elegant
>>>determinant solution (4 or 5 determinants, each 4x4, plus a few
>>>arithmetic operations) and I'm using that, but maybe someone has coded
>>>a faster version.
>>> Thanks for any information.
>>>
>>>Steve Gray
>>> [...]
>
> If raw speed is the issue, the variant below is faster.
>
> centerAndRadius2[data_] :=
> Module[{x, y, z, x0, y0, z0, rsqr, coeffs, rules, polys, lpolys, cen},
> rules = (Thread[{x, y, z} -> #1] &) /@ data;
> polys = x^2 - 2*x*x0 + y^2 - 2*y*y0 + z^2 - 2*z*z0 /. rules;
> lpolys = Rest[polys] - First[polys];
> coeffs = Normal[CoefficientArrays[lpolys, {x0, y0, z0}]];
> cen = LinearSolve[Last[coeffs], -First[coeffs]];
> {cen, Norm[cen - First[data]]}]
> [...]
Last time on this, I promise (well, I hope, anyway). Significantly
faster still, as well as working in arbitrary dimension, is:
centerAndRadius3[data_] :=
Module[{coeffs, rhs, soln, cen},
rhs = Map[#.#&,data];
coeffs = Map[Append[#,1]&,data];
soln = LinearSolve[coeffs,rhs];
cen = Most[soln];
{cen/2,Sqrt[Last[soln]+cen.cen/4]}
]
Daniel Lichtblau
Wolfram Research
- References:
- Sphere through 4 points
- From: Steve Gray <stevebg@roadrunner.com>
- Re: Sphere through 4 points
- From: danl@wolfram.com
- Re: Re: Sphere through 4 points
- From: Daniel Lichtblau <danl@wolfram.com>
- Sphere through 4 points