Jack
Jack

Reputation: 209

Rotating a Plot About the Y Axis

I have a vector of values that I want to plot as brightness on a circle through the radius of it (I.e. If it was 0 3 1 5 I'd want a circle that was dark at the centre, then a bright ring around it, then a slightly darker ring, then a brighter ring).

To do this I've attempted to rotate my radial vector (E) around the y axis, as such

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

However I'm clearly not doing it right, as this appears to be rotating my curve around the x axis. I've tried just swapping X and Y, but it still rotates it around the x axis. Any help would be greatly appreciated.

Upvotes: 0

Views: 1045

Answers (3)

Hoki
Hoki

Reputation: 11812

One way would be to rotate your vector and create a surface. The Z data of the surface (your rotated vector) will be color coded according to the colormap you choose, if you display the surface from the top you get your circles at the different brightness.

If you are really only interested from the "top view" of this surface, then no need to create a full surface, a simple pcolor will do the job.


example:

%% // 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

So if I use stairs([E 0]) you get your different brightness levels: stairs

I had to add a last 0 to the vector to "close" the last level, we'll have to do that again in the solution below.

Now to rotate/replicate that around Y, color code the height, and look at it from the top:

%% // 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

will yield the following :

circles


Note that your problem was not fully defined, I had to take assumptions on:

  • What radius each brightness circle should have ? (I made them all the same but you can modify that)
  • How many brightness levels you want ? (You can also modify that easily though).

Upvotes: 1

Derrops
Derrops

Reputation: 8127

Using this library 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

Upvotes: 0

Nikolaos Sarafianos
Nikolaos Sarafianos

Reputation: 1

Have you tried the rotate function?

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

In this example a 90 degree rotation is performed around the y axis.

Upvotes: 0

Related Questions