Products & Services Industries Academia Support User Community Company

Learn more about MATLAB   

rotate3d - Rotate 3-D view using mouse

GUI Alternatives

Use the Rotate3D tool on the figure toolbar to enable and disable rotate3D mode on a plot, or select Rotate 3D from the figure's Tools menu. For details, see Rotate 3D — Interactive Rotation of 3-D Views in the MATLAB Graphics documentation.

Syntax

rotate3d on
rotate3d off
rotate3d
rotate3d(figure_handle,...)
rotate3d(axes_handle,...)
h = rotate3d(figure_handle)

Description

rotate3d on enables mouse-base rotation on all axes within the current figure.

rotate3d off disables interactive axes rotation in the current figure.

rotate3d toggles interactive axes rotation in the current figure.

rotate3d(figure_handle,...) enables rotation within the specified figure instead of the current figure.

rotate3d(axes_handle,...) enables rotation only in the specified axes.

h = rotate3d(figure_handle) returns a rotate3d mode object for figure figure_handle for you to customize the mode's behavior.

Using Rotate Mode Objects

You access the following properties of rotate mode objects via get and modify some of them using set.

Rotate3D Mode Callbacks

You can program the following callbacks for rotate3d mode operations.

Rotate3D Mode Utility Functions

The following functions in pan mode query and set certain of its properties.

Examples

Example 1

Simple 3-D rotation

surf(peaks);
rotate3d on
% rotate the plot using the mouse pointer.

Example 2

Rotate the plot using the "Plot Box" rotate style:

surf(peaks);
h = rotate3d;
set(h,'RotateStyle','box','Enable','on');
% Rotate the plot.

Example 3

Create two axes as subplots and then prevent one from rotating:

ax1 = subplot(1,2,1);
surf(peaks);
h = rotate3d;
ax2 = subplot(1,2,2);
surf(membrane);
setAllowAxesRotate(h,ax2,false);
% rotate the plots.

Example 4

Create a buttonDown callback for rotate mode objects to trigger. Copy the following code to a new M-file, execute it, and observe rotation behavior:

function demo
% Allow a line to have its own 'ButtonDownFcn' callback.
hLine = plot(rand(1,10));
set(hLine,'ButtonDownFcn','disp(''This executes'')');
set(hLine,'Tag','DoNotIgnore');
h = rotate3d;
set(h,'ButtonDownFilter',@mycallback);
set(h,'Enable','on');
% mouse-click on the line
%
function [flag] = mycallback(obj,event_obj)
% If the tag of the object is 'DoNotIgnore', then return true.
objTag = get(obj,'Tag');
if strcmpi(objTag,'DoNotIgnore')
   flag = true;
else
   flag = false;
end

Example 5

Create callbacks for pre- and post-buttonDown events for rotate3D mode objects to trigger. Copy the following code to a new M-file, execute it, and observe rotation behavior:

function demo
% Listen to rotate events
surf(peaks);
h = rotate3d;
set(h,'ActionPreCallback',@myprecallback);
set(h,'ActionPostCallback',@mypostcallback);
set(h,'Enable','on');
%
function myprecallback(obj,evd)
disp('A rotation is about to occur.');
%
function mypostcallback(obj,evd)
newView = round(get(evd.Axes,'View'));
msgbox(sprintf('The new view is [%d %d].',newView));

Remarks

When enabled, rotate3d provides continuous rotation of axes and the objects it contains through mouse movement. A numeric readout appears in the lower left corner of the figure during rotation, showing the current azimuth and elevation of the axes. Releasing the mouse button removes the animated box and the readout. This differs from the camorbit function in that while the rotate3d tool modifies the View property of the axes, the cameraorbit function fixes the aspect ratio and modifies the CameraTarget, CameraPosition and CameraUpVector properties of the axes. See Axes Properties for more information.

You can also enable 3-D rotation from the figure Tools menu or the figure toolbar.

You can create a rotate3D mode object once and use it to customize the behavior of different axes, as example 3 illustrates. You can also change its callback functions on the fly.

When you assign different 3-D rotation behaviors to different subplot axes via a mode object and then link them using the linkaxes function, the behavior of the axes you manipulate with the mouse will carry over to the linked axes, regardless of the behavior you previously set for the other axes.

See Also

camorbit, pan, rotate, view, zoom

Object Manipulation for related functions

Axes Properties for related properties

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS