필터 지우기
필터 지우기

create a 3D average curve from two 3D curves

조회 수: 5 (최근 30일)
Alberto Acri
Alberto Acri 2024년 5월 31일
댓글: Mathieu NOE 2024년 5월 31일
I have curves M1 and M2 composed of x nodes in space.
Is it possible to create an average curve (up to a specific height, from bottom to top - red curve) as in the figure?
load M1_and_M2.mat
figure
plot3(M1(:,1),M1(:,2),M1(:,3),'mo','Markersize',4);
hold on
plot3(M2(:,1),M2(:,2),M2(:,3),'go','Markersize',4);
hold off
axis equal
xlabel('x')
ylabel('y')
zlabel('z')
grid off

채택된 답변

Mathieu NOE
Mathieu NOE 2024년 5월 31일
hello Alberto and welcome back
we need to sort and remove duplictes in your data before creating a common z vector, then interpolate both x,y datas on this new reference
then as we have now a common z axis (zm indeed) , we can sum the x and y datas
the new curve is in black
load M1_and_M2.mat
x1 = M1(:,1);
y1 = M1(:,2);
z1 = M1(:,3);
x2 = M2(:,1);
y2 = M2(:,2);
z2 = M2(:,3);
% remove duplicates and sort z data
[z1,ia,ic] = unique(z1);
x1 = x1(ia);
y1 = y1(ia);
[z2,ia,ic] = unique(z2);
x2 = x2(ia);
y2 = y2(ia);
% ctreate new common z array
zmin = max([min(z1);min(z2)]);
zmax = min([max(z1);max(z2)]);
zm = linspace(zmin,zmax,200); % common z value
% interpolate x,y data
x1i = interp1(z1,x1,zm');
y1i = interp1(z1,y1,zm');
x2i = interp1(z2,x2,zm');
y2i = interp1(z2,y2,zm');
% mean curve
xm = (x1i+x2i)/2;
ym = (y1i+y2i)/2;
figure
plot3(x1,y1,z1,'mo','Markersize',4);
hold on
plot3(x2,y2,z2,'go','Markersize',4);
plot3(xm,ym,zm,'k*','Markersize',4);
hold off
axis equal
xlabel('x')
ylabel('y')
zlabel('z')
grid off
  댓글 수: 2
Alberto Acri
Alberto Acri 2024년 5월 31일
Thanks! :)
Mathieu NOE
Mathieu NOE 2024년 5월 31일
as always, my pleasure !

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by