File Exchange

image thumbnail

Fast Sphere Fit [Non Iterative]

version 1.0.0.0 (1.19 KB) by Sumith YD
Fits a 3D data set using geometric fit using an exact solution. Algorithm is fast and non iterative

3 Downloads

Updated 11 Jan 2016

View License

Fits 3D data using exact solution of a geometric fit. Please refer and cite "Sumith YD, "Fast Geometric Fit Algorithm for Sphere Using Exact Solution", 2015, arXiv:1506.02776" for the details of algorithm. This algorithm will work well for sphere, hemisphere and any portion of sphere.

Cite As

Sumith YD (2020). Fast Sphere Fit [Non Iterative] (https://www.mathworks.com/matlabcentral/fileexchange/51140-fast-sphere-fit-non-iterative), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (2)

Su Lyu

Sumith YD

% this file is to demonstrate sumith_fit.m
clc; clear;

Radius_orig = 9.02321; % Radius
XC = 2.3423; YC = 0.8764; ZC = 45.8785; % center coordinates
NoiseScale = 0.1; % add some noise
N = 100; % No: of points

%---dont modify anything below--------
Center_orig = [XC,YC,ZC];
x = zeros(N,1); y = zeros(N,1); z = zeros(N,1);

for i = 1:N
a = 0;
b = NoiseScale;
R = a + (b-a)*rand(1) + Radius_orig;
b = 2*pi;
theta = a + (b-a)*rand(1);
b = pi;
phi = a + (b-a)*rand(1);
x(i) = R*cos(theta)*sin(phi);
y(i) = R*sin(theta)*sin(phi);
z(i) = R*cos(phi);
end

x = x + Center_orig(1);y = y + Center_orig(2);z = z + Center_orig(3);

[xc,yc,zc,R] = sumith_fit(x,y,z);
ERROR = [XC-xc YC-yc ZC-zc Radius_orig-R];

figure(100);clf;
subplot(1,2,1);
plot3(x,y,z,'b.')
hold on;daspect([1,1,1]);
[xx,yy,zz] = sphere(30);
surf(xx*Radius_orig+XC, yy*Radius_orig+YC, zz*Radius_orig+ZC,'faceAlpha',0.4)
subplot(1,2,2);
plot3(x,y,z,'r.')
hold on;daspect([1,1,1]);
[xx,yy,zz] = sphere(30);
surf(xx*Radius_orig+XC, yy*Radius_orig+YC, zz*Radius_orig+ZC,'faceAlpha',0.3,'Facecolor','b')

Updates

1.0.0.0

updated with figure and sample script

MATLAB Release Compatibility
Created with R2015a
Compatible with any release
Platform Compatibility
Windows macOS Linux