Multiply Rotation Matrix to a Large Set of Data
12 ビュー (過去 30 日間)
古いコメントを表示
Hi
I have a set of data that I need to apply a rotation matrix to. I have the normalised data and created a rotation matrix, however the issue I’m having is multiplying the rotation matrix to the data as they are drastically different sizes.
For context I am looking to rotate the data about a specified point and angle (I have been able to extract the point of rotate and angle of rotation) and have used the below code to shift the existing data to the point of rotation and to create the rotation matrix.
The rotation matrix I get is a 2x2 array, meanwhile I’m trying to then multiple this by the original data to rotate it which is a 6135 x 2 array. I have attached the data for reference. Person1XY has individual data points that has been shifted to the centre of rotation with column 1 being X and column 2 being Y.
% First find the slope of the line and angle of rotation/slope (theta)
Slope = (PlotConXY(2,2)-PlotConXY(1,2))./(PlotConXY(2,1)-PlotConXY(1,1));
AngleSlope = atand(Slope);
% Now reposition data to centre point for rotation and create the rotation matrix
X_Int = XYIntercept(1,1);
Y_Int = XYIntercept(1,2);
theta = AngleSlope;
CentreXY1 = repmat([X_Int;Y_Int],1,length(DataConXY));
CentreXY = transpose(CentreXY1);
RotationMatrix = [cos(theta) -sin(theta); sin(theta) cos(theta)]; %Data attached
%% Create arrays for each individual person (7 total but can add more)
P1 = [DataConXY(:,1), DataConXY(:,2)];
% Now shift the data to centre of rotation for each person
P1Shift = P1 - CentreXY; % saved data file as Person1XY
% Now apply the rotatioon matrix to each person
P1Rotate = RotationMatrix .* P1Shift; % This did not work, recieved error message
% Create new rotated data back to origin
P1OG = P1Rotate + CentreXY;
I have tried using bsxfun to multiple the Rotation Matrix and Person1XY data but had no luck.
Does anyone know how I can multiply this data together when they are of different sizes?
2 件のコメント
David Goodmanson
2022 年 10 月 3 日
編集済み: David Goodmanson
2022 年 10 月 3 日
Hi Tanya, the general idea if you want to do a coordinate rotation of all of the rows of a 6135x2 matrix M, say, is Mnew = M*R, i.e. right multiplication by R. Since you multply by R on the right, the sign of the rotation angle theta may well have to have a change of sign compared to what you construct initially.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!