Rotate output of streamslice fucntion

4 次查看(过去 30 天)
I simulated a problem in a body fixed reference frame but wanted to display the results in a lab fixed reference frame (with the body appearing to rotate and the frame fixed). I'm trying to use the streamslice function in matlab on the rotated data, but it doesn't want to do it on a grid that isn't uniformly aligned on the x-y axis. Is there any way to get streamslice to rotate my flowlines by 45 degrees?
  1 个评论
Shree Charan M L
Shree Charan M L 2023-10-9
Rotating the flow field by 45 degrees before using streamslice might help.
% Assuming u and v are flowline, calculate rotated flowlines
theta = deg2rad(45);
u_rotated = u * cos(theta) - v * sin(theta);
v_rotated = u * sin(theta) + v * cos(theta);

请先登录,再进行评论。

回答(1 个)

Avni Agrawal
Avni Agrawal 2023-12-15
Hi Ian,
I understand you are trying to use streamslice’ function in MATLAB on the rotated data. The ‘streamslice’ function in MATLAB is designed to work with data on a uniformly spaced grid aligned with the axes of the coordinate system. If you need to rotate the flow field by 45 degrees and still use ‘streamslice’, you will have to rotate your data to align with the grid, plot the streamlines, and then apply a visual transformation to rotate the plot.
Here is a simple example of how to rotate a flow field by 45 degrees using the ‘streamslice’function:
% Define the grid
[x, y] = meshgrid(linspace(-1, 1, 20), linspace(-1, 1, 20));
% Define a simple vector field (e.g., a circular pattern)
U = -y;
V = x;
% Define the rotation angle (45 degrees converted to radians)
theta = -45 * (pi / 180);
% Define the rotation matrix
R = [cos(theta) -sin(theta); sin(theta) cos(theta)];
% Apply the rotation to the vector field
% Initialize the rotated velocity components
U_rot = zeros(size(U));
V_rot = zeros(size(V));
% Rotate each vector
for i = 1:numel(x)
% Rotate the velocity vector at (x(i), y(i))
v = [U(i); V(i)];
v_rot = R * v;
% Store the rotated components
U_rot(i) = v_rot(1);
V_rot(i) = v_rot(2);
end
% Plot the original streamlines
figure;
subplot(1, 2, 1);
streams = streamslice(x, y, U, V);
set(streams, 'Color', 'b');
title('Original Field');
% Plot the rotated streamlines
subplot(1, 2, 2);
streams_rot = streamslice(x, y, U_rot, V_rot);
set(streams_rot, 'Color', 'r');
title('Rotated Field');
Please refer to the following documentation page for more information on the streamslice’ function: https://www.mathworks.com/help/matlab/ref/streamslice.html
I hope this helps.

类别

Help CenterFile Exchange 中查找有关 Polar Plots 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by