Rigidly translating and mirroring 2D coordinates

7 次查看(过去 30 天)
Hi! I would like to rigidly translate the coordinates of file curve2.txt so that its center of gravity coincides with the center of gravity of file curve1.txt. I tried to use the command "transltform2d" but it gives me an error.
curve1 = importdata("curve1.txt");
x_curve1 = sum(curve1(:,1))/length(curve1(:,1));
y_curve1 = sum(curve1(:,2))/length(curve1(:,2));
G_curve1 = [x_curve1, y_curve1];
curve2 = importdata("curve2.txt");
x_curve2 = sum(curve2(:,1))/length(curve2(:,1));
y_curve2 = sum(curve2(:,2))/length(curve2(:,2));
G_curve2 = [x_curve2, y_curve2];
tx = G_curve2 - G_curve1;
ty = G_curve2 - G_curve1;
tform = transltform2d(tx, ty);
Error using transltform2d
Expected input to be a scalar.
figure
plot(curve1(:,1),curve1(:,2),'k.', 'MarkerSize', 10)
hold on
plot(G_curve1(:,1),G_curve1(:,2),'k.', 'MarkerSize', 15)
plot(curve2(:,1),curve2(:,2),'r.', 'MarkerSize', 10)
plot(G_curve2(:,1),G_curve2(:,2),'r.', 'MarkerSize', 15)
hold off
grid off
axis equal
xlabel('x')
ylabel('y')
And then I should mirror, with respect to the Y axis, curve2.txt with respect to its center of gravity.

采纳的回答

Matt J
Matt J 2023-1-2
编辑:Matt J 2023-1-2
curve1 = importdata("curve1.txt"); curve1(:,3)=[];
curve2 = importdata("curve2.txt");
[ocurve1,ocurve2]=deal(curve1,curve2); %keep a copy of original curves
G=mean(curve1);
curve2=curve2-mean(curve2)+G; %make centroids the same
curve2(:,2)=curve2(:,2) + 2*(G(2)-curve2(:,2)); %reflect across G (y-direction)
tiledlayout(1,2)
nexttile
plot(ocurve1(:,1), ocurve1(:,2),'k.', 'MarkerSize', 10); hold on
plot(ocurve2(:,1), ocurve2(:,2),'r.', 'MarkerSize', 10); hold off
title Original
grid off
axis equal
xlabel('x')
ylabel('y')
nexttile
plot(curve1(:,1), curve1(:,2),'k.', 'MarkerSize', 10); hold on
plot(curve2(:,1), curve2(:,2),'r.', 'MarkerSize', 10); hold off
title Transformed
grid off
axis equal
xlabel('x')
ylabel('y')

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Smoothing 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by