旋转关于Y轴的情节

时间:2015-08-16 16:58:41

标签: matlab

我有一个值向量,我希望通过它的半径绘制为圆上的亮度(即如果它是0 3 1 5我想要一个在中心是黑暗的圆,那么a围绕它的亮环,然后是一个稍微更暗的环,然后是一个更亮的环)。

为此,我尝试围绕y轴旋转我的径向矢量(E),

[X,Y,Z] = cylinder(E);
h = surf(X,Y,Z),

然而,我显然没有正确行事,因为这似乎是围绕x轴旋转我的曲线。我尝试过交换X和Y,但它仍围绕x轴旋转。任何帮助将不胜感激。

3 个答案:

答案 0 :(得分:1)

一种方法是旋转矢量并创建surface。曲面的Z数据(旋转的矢量)将根据您选择的颜色图进行颜色编码,如果您从顶部显示曲面,则会得到不同亮度的圆圈。

如果你真的只对这个表面的“顶视图”感兴趣,那么不需要创建一个完整的表面,一个简单的pcolor就可以完成这项工作。

示例:

%% // input data (and assumptions)
E=[0 3 1 5 2 7];                
nBrightness = 10 ;                      %// number of brightness levels
r = (0:numel(E)) ;                      %// radius step=1 by default for consecutive circles
                                        %// otherwise define different thickness for each circle

因此,如果我使用stairs([E 0]),您将获得不同的亮度级别: stairs

我必须在向量中添加最后0以“关闭”最后一级,我们将不得不在下面的解决方案中再次执行此操作。

现在围绕Y旋转/复制它,颜色编码高度,并从顶部看它:

%% // replicate profile around axis
ntt = 50 ;                              %// define how many angular division for the plot
theta = linspace(0,2*pi,ntt) ;          %// create all the angular divisions
[rr,tt]=meshgrid(r,theta) ;             %// generate a grid 

z = repmat( [E 0] , ntt , 1 ) ;         %// replicate our "E" vector to match the grid

[xx,yy,zz] = pol2cart(tt,rr,z) ;        %// convert everything to cartesian coordinates

pcolor(xx,yy,zz)                        %// plot everything
colormap(gray(nBrightness))             %// make sure we use only "nBrightness" colors (Shades of gray)
caxis([0 nBrightness])

shading flat ; axis equal               %// refine the view (axis ratio and "spokes" not visible) etc...
colorbar
axis off

将产生以下结果:

circles

请注意,您的问题尚未完全定义,我必须对以下内容进行假设:

  • 每个亮度圆的半径应该是多少? (我把它们都做了,但你可以修改它)
  • 您想要多少亮度? (你也可以轻松修改它。)

答案 1 :(得分:0)

您是否尝试过rotate功能?

direction = [0 1 0];
rotate(h,direction,90);

在此示例中,围绕y轴执行90度旋转。

答案 2 :(得分:0)

使用此库http://www.mathworks.com/matlabcentral/fileexchange/45952-circle-plotter

%http://www.mathworks.com/matlabcentral/fileexchange/45952-circle-plotter
x0 = 0;
y0 = 0;
colors = [0 3 1 5];
maxC = max(colors);
sz = numel(colors);
for i=fliplr(1:sz)
    c = colors(i);
    circles(x0,y0,i,'facecolor',[c/maxC c/maxC 0])   % http://au.mathworks.com/help/matlab/ref/colorspec.html
end