Matlab coneplot函数绘制圆锥体速度向量

4.5
(4)

前面几篇,我们介绍了很多关于Matlab绘制流线图的教程,主要包括了streamline函数、streamslice函数、streamparticles函数、streamribbon函数、streamtube函数。本文,我们将介绍coneplot函数。Matlab中,coneplot函数可以用于在三维向量场中以圆锥体形式绘制速度向量。文章,主要coneplot函数的常见用法,语法说明、三维圆锥图等用法。

Matlab coneplot函数绘制圆锥体速度向量

下面,我们首先给出Matlab中关于coneplot函数的帮助文档如下:

>> help coneplot
 coneplot  3D cone plot.
    coneplot(X,Y,Z,U,V,W,Cx,Cy,Cz) plots velocity vectors as cones
    at the points (Cx,Cy,Cz) in vector field defined by U,V,W.  The
    arrays X,Y,Z define the coordinates for U,V,W and must be
    monotonic and 3D plaid (as if produced by MESHGRID). coneplot
    automatically scales the cones to fit. 
    
    coneplot(U,V,W,Cx,Cy,Cz) assumes [X Y Z] = meshgrid(1:N, 1:M, 1:P)
    where [M,N,P]=SIZE(U). 
    
    coneplot(...,S) automatically scales the cones to fit and then
    stretches them by S.  Use S=0 to plot the cones without the automatic
    scaling.
 
    coneplot(...,COLOR) colors the cones using the array
    COLOR. COLOR must be a 3D array and be the same size as U. This
    option only works with cones and not quiver arrows.
    
    coneplot(...,'quiver') draws arrows instead of cones (see QUIVER3).
 
    coneplot(...,'method') specifies the interpolation method to use.
    'method' can be 'linear', 'cubic', or 'nearest'.  'linear' is the
    default (see INTERP3).
    
    coneplot(X,Y,Z,U,V,W, 'nointerp') does not interpolate the
    positions of the cones into a volume. The cones are drawn at
    positions defined by X,Y,Z and are oriented according to
    U,V,W. Arrays  X,Y,Z,U,V,W must all be the same size.
 
    coneplot(AX,...) plots into AX instead of GCA.
 
    H = coneplot(...) returns a PATCH handle in H.
    
    Example:
       load wind
       vel = sqrt(u.*u + v.*v + w.*w);
       p = patch(isosurface(x,y,z,vel, 40));
       isonormals(x,y,z,vel, p)
       p.FaceColor = 'red';
       p.EdgeColor = 'none';
 
       [f verts] = reducepatch(isosurface(x,y,z,vel, 30), .2); 
       h=coneplot(x,y,z,u,v,w,verts(:,1),verts(:,2),verts(:,3),2);
       h.FaceColor = 'blue';
       h.EdgeColor = 'none';
       [cx cy cz] = meshgrid(linspace(71,134,10),linspace(18,59,10),3:4:15);
       h2=coneplot(x,y,z,u,v,w,cx,cy,cz,v,2); %color by North/South velocity
       h2.EdgeColor = 'none';
 
       axis tight; box on
       camproj p; camva(24); campos([185 2 102])
       camlight left; lighting phong

常见用法

coneplot(X,Y,Z,U,V,W,Cx,Cy,Cz)
coneplot(U,V,W,Cx,Cy,Cz)
coneplot(...,s)
coneplot(...,color)
coneplot(...,'quiver')
coneplot(...,'method')
coneplot(X,Y,Z,U,V,W,'nointerp')
coneplot(axes_handle,...)
h = coneplot(...)

语法说明

coneplot(X,Y,Z,U,V,W,Cx,Cy,Cz) 以指向速度向量方向的圆锥体形式绘制速度向量,并且具有与速度向量的量级成比例的长度。 X、Y、Z 定义向量场的坐标。U、V、W 定义向量场。这些数组必须为大小相同的单调数组,并表示轴对齐的笛卡尔网格(例如 meshgrid 生成的数据)。Cx、Cy、Cz 定义向量场中圆锥体的位置。可视化方法中的指定流线图的起点部分提供了有关定义起始点的详细信息。

coneplot(U,V,W,Cx,Cy,Cz)(省略 X、Y 和 Z 参数)假定 [X,Y,Z] = meshgrid(1:n,1:m,1:p),其中 [m,n,p]= size(U)。

coneplot(…,s) 将自动缩放圆锥体以适应图形,然后按缩放因子 s 对圆锥体进行拉伸。如果未为 s 指定值,则 coneplot 使用值 1。使用 s = 0 绘制圆锥体,无需自动缩放。

coneplot(…,color) 在向量场上插入数组 color,然后根据插入的值对圆锥体进行着色。color 数组的大小必须与 U、V、W 数组的大小相同。此选项仅对圆锥体有效(即不能与 quiver 选项一起使用)。

coneplot(…,’quiver’) 绘制箭头而不是圆锥体(有关箭头图的说明,请参阅 quiver3)。

coneplot(…,’method’) 指定要使用的插值方法。method 可以是 linear、cubic 或 nearest。linear 是默认值。(有关这些插值方法的讨论,请参阅 interp3。)

coneplot(X,Y,Z,U,V,W,’nointerp’) 不将圆锥体的位置插入三维体中。圆锥体在 X、Y、Z 定义的位置进行绘制,并根据 U、V、W 定位方向。数组 X、Y、Z、U、V、W 的大小必须相同。

coneplot(axes_handle,…) 将图形绘制到带有句柄 axes_handle 的坐标区中,而不是当前坐标区 (gca) 中。

h = coneplot(…) 返回用于绘制圆锥体的 patch 对象的句柄。

coneplot 自动缩放圆锥体以适应图形,同时使圆锥体与各自的速度向量成比例。

三维圆锥图

为向量三维体数据绘制速度向量圆锥体,以表示气体流经矩形空间区域的运动。

加载数据。wind 数据集包含指定向量分量的数组 u、v 和 w 以及指定坐标的数组 x、y 和 z。

load wind

确定要用于放置切片平面和指定圆锥体绘图所在位置的数据范围。

xmin = min(x(:));
xmax = max(x(:));
ymin = min(y(:));
ymax = max(y(:));
zmin = min(z(:));

定义绘制圆锥体的位置。选择 x 和 y 中的完整范围并选择 z 中的范围 3 到 15。

xrange = linspace(xmin,xmax,8);
yrange = linspace(ymin,ymax,8);
zrange = 3:4:15;
[cx,cy,cz] = meshgrid(xrange,yrange,zrange);

绘制圆锥体,并将缩放因子设置为 5,以使圆锥体大于默认大小。

figure
hcone = coneplot(x,y,z,u,v,w,cx,cy,cz,5);
Matlab coneplot函数绘制圆锥体速度向量

设置圆锥图颜色。

hcone.FaceColor = 'red';
hcone.EdgeColor = 'none';
Matlab coneplot函数绘制圆锥体速度向量

计算向量场的模(代表风速),以生成用于 slice 命令的标量数据。

hold on
wind_speed = sqrt(u.^2 + v.^2 + w.^2);

沿 x 轴的 xmin 和 xmax、y 轴的 ymax 和 z 轴的 zmin 处创建切片平面。指定插值面颜色,这样切片颜色指示风速,并且不绘制边缘。

hsurfaces = slice(x,y,z,wind_speed,[xmin,xmax],ymax,zmin);
set(hsurfaces,'FaceColor','interp','EdgeColor','none')
hold off
Matlab coneplot函数绘制圆锥体速度向量

更改坐标区视图并设置数据纵横比。

view(30,40)
daspect([2,2,1])
Matlab coneplot函数绘制圆锥体速度向量

在相机的右侧添加一个光源,然后通过 Gouraud 光照使圆锥体和切片平面上产生平滑的三维外观。

camlight right
lighting gouraud
set(hsurfaces,'AmbientStrength',0.6)
hcone.DiffuseStrength = 0.8;
Matlab coneplot函数绘制圆锥体速度向量

共计4人评分,平均4.5

到目前为止还没有投票~

很抱歉,这篇文章对您没有用!

让我们改善这篇文章!

告诉我们我们如何改善这篇文章?

文章目录

转载文章,原文出处:MathWorks官网,由古哥整理发布

如若转载,请注明出处:https://iymark.com/articles/2064.html

(1)
微信公众号
古哥的头像古哥管理团队
上一篇 2021年03月10日 19:09
下一篇 2021年03月12日 22:13

你可能感兴趣的文章

发表回复

登录后才能评论
微信小程序
微信公众号