Re: Sphere through 4 points
- To: mathgroup at smc.vnet.net
- Subject: [mg85415] Re: [mg85401] Sphere through 4 points
- From: danl at wolfram.com
- Date: Sun, 10 Feb 2008 05:10:05 -0500 (EST)
- References: <200802090915.EAA16803@smc.vnet.net>
> 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 > Not sure if this is faster, but could do: centerAndRadius[data_] := Module[ {x, y, z, vars, rsq, coeffs, polys, lpolys, cen}, vars = {x, y, z}; polys = (vars.vars - rsq) /. Thread[vars -> (vars - Transpose[data])]; lpolys = Expand[Rest[polys] - First[polys]]; coeffs = CoefficientArrays[lpolys, vars]; cen = LinearSolve[Last[coeffs], First[coeffs]]; {cen, Sqrt[rsq]} /. First[Solve[(First[polys] /. Thread[vars -> cen]) == 0]] ] In[147]:= SeedRandom[1111]; data = RandomReal[{-5, 5}, {4, 3}]; centerAndRadius[data] Out[149]= {{-2.25666, -13.9661, 7.0018}, 15.1774} Can do around 200+ per second, on my laptop. In[150]:= Timing[Do[centerAndRadius[data], {100}]] Out[150]= {0.421, Null} Daniel Lichtblau Wolfram Research
- Follow-Ups:
- Re: Re: Sphere through 4 points
- From: Daniel Lichtblau <danl@wolfram.com>
- Re: Re: Sphere through 4 points
- References:
- Sphere through 4 points
- From: Steve Gray <stevebg@roadrunner.com>
- Sphere through 4 points