Rotate matrices about a point

조회 수: 56 (최근 30일)
Addison Collins
Addison Collins 2021년 6월 30일
댓글: Addison Collins 2021년 6월 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

답변 (2개)

Image Analyst
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;
  댓글 수: 1
Addison Collins
Addison Collins 2021년 6월 30일
편집: Addison Collins 2021년 6월 30일
So I left out a lot of the code that is irrelevant to making that plot. I'll summarize what is going on:
I took some particle image velocimetry (PIV) data from an extperiment, the laser sheet is coming in from the right side. It hits the middle of a circular probe (which is yawed 20°). I mask (set to NaN) the data that the camera/software collects from the location of the probe and data on the opposite side of the probe (the probe is polycarbonate and scatters the light, resulting in unusable data on that side). The camera is directly above the probe and it observes the movement of small smoke particles that follow the flow field. This generates U and V velocities that I am plotting.
My Code:
The solid red lines represnt the outer walls of the probe as if it was not rotated. The blue lines represent the inner walls. These lines are a product of when I ran PIV data with the probe at 0°. I use them to understand where the probe entrance is. The black line represents the data that is being plotted on the 1d graph in the subplot. I am attempting to rotate the data so I can analyze the 20° cases as if they are at 0°. It's easier (as far as I know) to analyze the points as if they are in a single vector rather than hopping across the matrix.
What I am trying to get the rotated code to look like: Note that the probe tip is parallel to the black line. When I rotate the probe in the experiment, it rotates at about the probe tip, (-2.117,-8.053) in this case.
I suppose I am trying to rotate the velocity matrices U and V about (-2.117,-8.053). My frame (x,y) doesn't really need to change.

댓글을 달려면 로그인하십시오.


Matt J
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
  댓글 수: 1
Addison Collins
Addison Collins 2021년 6월 30일
I had some issues with those lines. Vrotated was almost completely populated with zeros.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 3-D Scene Control에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by