主要内容

translate

R2026b

Translate mesh or scene object using translation vector

Since R2026b

Description

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

translate(meshORsceneObj,translation) translates the mesh or scene object meshORsceneObj by the specified translation vector translation.

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

Create a copy of the raw mesh.

translatedMesh = copy(pyramidMesh);

Shift the mesh 2 units along the X-axis.

translate(translatedMesh,[2 0 0])

Visualize the mesh shifted 2 units along the X-axis compared to the original position.

figure
subplot(1,2,1)
patch(pyramidMesh,EdgeColor="k")
axis equal
title("Position: [0 0 0]")
subplot(1,2,2)
patch(translatedMesh,EdgeColor="k")
axis equal
title("Position: [2 0 0]")

Input Arguments

collapse all

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

Translation vector, specified as a three-element row vector of the form [tx ty tz] representing the displacement along each axis.

Data Types: double

Version History

Introduced in R2026b

See Also

| | | |