用椭圆和颜色表示矢量场
Representing vector field with ovals and color
我有一个矢量场,它显示了一些椭圆在不同位置的不同纵横比的方向。我可以通过以下脚本在 Matlab 中绘制它:
[X, Y] = meshgrid(1:size(nx,1), 1:size(nx,2));
quiver(X,Y, nx, ny, 'ShowArrowHead', 'Off','linewidth',1);
set(qh, 'Color', 'k');
其中 X 和 Y 表示 space 中的位置,nx
和 ny
表示椭圆的方向。关于纵横比的信息在nx
和ny
里面。因此,sqrt(nx.^2+ny.^2)
给出了一个介于 0 和 1 之间的大小。如果这个大小在某些点上为零,则意味着在这些点上我们有圆形而不是椭圆形。如果它等于 1,则表示我们有一个拉长的椭圆形。
但它看起来很基本。我想要一些东西,其中 space 中的每个点都有一个旋转的椭圆形,其中颜色显示纵横比。我如何在 Matlab 或 python 中执行此操作?
您可以创建一个椭圆网格并对每个网格应用旋转矩阵。这是一个最小的例子:
[X0, Y0] = meshgrid(0:5,0:5); % the initial grid
a = 0.2; % horizontal radius
b = 0.4; % vertical radius
t = 0:0.01:2*pi;
rotmat = @(phi) [cos(phi) sin(phi); -sin(phi) cos(phi)]; % A 2D anonymous rotation matrix
hold on
% For each point of the grid we plot an ellipse
for ii = 1:numel(X0)
phi = mod((ii/20),2*pi); % rotation by phi (in radian)
XY = rotmat(phi)*[a*cos(t);b*sin(t)]; % we apply the rotation to the ellipse equation
x = XY(1,:)+X0(ii); % Shift x with X0
y = XY(2,:)+Y0(ii); % Shift y with Y0
fill(x,y,ii) % plot the ellipse
end
axis equal
我们得到:
你只需要根据nx
和ny
改变水平和垂直半径和phi
。
我有一个矢量场,它显示了一些椭圆在不同位置的不同纵横比的方向。我可以通过以下脚本在 Matlab 中绘制它:
[X, Y] = meshgrid(1:size(nx,1), 1:size(nx,2));
quiver(X,Y, nx, ny, 'ShowArrowHead', 'Off','linewidth',1);
set(qh, 'Color', 'k');
其中 X 和 Y 表示 space 中的位置,nx
和 ny
表示椭圆的方向。关于纵横比的信息在nx
和ny
里面。因此,sqrt(nx.^2+ny.^2)
给出了一个介于 0 和 1 之间的大小。如果这个大小在某些点上为零,则意味着在这些点上我们有圆形而不是椭圆形。如果它等于 1,则表示我们有一个拉长的椭圆形。
但它看起来很基本。我想要一些东西,其中 space 中的每个点都有一个旋转的椭圆形,其中颜色显示纵横比。我如何在 Matlab 或 python 中执行此操作?
您可以创建一个椭圆网格并对每个网格应用旋转矩阵。这是一个最小的例子:
[X0, Y0] = meshgrid(0:5,0:5); % the initial grid
a = 0.2; % horizontal radius
b = 0.4; % vertical radius
t = 0:0.01:2*pi;
rotmat = @(phi) [cos(phi) sin(phi); -sin(phi) cos(phi)]; % A 2D anonymous rotation matrix
hold on
% For each point of the grid we plot an ellipse
for ii = 1:numel(X0)
phi = mod((ii/20),2*pi); % rotation by phi (in radian)
XY = rotmat(phi)*[a*cos(t);b*sin(t)]; % we apply the rotation to the ellipse equation
x = XY(1,:)+X0(ii); % Shift x with X0
y = XY(2,:)+Y0(ii); % Shift y with Y0
fill(x,y,ii) % plot the ellipse
end
axis equal
我们得到:
你只需要根据nx
和ny
改变水平和垂直半径和phi
。