필터 지우기
필터 지우기

create a 3D smoothing with csaps (or similar)

조회 수: 3 (최근 30일)
Alberto Acri
Alberto Acri 2024년 6월 7일
댓글: Mathieu NOE 2024년 6월 10일
To get a better set of nodes arranged in space as a ‘curve’, how can I improve this code? Could you suggest?
load curve_1
cc = curve_1; %or curve_2
x = cc(:,1);
y = cc(:,2);
z_min = min(cc(:,3));
z_max = max(cc(:,3));
z = z_min:0.1:z_max;
z = z';
% code
[pp,p] = csaps(z,[x;y]);
val = fnval(pp,z);
figure
plot3(x,y,z);
hold on
plot3(val(1,:),val(2,:),z,'r-')
grid on

채택된 답변

Mathieu NOE
Mathieu NOE 2024년 6월 7일
hello again !
as your post title is about smoothing, this is what I propose , based on the fex submission :
I attached the function in my answer if it makes your life simpler
now, maybe we should also create some intermediate points with interpolation (will be done just after this first answer)
so the starter :
load curve_1
cc = curve_1; %or curve_2
% load curve_2
% cc = curve_2; %or curve_2
x = cc(:,1);
y = cc(:,2);
z = cc(:,3);
% smoothing (if needed)
[zz,s,exitflag] = smoothn({x,y,z},1);
xn = zz{1};
yn = zz{2};
zn = zz{3};
plot3(x,y,z,'*');
hold on
plot3(xn,yn,zn);
  댓글 수: 4
Alberto Acri
Alberto Acri 2024년 6월 7일
Thank you @Mathieu NOE! You always surprise me!
Mathieu NOE
Mathieu NOE 2024년 6월 10일
My pleasure , and thanks again for accepting my answer
you can also reward other contributors by voting

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt J
Matt J 2024년 6월 7일
편집: Matt J 2024년 6월 7일
load curve_1
cc = curve_1; %or curve_2
x = cc(:,1);
y = cc(:,2);
z = cc(:,3);
t=linspace(0,1,height(cc));
tu=linspace(0,1,5*height(cc));
% code
[pp,p] = csaps(t,cc',0.995);
val = fnval(pp,tu);
figure
plot3(x,y,z,'o');
hold on
plot3(val(1,:),val(2,:),val(3,:),'r-')
grid on
  댓글 수: 1
Alberto Acri
Alberto Acri 2024년 6월 7일
Thank you! I accepted Mathieu's answer because it gave me more solutions. However, your answer is well accepted and I cannot accept both!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by