主要内容

rotate

R2026b

Rotate mesh or scene object

Since R2026b

Description

Add-On Required: This feature requires the 3D Asset Processing Library for MATLAB add-on.

rotate(meshORsceneObj,angles) rotates the mesh or scene object meshORsceneObj by the specified Euler angles angles in radians.

rotate(meshORsceneObj,axis,angle) rotates the mesh or scene object meshORsceneObj by angle radians about the direction vector axis.

rotate(meshORsceneObj,angles,Name=Value) rotates the mesh or scene object meshORsceneObj using one or more name-value arguments. For example, Sequence="ZYX" rotates the mesh using the ZYX rotation sequence. You can use name-value arguments only with the first syntax with input Euler angles angles.

example

Examples

collapse all

Define a simple pyramid with 5 vertices and 6 triangular faces.

vertices = [0 0 0; 1 0 0; 1 1 0; 0 1 0; 0.5 0.5 1];
faces = [1 2 5; 2 3 5; 3 4 5; 4 1 5; 1 3 4; 1 2 3];

Create a mesh with per-face color.

faceColors = uint8([230 50  50;    % red - front
                    50  180 50;    % green - right
                    50  100 230;   % blue - back
                    230 180 25;    % yellow - left
                    150 75  200;   % purple - bottom 1
                    25  200 200]); % cyan - bottom 2
pyramidMesh = asset3d.Mesh(vertices,faces,FaceColors=faceColors);

Rotate mesh 45 degrees about the Z-axis.

rotatedMesh = copy(pyramidMesh);
rotate(rotatedMesh,[0 0 pi/4])

Visualize the mesh rotated 45 degrees about the Z-axis compared to no rotation.

figure
subplot(1,2,1)
patch(pyramidMesh,EdgeColor="k")
axis equal
title("Angles: [0 0 0]")
subplot(1,2,2)
patch(rotatedMesh,EdgeColor="k")
axis equal
title("Angles: [0 0 pi/4]")

Input Arguments

collapse all

Source mesh or scene, specified as a Mesh object or Scene object.

Euler angles in radians, specified as a three-element row vector of the form [rx ry rz].

Data Types: double

Rotation axis direction vector, specified as a three-element row vector of the form [x y z]. The mesh or scene is rotated about this axis by angle radians.

Data Types: double

Rotation angle in radians, specified as a scalar.

Data Types: double

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: rotate(mesh,[0 pi/2 0],Sequence="ZYX") rotates the mesh using the ZYX rotation sequence.

Rotation sequence, specified as a string indicating the order of axis rotations. For example, "XYZ", "ZYX", and "YXZ".

Data Types: char | string

Rotation type convention, specified as one of these values:

"point" — Extrinsic rotation, specifies rotations about fixed axes.

"frame" — Intrinsic rotation, specifies rotations about body-attached axes.

Data Types: char | string

Version History

Introduced in R2026b