MATLAB Answers

How to rotate velocities and corresponding coordinates

2 views (last 30 days)
Addison Collins
Addison Collins on 12 Aug 2021
Commented: Addison Collins on 13 Aug 2021
Hello everyone. I am trying to rotate my velocity data 90 degrees clockwise. I attempted using rot(90) a couple of times, but I am having issues plotting everything correctly. I have attached the matlab data file and the file with the code (it's identical to the code below).
PS, the 'if loops' are just to determine the vector that characterizes where to start the streamlines upstream.
The photo below is the graph I currently have:
I basically need to rotate all my x,y, and u,v data such that the streamlines are going from left to right as opposed from bottom to top (current setup). Below is basically what I need the streamlines to look like.
clc;clear;close all;
% Set plot stuff:
% set(0,'DefaultLineColor',[1,1,1])
% set(0,'DefaultTextInterpreter','latex')
%% User Inputs
quiv_opt = 0;
streamline_opt = 0; yay ='yes';
run = '1';
runname = 'M.25_0Y_A';
if streamline_opt == 0
left = 2; % Adjust begining location of streamlines
right = 2; % Adjust ending location of streamlines
left = 11; % Adjust begining location of streamlines
right = 9; % Adjust ending location of streamlines
%% Load data
Uavg(Uavg==0) = NaN; % Set null data to NaN
Vavg(Vavg==0) = NaN; % Set null data to NaN
Xi = sort(X(:,1));
Yi = sort(Y(1,:))';
% Create the combination of xq and yq
[Xq, Yq] = meshgrid(Xi,Yi);
% Interp the data if the x and y data in the file is not in a grid
% Uq = (Uavg);
% Vq = (Vavg);
% Xq = rot90(rot90(Xq));
% Yq = rot90(rot90(Yq));
Uq = rot90(Uavg);
Vq = rot90(Vavg);
% probe walls (Need rotate these eventually)
xtip = -4.18; % Bottom left vertice of left probe wall
ytip = -7.703; % Bottom left vertice of left probe wall
height = 12.7; % mm
width = 1; % mm
gap = 3; % mm - Distance between probe walls (left end of the walls)
% New coordinates (origin will be at hte probe tip)
xcenter = xtip+2; % X-center point of probe tip
ycenter = ytip; % Y-center point of probe tip
xtip = xtip-xcenter; % Bottom left vertice of left probe wall
ytip = ytip-ycenter; % Bottom left vertice of left probe wall
Xq = Xq-xcenter;
Yq = Yq-ycenter;
%% Plot vectors, probe walls, and streamlines
fig = figure('Renderer', 'painters', 'Position', [1300 10 947 900])
if quiv_opt == 1
quiver(Xq,Yq,Uq,Vq, 1);
hold on;
l = title({'test_line'}, 'Interpreter', 'none');
title(['Averaged Velocities and Streamlines (',runname,')'])
% Plot probe walls
% rectangle('Position',[xtip,ytip,width,height],'FaceColor','k')
% rectangle('Position',[xtip+gap,ytip,width,height],'FaceColor','k')
% Plot streamlines
xlabel('x (mm)')
ylabel('y (mm)')
%% Streamline options
s = 0.015;
if streamline_opt == 1
% Calculation Streamlines
startx = (-3-xcenter+left*s):s:(-1.75-xcenter+right*s);
% Figure Streamlines (for thesis to demonstrate)
s = 0.10;
startx = (-3-xcenter+left*s):0.10:(-1.75-xcenter+right*s);
starty = (min(min(Yq))+.3255)*ones(size(startx));
if strcmp(yay,'yes') == 1
hgridinterp = streamline(Xq,Yq,Uq,Vq,startx,starty); hold on;
xbound = -3;
xlim([xbound abs(xbound)]);
ylim([-5 1]);
daspect([1 1 1])
  1 Comment
Addison Collins
Addison Collins on 13 Aug 2021
I solved my issue by simply inputting X as Y and Y as X, same for U and V. It worked with my quiver plot, now I am trying it with the streamlines.
My Inputs
hgridinterp = streamline(Yq,-Xq,Vq,-Uq,startx,starty);
quiver(Yq,-Xq,Vq,-Uq, 1);

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 12 Aug 2021
Edited: Walter Roberson on 12 Aug 2021
There are two approaches possible here:
  1. You can create a hgtransform() and parent the streamline() plot to it, and set the Matrix property of the transform to rotate the plot;
  2. You can use stream2() to calculate the vertices as a cell array, and then cellfun() to apply a rotation matrix, which would be (x,y) -> (-y, x) I believe . Then you can streamline() passing in the rotated coordinates cell instead of x, y
rot90() has nothing to do with the situation: it is for matrices, not for coordinates.
  1 Comment
Addison Collins
Addison Collins on 13 Aug 2021
But X and Y are in fact matrices that deal with the coordinates. I almost have it, but the points are slightly off with the original. Not sure why.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by