Borrar filtros
Borrar filtros

Auto-completion and smoothing of incomplete 3D ring

1 visualización (últimos 30 días)
Tingting
Tingting el 21 de Feb. de 2024
Comentada: Mathieu NOE el 14 de Mzo. de 2024
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!

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 27 de Feb. de 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 comentarios
Tingting
Tingting el 14 de Mzo. de 2024
Thanks for your patient answer! It really helps me.
Mathieu NOE
Mathieu NOE el 14 de Mzo. de 2024
My pleasure!!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by