Why does the view zoom in and out randomly when I try to rotate around my 3-D image?

38 views (last 30 days)
Why does the view zoom in and out randomly when I try to rotate around my 3-D image?
I have created a 3-D image and want to rotate my view around the image. As it rotates, the perspective seems to zoom in and out causing an undesired bouncing effect. The following code illustrates this effect:
% This part of the code draws an arbitrary image
figure('renderer','zbuffer','color','k')
[x,y,z]=sphere;
hold on
for j=[-1 1],
patch([-1 -1 1 1],[-1 1 1 -1],[j j j j],'b')
patch([-1 -1 1 1],[j j j j],[-1 1 1 -1],'r')
patch([j j j j],[-1 -1 1 1],[-1 1 1 -1],'g')
surf(x+3*j,y,z)
surf(x,y+3*j,z)
end
axis([-5 5 -6 6 -5 5],'off')
view(3)
%%%%%%%%%%%%%%%%
% Get the current view angle
[az,el]=view;
el=el+15;
%%%%%%%%%%
% Now rotate around the image
for j=10:10:360,
view(az+j,el)
pause(0.1)
end
How can I stabalize the view so that I can rotate the camera smoothly around my image?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 5 Jul 2012
You must do two things in order to avoid seeing a "bouncing" affect as you rotate around a 3-D image.
1. Set 'CameraViewAngleMode' to 'Manual'
The 'CameraViewAngle' property determines the camera field of view. Changing this value affects the size of graphics objects displayed in the axes. By default, the 'CameraViewAngleMode' is set to 'Auto' so that MATLAB adjusts the view angle automatically. Setting 'CameraViewAngleMode' to 'Manual' prevents any unexpected adjustments. You can set this mode to manual with the following command:
set(axes_handle,'CameraViewAngleMode','Manual')
where "axes_handle" is the handle to axes (usually obtained by using the GCA command).
2. Setting the axes aspect ratio to 1.
Set the axes aspect ratio to [1 1] so that equal tick mark increments on the x-,y- and z-axis are equal in size. You can do this with the command:
axis equal
This step is very important in order to properly rotate around your image. As the camera moves through your coordinate system, it is important that each tick have equal value. If the tick marks in one direction are much larger than the tick marks in another direction, then the camera will appear to zoom in and out as it changes axis alignments.
The following code domonstrates how these two steps produce a smoothly rotating animation.
% This part of the code draws an arbitrary image
figure('renderer','zbuffer','color','k')
[x,y,z]=sphere;
hold on
for j=[-1 1],
patch([-1 -1 1 1],[-1 1 1 -1],[j j j j],'b')
patch([-1 -1 1 1],[j j j j],[-1 1 1 -1],'r')
patch([j j j j],[-1 -1 1 1],[-1 1 1 -1],'g')
surf(x+3*j,y,z)
surf(x,y+3*j,z)
end
axis([-5 5 -6 6 -5 5],'off')
view(3)
%%%%%%%%%%%%%%%%
% Get the current view angle
[az,el]=view;
el=el+15;
%%%%%%%%%%
% The next two lines prevent the "bouncing" affect as you rotate the camera
set(gca,'cameraviewanglemode','manual')
axis equal
% Now rotate around the image
for j=10:10:360,
view(az+j,el)
pause(0.1)
end

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!