Rotate matrices about a point
49 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
I am trying to rotate the matrix 'V' about the (X,Y) coordinate (-2.117,-8.053) 20 degrees clockwise. I plot the unrotated pcolor graph below. The white NaN data at the center of the graph (see picture) should be about parallel to the black line I plotted. I am aware that some corner data might be cut off in this process, but the only relevant data is in the center of my plot, so it should not be removed(?).
I have attached a file with containing matrices (X,Y,U,V)
%% UNCLEANED PLOT
clear; clc; close all;
load(['matrix_data.mat'])
% 0 values set to NaN
U(U==0) = NaN; % Set null data to NaN
V(V==0) = NaN; % Set null data to NaN
% Y direction
mult = 2.3;
close all
locationx = 123;
locationy = 145;
% X direction
figure('Position', [630 35 mult*560 mult*420])
subplot(2,2,1)
plot(X(:,locationx),V(:,locationx))
title('Steamwise Velocity (V-component)')
xlabel('X-position (mm)')
ylabel('Stream-wise veloctity (m/s)')
Lwall = -4.182; Rwall = 0.1648;
xline(Lwall,'color','r','linewidth',1)
xline(Lwall+1,'color','b','linewidth',1)
xline(Rwall,'color','r','linewidth',1)
xline(Rwall-1,'color','b','linewidth',1)
ylim([-5 95])
subplot(2,2,2)
pcolor(X,Y,V); hold on;
shading interp
colorbar
caxis([0 80])
plot(X(:,locationx),Y(:,locationx),'linewidth',1,'color','k')
title('Steamwise Velocity vs X-position')
xline(Lwall,'color','r','linewidth',1)
xline(Lwall+1,'color','b','linewidth',1)
xline(Rwall,'color','r','linewidth',1)
xline(Rwall-1,'color','b','linewidth',1)
xlabel('mm')
ylabel('mm')
axis equal
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/670378/image.png)
0 个评论
回答(2 个)
Image Analyst
2021-6-30
Not sure I follow your code but the general process to rotate points around a pivot point is to subtract the pivot point from all coordinates, then do the rotation with the rotation matrix, then add back in the offsets you subtracted initially. Something like (untested);
x = x - xCenter; % (xCenter, yCenter) is your pivot point.
y = y - yCenter;
% Now all x, y are with respect to your pivot point since they're been translated to the origin.
rotationMatrix = [cosd(angle), -sind(angle); sind(angle), cosd(angle)]; % angle is in degrees
rotatedxy = rotationMatrix * [x; y]; % x is a row vector
xNew = rotatedxy(1, :) + xCenter;
yNew = rotatedxy(2, :) + yCenter;
Matt J
2021-6-30
dt=flip(size(V)/2+0.5) - [-2.117,-8.053];
Vrotated = imtranslate( imrotate( imtranslate(V,dt) , -20) ,-dt); %the result
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!