Auto-completion and smoothing of incomplete 3D ring

3 views (last 30 days)
hello, here I got an incomplete 3D ring, and I want to interpolate it to a complete and smoothing 3D ring.
Could anyone help me, thanks very much!

Accepted Answer

Mathieu NOE
Mathieu NOE on 27 Feb 2024
hello
maybe this ?
load('3D ring.mat')
x = data.Points(:,1);
y = data.Points(:,2);
z = data.Points(:,3);
%% method 1
centroid_x = mean(x);
centroid_y = mean(y);
centroid_z = mean(z);
[theta,r,zz] = cart2pol(x-centroid_x,y-centroid_y,z-centroid_z);
% sort theta in ascending order
[theta,ind] = sort(theta);
r = r(ind);
zz = zz(ind);
% remove duplicates
[theta,IA,IC] = unique(theta);
r = r(IA);
zz = zz(IA);
theta_new = linspace(min(theta),max(theta),100);
r_new = interp1(theta,r,theta_new);
z_new = interp1(theta,zz,theta_new);
% smoothing
% add some overlap (pre and post data at closure point)
N = 10;
r_tmp = [r_new(end-N:end) r_new r_new(1:1+N)];
rs = smoothdata(r_tmp,'gaussian',N);
zz_tmp = [z_new(end-N:end) z_new z_new(1:1+N)];
zs = smoothdata(zz_tmp,'gaussian',N);
% remove extra pre and post data
rs(1:1+N) = [];
rs(end-N:end) = [];
zs(1:1+N) = [];
zs(end-N:end) = [];
% convert to cartesian
[xn,yn,zn] = pol2cart(theta_new,rs,zs);
% add back centroid info
xn = xn + centroid_x;
yn = yn + centroid_y;
zn = zn + centroid_z;
%% XY plot
figure(1),
plot3(x,y,z,'g.');
hold on
plot3(xn,yn,zn,'r','linewidth',5);
hold off
legend('raw','smoothed');
  3 Comments
Tingting
Tingting on 14 Mar 2024
Thanks for your patient answer! It really helps me.

Sign in to comment.

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!