主要内容

transform

R2026b

Apply homogeneous transformation to mesh or scene object

Since R2026b

Description

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

transform(meshORsceneObj,T) applies the transformation T to the mesh or scene object meshORsceneObj. The transformation modifies the mesh vertices in-place and rotates by the rotation component of the matrix.

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);

Build a transform that rotates 90 degrees about the Y-axis and translates by [3 0 1].

Apply a custom 4-by-4 transformation matrix that combines rotation and translation in a single operation.

transformedMesh = copy(pyramidMesh);
angle = pi/2;
T = [cos(angle) 0 sin(angle) 3; 
    0           1 0          0; 
    -sin(angle) 0 cos(angle) 1; 
    0           0 0          1];
transform(transformedMesh,T)

Visualize the mesh with the custom transform applied compared to the original.

figure
subplot(1,2,1)
patch(pyramidMesh,EdgeColor="k")
axis equal
title("Raw Mesh")
subplot(1,2,2)
patch(transformedMesh,EdgeColor="k")
axis equal
title("Transformed Mesh")

Input Arguments

collapse all

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

Homogeneous transformation, specified as a 4-by-4 matrix or a rigidtform3d object. When specified as a 4-by-4 matrix, the upper-left 3-by-3 submatrix encodes rotation and scale, and the first three elements of the fourth column encode translation.

Data Types: double

Version History

Introduced in R2026b