필터 지우기
필터 지우기

Rigidly translating and mirroring 2D coordinates

조회 수: 4 (최근 30일)
Alberto Acri
Alberto Acri 2023년 1월 2일
편집: Matt J 2023년 1월 2일
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에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by