Clear Filters
Clear Filters

Rotate matrices about a point

46 views (last 30 days)
Addison Collins
Addison Collins on 30 Jun 2021
Commented: Addison Collins on 30 Jun 2021
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)
clear; clc; close all;
% 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])
title('Steamwise Velocity (V-component)')
xlabel('X-position (mm)')
ylabel('Stream-wise veloctity (m/s)')
Lwall = -4.182; Rwall = 0.1648;
ylim([-5 95])
pcolor(X,Y,V); hold on;
shading interp
caxis([0 80])
title('Steamwise Velocity vs X-position')
axis equal

Answers (2)

Image Analyst
Image Analyst on 30 Jun 2021
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 Comment
Addison Collins
Addison Collins on 30 Jun 2021
Edited: Addison Collins on 30 Jun 2021
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.

Sign in to comment.

Matt J
Matt J on 30 Jun 2021
dt=flip(size(V)/2+0.5) - [-2.117,-8.053];
Vrotated = imtranslate( imrotate( imtranslate(V,dt) , -20) ,-dt); %the result
  1 Comment
Addison Collins
Addison Collins on 30 Jun 2021
I had some issues with those lines. Vrotated was almost completely populated with zeros.

Sign in to comment.


Find more on 2-D and 3-D Plots in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!