Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep object size constant when rotating 3-D Matlab plot

I am trying to generate a set of views of a 3-D object in Matlab such that the angle changes but the object size stays constant. Because Matlab tries to fit the entire axis into view, an object will shrink or grow depending on whether the plot is viewed head-on or at an angle. As an example:

[x,y,z] = sphere(50); % coordinates of a sphere
surf(x,y,z);          % plot the sphere
axis image off
view(0,0)             % at this angle the sphere fills the axes
view(-37.5,30)        % at this angle the sphere is much smaller

How can I make it so that the sphere appears the same size no matter what angle it's viewed at?

like image 808
David Pfau Avatar asked Oct 03 '22 06:10

David Pfau


1 Answers

The axis function is your friend here. Try adding

axis vis3d

From the help, "axis VIS3D freezes aspect ratio properties to enable rotation of 3-D objects and overrides stretch-to-fill." If you're interested The same this can be accomplished via

ax = gca;
props = {'CameraViewAngle','DataAspectRatio','PlotBoxAspectRatio'};
set(ax,props,get(ax,props));
like image 154
horchler Avatar answered Oct 07 '22 19:10

horchler