今天,带来Matlab中,使用streamribbon函数根据向量三维体数据生成三维流带图的教程。前面,我们有讲过《Matlab streamslice切片平面流线图函数》以及《Matlab使用streamparticles绘制流粒子》。这些都属于Matlab流线图函数相关的范畴。
本文主要讲解streamribbon函数的常见用法、语法说明、使用流带指示流动情况、使用预先计算的数据指示流动情况、有扭曲角度的流带、圆锥图和流带图的组合等用法。
下面,我们首先给出Matlab中关于streamribbon函数的帮助文档如下:
>> help streamribbon streamribbon 3D stream ribbon. streamribbon(X,Y,Z,U,V,W,STARTX,STARTY,STARTZ) draws stream ribbons from vector data 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). STARTX, STARTY, and STARTZ define the starting positions of the streamlines at the center of the ribbons. The twist of the ribbons is proportional to the curl of the vector field. The width of the ribbons is calculated automatically. streamribbon(U,V,W,STARTX,STARTY,STARTZ) assumes [X Y Z] = meshgrid(1:N, 1:M, 1:P) where [M,N,P]=SIZE(U). streamribbon(VERTICES,X,Y,Z,CAV,SPEED) assumes precomputed streamline vertices, curl angular velocity, and flow speed. VERTICES is cell array of streamline vertices (as if produced by stream3). X,Y,Z, CAV and SPEED are 3D arrays. streamribbon(VERTICES,CAV,SPEED) assumes [X Y Z] = meshgrid(1:N, 1:M, 1:P) where [M,N,P] = SIZE(CAV). streamribbon(VERTICES,TWISTANGLE) uses the cell array of vectors TWISTANGLE for the twist of the ribbons (in radians). The size of each corresponding element of VERTICES and TWISTANGLE must be equal. streamribbon(...,WIDTH) sets the width of the ribbons to be WIDTH. streamribbon(AX,...) plots into AX instead of GCA. H = streamribbon(...) returns a vector of handles (one per start point) to SURFACE objects. Example 1: load wind [sx sy sz] = meshgrid(80, 20:10:50, 0:5:15); daspect([1 1 1]) h=streamribbon(x,y,z,u,v,w,sx,sy,sz); axis tight shading interp; view(3); camlight; lighting gouraud Example 2: load wind [sx sy sz] = meshgrid(80, 20:10:50, 0:5:15); daspect([1 1 1]) verts = stream3(x,y,z,u,v,w,sx,sy,sz); cav = curl(x,y,z,u,v,w); spd = sqrt(u.^2 + v.^2 + w.^2); h=streamribbon(verts,x,y,z,cav,spd); axis tight shading interp; view(3); camlight; lighting gouraud Example 3: t = 0:.15:15; verts = {[cos(t)' sin(t)' (t/3)']}; twistangle = {cos(t)'}; daspect([1 1 1]) h=streamribbon(verts,twistangle); axis tight shading interp; view(3); camlight; lighting gouraud Example 4: xmin = -7; xmax = 7; ymin = -7; ymax = 7; zmin = -7; zmax = 7; x = linspace(xmin,xmax,30); y = linspace(ymin,ymax,20); z = linspace(zmin,zmax,20); [x y z] = meshgrid(x,y,z); u = y; v = -x; w = 0*x+1; daspect([1 1 1]); [cx cy cz] = meshgrid(linspace(xmin,xmax,30),linspace(ymin,ymax,30),[-3 4]); h2=coneplot(x,y,z,u,v,w,cx,cy,cz, 'q'); h2.Color = 'k'; [sx sy sz] = meshgrid([-1 0 1],[-1 0 1],-6); p = streamribbon(x,y,z,u,v,w,sx,sy,sz); [sx sy sz] = meshgrid([1:6],[0],-6); p2 = streamribbon(x,y,z,u,v,w,sx,sy,sz); shading interp view(-30,10) ; axis off tight camproj p; camva(66); camlookat; camdolly(0,0,.5,'f') camlight
常见用法
streamribbon(X,Y,Z,U,V,W,startx,starty,startz) streamribbon(U,V,W,startx,starty,startz) streamribbon(vertices,X,Y,Z,cav,speed) streamribbon(vertices,cav,speed) streamribbon(vertices,twistangle) streamribbon(...,width) streamribbon(axes_handle,...) h = streamribbon(...)
语法说明
streamribbon(X,Y,Z,U,V,W,startx,starty,startz) 从向量三维体数据 U、V 和 W 绘制流带。
数组 X、Y 和 Z 用于定义 U、V 和 W 的坐标,它们必须是单调的,无需间距均匀。X、Y 和 Z 必须具有相同数量的元素,就像由 meshgrid 生成一样。
startx, starty 和 startz 定义流带的起始位置(中心处)。
条带的扭曲度与向量场的旋度成比例。条带的宽度将会自动计算。
streamribbon(U,V,W,startx,starty,startz) 假定 X、Y 和 Z 由以下表达式确定
[X,Y,Z] = meshgrid(1:n,1:m,1:p)
其中 [m,n,p] = size(U)。
streamribbon(vertices,X,Y,Z,cav,speed) 使用预先计算的流线图顶点、旋转角速度和流速。vertices 是流线图顶点的元胞数组(就像由 stream3 生成一样)。X、Y、Z、cav 和 speed 是三维数组。
streamribbon(vertices,cav,speed) 假定 X、Y 和 Z 由以下表达式确定
[X,Y,Z] = meshgrid(1:n,1:m,1:p)
其中 [m,n,p] = size(cav)。
streamribbon(vertices,twistangle) 将包含向量 twistangle 的元胞数组用于条带的扭曲度(以弧度为单位)。vertices 和 twistangle 的每个对应元素的大小必须相等。
streamribbon(…,width) 将条带的宽度设置为 width。
streamribbon(axes_handle,…) 将图形绘制到句柄为 axes_handle 的坐标区对象中,而不是当前坐标区对象 (gca) 中。
h = streamribbon(…) 将句柄(每个起始点一个句柄)向量返回到 surface 对象。
使用流带指示流动情况
使用流带指示数据集中的流动情况。
load wind [sx,sy,sz] = meshgrid(80,20:10:50,0:5:15); streamribbon(x,y,z,u,v,w,sx,sy,sz); axis tight shading interp view(3); camlight lighting gouraud
使用预先计算的数据指示流动情况
使用预先计算的顶点数据、旋转平均速度和速度指示流动情况。
load wind [sx,sy,sz] = meshgrid(80,20:10:50,0:5:15); verts = stream3(x,y,z,u,v,w,sx,sy,sz); cav = curl(x,y,z,u,v,w); spd = sqrt(u.^2 + v.^2 + w.^2).*.1; streamribbon(verts,x,y,z,cav,spd); axis tight shading interp view(3); camlight; lighting gouraud
利用预先计算的数据,您可以使用从单一数据源计算的值之外的值。在这种情况下,相对于上一示例,速度按照因子 10 下降。
有扭曲角度的流带
指定流带的扭曲角度
t = 0:.15:15; verts = {[cos(t)' sin(t)' (t/3)']}; twistangle = {cos(t)'}; streamribbon(verts,twistangle); axis tight shading interp view(3) camlight lighting gouraud
圆锥图和流带图的组合
创建三维数组和圆锥图。
xmin = -7; xmax = 7; ymin = -7; ymax = 7; zmin = -7; zmax = 7; x = linspace(xmin,xmax,30); y = linspace(ymin,ymax,20); z = linspace(zmin,zmax,20); [x,y,z] = meshgrid(x,y,z); u = y; v = -x; w = 0*x+1; [cx,cy,cz] = meshgrid(linspace(xmin,xmax,30),... linspace(ymin,ymax,30),[-3 4]); h = coneplot(x,y,z,u,v,w,cx,cy,cz,'quiver'); set(h,'Color','k');
绘制两组流带图。然后,定义视图和光照。
[sx,sy,sz] = meshgrid([-1 0 1],[-1 0 1],-6); streamribbon(x,y,z,u,v,w,sx,sy,sz); [sx,sy,sz] = meshgrid([1:6],[0],-6); streamribbon(x,y,z,u,v,w,sx,sy,sz); shading interp view(-30,10) axis off tight camproj perspective camva(66) camlookat camdolly(0,0,.5,'fixtarget') camlight
转载文章,原文出处:MathWorks官网,由古哥整理发布
如若转载,请注明出处:https://iymark.com/articles/1984.html