Rotate object about specified origin and direction
The rotate function rotates a graphics object in three-dimensional space.
rotate(h,direction,alpha) rotates the graphics object h by alpha degrees. direction is a two- or three-element vector that describes the axis of rotation in conjunction with the origin of the axis of rotation. The default origin of the axis of rotation is the center of the plot box. This point is not necessarily the origin of the axes.
Positive alpha is defined as the righthand-rule angle about the direction vector as it extends from the origin of rotation.
If h is an array of handles, all objects must be children of the same axes.
Create a 2-by-2 set of surface plots and rotate them around their x and y axes.
figure sp11 = subplot(2,2,1); h11 = surf(sp11, peaks(20)); title('No Rotation') sp12 = subplot(2,2,2); h12 = surf(sp12, peaks(20)); title('Rotation Around X-Axis') zdir = [1 0 0]; rotate(h12,zdir,25) sp21 = subplot(2,2,3); h21 = surf(sp21, peaks(20)); title('Rotation Around Y-Axis') zdir = [0 1 0]; rotate(h21,zdir,25) sp22 = subplot(2,2,4); h22 = surf(sp22, peaks(20)); title('Rotation Around X- and Y-Axis') zdir = [1 1 0]; rotate(h22,zdir,25)
The axis of rotation is defined by an origin of rotation and a point P. Specify P as the spherical coordinates [theta phi] or as the Cartesian coordinates [xp,yp,zp].
In the two-element form for direction, theta is the angle in the x-y plane counterclockwise from the positive x-axis. phi is the elevation of the direction vector from the x-y plane.
The three-element form for direction specifies the axis direction using Cartesian coordinates. The direction vector is the vector from the origin of rotation to P.
rotate changes the values of the Xdata, Ydata, and Zdata properties to rotate graphics objects.