Rotation of a 3D vector field around axis

18 次查看(过去 30 天)
AC95
AC95 2020-8-18
回答: Gautam 2024-10-23,4:57
Hi all,
I am trying to rotate a vector field V described by its x,y and z components (Vx,Vy,Vz) and all three having dimensions of a 51x51x51 matrix. I am trying to rotate it around the y-axis of an angle theta. However, when I plot the streamlines of the field it looks very weird (figure 1). Basically, I am trying to tilt the streamlines in red to meet the green ones (figure 2). What I am currently doing is calculating the field over an x-y-z grid, then rotate the three components by use of the rotation matrix and finally plot the streamlines over the original mesh (i.e. I require the xyz coordinates to remain in place whilst the vector direction is rotated by theta.
Thanks in advance for any help provided!

回答(1 个)

Gautam
Gautam 2024-10-23,4:57
Hello @AC95,
I was able to rotate the vector field about the y-axis using a rotation matrix
Here's the code uses a rotation matrix to rotate the vector field counter-clockwise by an arbitrary angle “theta”
load wind
hold on
% Original streamline plot
l1 = streamslice(x,y,z,u,v,w,[],[],5, 0.2, "noarrows");
axis tight
theta = pi / 4; % Example: 45 degrees
% Define the rotation matrix around the y-axis
Ry = [cos(theta), 0, sin(theta);
0, 1, 0;
-sin(theta), 0, cos(theta)];
Vx_rot = zeros(size(u));
Vy_rot = zeros(size(v));
Vz_rot = zeros(size(w));
for i = 1:size(u, 1)
for j = 1:size(u, 2)
for k = 1:size(u, 3)
% Original vector
V = [u(i, j, k); v(i, j, k); w(i, j, k)];
% Rotated vector
V_rot = Ry * V;
% Store the rotated components
Vx_rot(i, j, k) = V_rot(1);
Vy_rot(i, j, k) = V_rot(2);
Vz_rot(i, j, k) = V_rot(3);
end
end
end
% Rotated streamline plot
l2 = streamslice(x,y,z,Vx_rot,Vy_rot,Vz_rot,[],[],5, 0.2,'noarrows');
set(l2,'Color','r');
hold off
Below is the output
In this, the red streamlines are rotated by 45 degrees with respect to the blue streamlines.

类别

Help CenterFile Exchange 中查找有关 3-D Scene Control 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by