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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1707171/image.png)
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!