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);
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.
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Smoothing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!