Main Content

rotate

Rotate surface mesh

Since R2022b

    Description

    rotate(mesh,"rotmat",rotMatrix) rotates the surface mesh mesh around its origin by the values specified in the rotation matrix rotMatrix.

    example

    rotate(mesh,"euler",E,rotSequence) rotates the surface mesh mesh around its origin using the Euler angles specified by the Euler vector E in the sequence of rotation rotSequence.

    example

    rotate(mesh,"quaternion",quat) rotates the surface mesh mesh around its origin using the values specified by the quaternion array quat.

    example

    rotate(___,pivot) specifies a pivot point around which to rotate the surface mesh, in addition to any combination of input arguments from the previous syntaxes.

    Examples

    collapse all

    Define mesh vertices for a surface mesh.

    vertices = [1 -1  1; 1 1 1; -1 1 1; -1 -1 1; ...
                1 -1 -1; 1 1 -1; -1 1 -1; -1 -1 -1];

    Define the mesh faces using the vertices.

    faces = [6 2 1; 1 5 6; 8 4 3; 3 7 8; 6 7 3; 3 2 6; ...
             5 1 4; 4 8 5; 4 1 2; 2 3 4; 7 6 5; 5 8 7];

    Create and display the surface mesh.

    mesh = surfaceMesh(vertices,faces);
    surfaceMeshShow(mesh,Title="Original Mesh")

    Define the Euler angles and rotation sequence for rotating the surface mesh about the z-axis by 30 degrees.

    eulerAngles = [30 0 0];
    rotSequence = "ZYX";

    Rotate the surface mesh and display the output.

    rotate(mesh,"euler",eulerAngles,rotSequence)
    surfaceMeshShow(mesh,Title="Rotated Mesh")

    Define mesh vertices for a surface mesh.

    vertices = [1 -1  1; 1 1 1; -1 1 1; -1 -1 1; ...
                1 -1 -1; 1 1 -1; -1 1 -1; -1 -1 -1];

    Define the mesh faces using the vertices.

    faces = [6 2 1; 1 5 6; 8 4 3; 3 7 8; 6 7 3; 3 2 6; ...
             5 1 4; 4 8 5; 4 1 2; 2 3 4; 7 6 5; 5 8 7];

    Create and display the surface mesh.

    mesh = surfaceMesh(vertices,faces);
    surfaceMeshShow(mesh,Title="Original Mesh")

    Define the quaternion array for rotatating the surface mesh about the y-axis by 60 degrees,

    eulerAngles = [60 0 0];
    quat = quaternion(eulerAngles,'eulerd','YZX','point');

    Rotate surface mesh and display the output.

    rotate(mesh,"quaternion",quat);
    surfaceMeshShow(mesh,Title="Rotated Mesh")

    Define mesh vertices for a surface mesh.

    vertices = [1 -1  1; 1 1 1; -1 1 1; -1 -1 1; ...
                1 -1 -1; 1 1 -1; -1 1 -1; -1 -1 -1];

    Define the mesh faces using the vertices.

    faces = [6 2 1; 1 5 6; 8 4 3; 3 7 8; 6 7 3; 3 2 6; ...
             5 1 4; 4 8 5; 4 1 2; 2 3 4; 7 6 5; 5 8 7];

    Create and display the surface mesh.

    mesh = surfaceMesh(vertices,faces);
    surfaceMeshShow(mesh,Title="Original Mesh")

    Define the pivot point for rotation.

    pivot = [-1 -1 0];

    Define a rotation matrix for rotating the surface mesh by 45 degrees about the z-axis.

    rotMatrix = [cosd(45)  -sind(45)  0;
                 sind(45)  cosd(45)   0;
                   0          0       1];

    Rotate the surface mesh about the pivot point and display the rotated mesh.

    rotate(mesh,"rotmat",rotMatrix,pivot);
    surfaceMeshShow(mesh,Title="Rotated Mesh");

    Input Arguments

    collapse all

    Surface mesh, specified as a surfaceMesh object.

    Rotation matrix, specified as a 3-by-3 matrix.

    Euler angles, specified as a three-element vector. The values of the vector are in degrees.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Sequence of rotation, specified as a character vector or string scalar. You can specify one of these options.

    • "YZY"

    • "YXY"

    • "ZYZ"

    • "ZXZ"

    • "XYX"

    • "XZX"

    • "XYZ"

    • "YZX"

    • "ZXY"

    • "XZY"

    • "ZYX"

    • "YXZ"

    For example, when you specify the sequence as "YZX", the function first rotates the mesh about the y-axis, then the about new z-axis, followed by the new x-axis. E defines the angles of rotation.

    Data Types: char | string

    Quaternion array for 3-D axes rotation, specified as a quaternion (Sensor Fusion and Tracking Toolbox) object.

    Pivot point about which to rotate the mesh, specified as a three-element vector. The values of the vector specify the x-, y-, and z-coordinates of the pivot point. The function first shifts the origin to the pivot point, then rotates the mesh, and lastly shifts the origin back to the original position.

    Version History

    Introduced in R2022b