MCPcopy
hub / github.com/mne-tools/mne-python / _fit_sphere

Function _fit_sphere

mne/bem.py:1108–1118  ·  view source on GitHub ↗

Fit a sphere to an arbitrary set of points.

(points)

Source from the content-addressed store, hash-verified

1106
1107
1108def _fit_sphere(points):
1109 """Fit a sphere to an arbitrary set of points."""
1110 # linear least-squares sphere fit, see for example
1111 # https://stackoverflow.com/a/78909044
1112 # TODO: At some point we should maybe reject outliers first...
1113 A = np.c_[2 * points, np.ones((len(points), 1))]
1114 b = (points**2).sum(axis=1)
1115 x, _, _, _ = np.linalg.lstsq(A, b, rcond=1e-6)
1116 origin = x[:3]
1117 radius = np.sqrt(x[0] ** 2 + x[1] ** 2 + x[2] ** 2 + x[3])
1118 return radius, origin
1119
1120
1121def _check_origin(origin, info, coord_frame="head", disp=False):

Callers 6

test_read_raw_curry_rfDCFunction · 0.90
test_set_montage_mghFunction · 0.90
fitMethod · 0.85
_fit_sphere_to_headshapeFunction · 0.85
get_meg_helmet_surfFunction · 0.85
fit_dipoleFunction · 0.85

Calls 2

sqrtMethod · 0.80
sumMethod · 0.45

Tested by 2

test_read_raw_curry_rfDCFunction · 0.72
test_set_montage_mghFunction · 0.72