Hello,
I have a 257x257 X,Y coordinate meshgrid that I need to rotate by 10 degrees (counterclockwise) and then move it along the x and y axis by adding a certain number to it (175.5362) in order to move it to the right location. This is what I have so far:
%Create the meshgrid
Xinit = 0:3125:800000;
Yinit = 0:3125:800000;
[Xq,Yq] = meshgrid(Xinit,Yinit);
When doing it in vector arrays I would do this:
theta=-10; %TO ROTATE CLOCKWISE BY X DEGREES
R=[cosd(theta) -sind(theta); sind(theta) cosd(theta)]; %CREATE THE MATRIX
rotXY=XY*R'; %MULTIPLY VECTORS BY THE ROT MATRIX
But this is a 257x257 matrix and I get this subsequently:
"Error using *
Inner matrix dimensions must agree."
I assume the second part of my question is just a matter of doing this:
%SHIFTING
Xq=Xq+175.5362;
Yq=Yq+175.5362;
Apologies if this is something very simple that I am missing again,
Thank you,
Pavlos

 採用された回答

Star Strider
Star Strider 2018 年 12 月 11 日

4 投票

One approach:
%Create the meshgrid
Xinit = 0:3125:800000;
Yinit = 0:3125:800000;
[Xq,Yq] = meshgrid(Xinit,Yinit);
Z = sin(Xq/40000) .* cos(Yq/40000); % ‘Z’ To Provide A Surface
figure
mesh(Xq,Yq,Z) % Original
grid on
XY = [Xq(:) Yq(:)]; % Create Matrix Of Vectors
theta=-10; %TO ROTATE CLOCKWISE BY X DEGREES
R=[cosd(theta) -sind(theta); sind(theta) cosd(theta)]; %CREATE THE MATRIX
rotXY=XY*R'; %MULTIPLY VECTORS BY THE ROT MATRIX
Xqr = reshape(rotXY(:,1), size(Xq,1), []);
Yqr = reshape(rotXY(:,2), size(Yq,1), []);
%SHIFTING
Xqrs = Xqr+175.5362;
Yqrs = Yqr+175.5362;
figure
mesh(Xqrs, Yqrs, Z) % Rotated & Shifted
grid on
See if that gives you the result you want.

4 件のコメント

Pavlos Farangitakis
Pavlos Farangitakis 2018 年 12 月 11 日
Hi,
It works absolutely fine! Thank you so much!
Pavlosrotgrid.JPG
Star Strider
Star Strider 2018 年 12 月 11 日
As always, my pleasure!
Scott Smith
Scott Smith 2022 年 10 月 3 日
This was very helpful! I was trying to follow what imrotate does to the x and y positions of an image that has x and y coordinate data (after upscaling the image), your answer was invaluble! Thank you!
Star Strider
Star Strider 2022 年 10 月 3 日
@Scott Smith — My pleasure!

サインインしてコメントする。

その他の回答 (1 件)

Matt J
Matt J 2018 年 12 月 11 日
編集済み: Matt J 2018 年 12 月 11 日

1 投票

theta=-10;
shift=[1,1]*175.5362;
R=[cosd(theta) -sind(theta); sind(theta) cosd(theta)];
szx=size(Xq);
XY=reshape( [Xq(:)*Yq(:)]*R.' + shift ,[sz,2]);
Xq=XY(:,:,1);
Yq=XY(:,:,2);

製品

リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by