|
[Date Index]
[Thread Index]
[Author Index]
Re: Re: Re: Sphere through 4 points
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
Prev by Date:
Re: eliminate all the occurrences of "theta ->" and "lambda ->"
Next by Date:
Re: eliminate all the occurrences of "theta ->" and "lambda ->"
Previous by thread:
Re: Re: Sphere through 4 points
Next by thread:
Re: Sphere through 4 points
|