在流丝带图中,如何绘制丝带本身的边缘,而不是每个面的边缘?
例如:
figure
load wind
[sx sy sz] = meshgrid(80,20:10:50,0:5:15);
h = streamribbon(x,y,z,u,v,w,sx,sy,sz);
axis tight
shading interp;
view(3);
camlight
lighting gouraud
产生:
如果我加 set(h,'edgecolor','k')
我得到:
而我正在寻找的是这样的东西(图像的顶部和左侧已使用gimp进行了编辑,以说明我所追求的目标):
如评论中所述,没有简单的方法来照亮色带表面的某些边缘,而不能照亮其他边缘。
However, the ribbon surfaces are simply defined by the points on the edges, so it is only a matter of retrieving these points and reorganizing them (inline them) to get a perfect coordinate set for 3D lines.
To get a closed profile, we just need to replicate the first point at the end of the profile.
I packaged that into a function which will return a set of handles
the same size as the ribbon handle array, and transfer any additional parameters you can send to the internal plot3
function. So the usage is quite straightforward:
So using exactly the same code than in the question (which retrieve the array of ribbon surface handle in the variable h
), adding:
hs = StreamEdges( h , 'k','Linewidth',1 ) ;
will produce:
Of course, you can always get crazy and set your line properties in group:
set(hs,'LineWidth',1,'Color','c')
%// or
set(hs,'LineWidth',2,'Color','r','Marker','none')
Code for function StreamEdges.m
:
function hs = StreamEdges(hribbon,varargin)
wasOnHold = ishold ; %// save hold state
hold on
hs = zeros( size(hribbon) ) ; %// initialize output handle array
for ih=1:numel( hribbon ) ;
%// retrieve X, Y, and Z data of each surface
hsurf = handle( hribbon(ih)) ; %// for pre-HG2 (2014a) versions
xx = hsurf.XData ;
yy = hsurf.YData ;
zz = hsurf.ZData ;
%// reoder coordinates to linearise surface profile (edge)
xx = [xx(:,1) ; flipud(xx(:,2)) ; xx(1)] ;
yy = [yy(:,1) ; flipud(yy(:,2)) ; yy(1)] ;
zz = [zz(:,1) ; flipud(zz(:,2)) ; zz(1)] ;
%// return double to stay compatible with pre-HG2
hs(ih) = double( plot3(xx(:),yy(:),zz(:), varargin{:} ) ) ;
end
if ~wasOnHold ; hold off ; end %// restore hold state
hs = handle(hs) ; %// convert "double" handle back to HG2 handles
The function should work with version pre-HG2 (=pre 2014b) or post-HG2. The handle array it will return will be in the HG2 format (= real handle, not just their double
representation). This gives you access to the dot notation on your graphic object even for version pre-HG2. If you are not comfortable with that, just comment the last line of the function (or to get the old handle style you can always use the function hs = double(hs)
)
Target axes
除了保留hold
状态外,该函数的行为类似于大多数高级绘图函数,这意味着它们将直接转到当前axes
(gca
),或者如果不存在则创建一个新的。
您可以轻松地修改函数以接受axes
句柄作为目标,或者简单地不进行修改就在参数中显式调用它:
hs = StreamEdges( h , 'Parent','target_axes_handle' , 'Color','k','Linewidth',1) ;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句