Main Content

rotate

Rotate object about specified origin and direction

    Description

    example

    Note

    hgtransform is recommended over rotate because it provides better performance. Consider using hgtransform unless you need to specify the origin of the axis of rotation.

    rotate(h,direction,angle) rotates the graphics object h in the specified direction by the specified number of degrees. rotate modifies the data of the graphics object, including the values of the Xdata, Ydata, and Zdata properties. This behavior is different from that of view and rotate3d, which modify only the viewpoint.

    example

    rotate(h,direction,angle,origin) specifies 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.

    Examples

    collapse all

    Create a surface plot of the peaks function and return the surface object.

    s = surf(peaks(20));
    xlabel("x-axis")
    ylabel("y-axis")
    zlabel("z-axis")
    axis([0 20 0 20 -10 10])

    Rotate the surface plot 25 degrees clockwise around its x-axis.

    direction = [1 0 0];
    rotate(s,direction,25)

    Create a surface plot of the peaks function and return the surface object.

    s = surf(peaks(20));
    xlabel("x-axis")
    ylabel("y-axis")
    zlabel("z-axis")
    axis([0 20 0 20 -10 10])

    Rotate the surface plot 25 degrees clockwise around its x-axis and y-axis.

    direction = [1 1 0];
    rotate(s,direction,25)

    Create a surface plot of the peaks function and return the surface object.

    s = surf(peaks(20));
    xlabel("x-axis")
    ylabel("y-axis")
    zlabel("z-axis")
    axis([0 20 0 20 -10 10])

    Rotate the surface plot 30 degrees counterclockwise around its y-axis, and set the origin of rotation to (20, 10, 0).

    s = surf(peaks(20));
    xlabel("x-axis")
    ylabel("y-axis")
    zlabel("z-axis")
    axis([0 20 0 20 -10 10])
    
    direction = [0 -1 0];
    origin = [20 10 0];
    rotate(s,direction,30,origin)

    Input Arguments

    collapse all

    Graphics object, specified as a single object or a vector of objects of one of these types:

    • Surface object

    • Patch object

    • Line object

    • Text object

    If h is a vector of objects, all objects must be children of the same axes.

    Note

    Image objects do not support 3-D data. Therefore, any rotation of an image out of the xy-plane is not supported.

    Direction of the axis of rotation, specified as a two-element vector of spherical coordinates ([theta phi]) or a three-element vector of Cartesian coordinates ([x y z]). Specify theta and phi in degrees.

    For more information about specifying direction, see Axis of Rotation.

    Example: rotate(h,[1 0 0],25) rotates the specified object clockwise around the x-axis.

    Example: rotate(h,[90 0],25) rotates the specified object clockwise around the y-axis.

    Angle of rotation, specified as a scalar value in degrees.

    Example: rotate(h,[1 0 0],25) rotates the specified object 25 degrees clockwise around the x-axis.

    Origin of the axis of rotation, specified as a three-element vector of Cartesian coordinates [x y z].

    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.

    More About

    collapse all

    Axis of Rotation

    The axis of rotation is defined by an origin of rotation and a direction vector or point P. For the rotate function, use the direction input argument to specify P as the spherical coordinates [theta phi] or as the Cartesian coordinates [x y z].

    In the two-element form for direction, theta is the angle in the xy-plane counterclockwise from the positive x-axis. phi is the elevation of the direction vector from the xy-plane.

    Cartesian axes displaying the location of point P relative to theta and phi

    The three-element form for direction specifies the Cartesian coordinates of point P. The axis of rotation follows the direction vector from the origin of rotation to P.

    Cartesian axes displaying the axis of rotation relative to an origin of rotation and point P

    Version History

    Introduced before R2006a