identify a factor that links two equal matrices but positioned in different places on the same plane
Show older comments
I have two matrices ('RC_matlab' and 'RC_trasl') representing the same 2D coordinates of nodes on the same plane but at different plane positions.
I would like to identify the factor(s) that links the 'RC_trasl' matrix to the 'RC_matlab' matrix. That is, transform 'RC_trasl' as 'RC_matlab'.
I tried to determine the centroid (with a function found among the answers in the forum) of the two matrices in order to obtain dX and dY but this is not the correct way (apparently).
load RC_matlab.mat
load RC_trasl.mat
% polygoncentroid
[xc_matlab,yc_matlab] = polygoncentroid(RC_matlab(:,1),RC_matlab(:,2));
[xc_trasl,yc_trasl] = polygoncentroid(RC_trasl(:,1),RC_trasl(:,2));
dX = xc_matlab - xc_trasl;
dY = yc_matlab - yc_trasl;
% Plot
figure
plot(RC_matlab(:,1),RC_matlab(:,2),'b.','Markersize',30);
hold on
plot(xc_matlab,yc_matlab,'k*','Markersize',10);
hold off
axis equal
figure
plot(RC_trasl(:,1),RC_trasl(:,2),'r.','Markersize',30);
hold on
plot(xc_trasl,yc_trasl,'k*','Markersize',10);
hold off
axis equal
% New matrix
R_trasl_new = dX + RC_trasl(:,1);
C_trasl_new = dY + RC_trasl(:,2);
RC_trasl_new = [R_trasl_new , C_trasl_new];
% ===== function
function [xc,yc] = polygoncentroid(x,y)
xn = circshift(x,-1);
yn = circshift(y,-1);
A = x.*yn-xn.*y;
a = 3*sum(A);
xc = sum((x+xn).*A)/a;
yc = sum((y+yn).*A)/a;
end

Accepted Answer
More Answers (0)
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
