create a 3D average curve from two 3D curves
조회 수: 5 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Interpolating Gridded Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!