function [xx,yy] = coordinate_transformation(x,y,A,B) % % The function [xx,yy] = coordinate_transformation(x,y,A,B) % transforms the coordinates (x,y) into (xx,yy), % translating the origin to the midpoint of AB, % and rotating along the direction of AB. % % ON ENTRY: % x x-coordinates; % y y-coordinates; % A x and y coordinates of start position; % B x and y coordinates of end position. % % ON RETURN: % xx x-coordinates after the transformation; % yy y-coordinates after the transformation; % midpoint = [ (A(1)+B(1))/2; (A(2)+B(2))/2 ]; % defines translation new_e1 = [ B(1) - midpoint(1); B(2) - midpoint(2) ]; new_e2 = [ -new_e1(2); new_e1(1) ]; rotation = [ new_e1 new_e2 ]; % new basis vectors define rotation xy = [x; y]; new_xy = rotation*xy; xx = new_xy(1,:) + midpoint(1); yy = new_xy(2,:) + midpoint(2);