-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUntitled2.m
More file actions
37 lines (28 loc) · 863 Bytes
/
Untitled2.m
File metadata and controls
37 lines (28 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
% Define sphere parameters
radius = 2500; % mm
center = [0, 0, 0]; % mm
% Generate a part of the sphere
[X, Y] = meshgrid(linspace(-50, 50, 200)); % 200x200 grid from -50 to +50 in both X and Y
% Z coordinate calculation (based on equation of sphere)
R_square = radius^2 - (X - center(1)).^2 - (Y - center(2)).^2;
mask = R_square < 0;
R_square(mask) = 0;
Z = sqrt(R_square) + center(3);
Z = -(Z-2500);
% Add some random noise
%Z = Z + 0.01 * radius * randn(size(Z));
% Fit sphere to noisy data
[sphere_params, Z_fit] = fitSphere(X, Y, Z);
% Display the fitted sphere parameters
disp(sphere_params)
% Plot the original and fitted spheres
figure;
subplot(1, 2, 1);
imagesc(Z);colorbar;
%surf(X, Y, Z);
title('Original sphere with noise');
subplot(1, 2, 2);
%surf(X, Y, Z_fit);
imagesc(Z_fit);colorbar;
title('Fitted sphere');
imagesc(Z-Z_fit);colorbar;