create a 3D average curve from two 3D curves

4 ビュー (過去 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 Center および File ExchangeInterpolating Gridded Data についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by