主要内容

transform

R2026b

Transform geometric models between coordinate frames

Since R2026b

    Description

    modelOut = transform(modelIn,tform) transforms the input model modelIn by applying the specified transformation tform, and returns the transformed model modelOut. The function does not modify the input model.

    example

    Examples

    collapse all

    Read a point cloud and select a region of interest (ROI) to focus on a subset of the scene.

    ptCloud = pcread("highwayScene.pcd");
    roi = [-30 30 -20 30 -8 13];
    
    indices = findPointsInROI(ptCloud,roi);
    ptCloud = select(ptCloud,indices);

    Fit a cuboid model to a smaller region that contains an object within the selected point cloud.

    cuboidROI = [9.6 13.8 7.9 9.3 -2.5 3];
    sampleIndices = findPointsInROI(ptCloud,cuboidROI);
    model = pcfitcuboid(ptCloud,sampleIndices);

    Create a rigid transformation that rotates the model about the z‑axis and translates it along the x-axis.

    angles = [0 0 20];
    translation = [3 0 0];
    tform = rigidtform3d(angles,translation);

    Apply the transformation to the cuboid model. To visualize the cuboid model in the transformed coordinate frame, apply the same transformation to the point cloud.

    transformedModel = transform(model,tform);
    transformedPtCloud = pctransform(ptCloud,tform);

    Visualize the original cuboid model overlaid on the original point cloud.

    figure
    pcshow(ptCloud)
    hold on
    plot(model,Color="green")
    xlabel("X(m)")
    ylabel("Y(m)")
    zlabel("Z(m)")
    title("Original Cuboid Model")

    Figure contains an axes object. The axes object with title Original Cuboid Model, xlabel X(m), ylabel Y(m) contains 2 objects of type scatter, patch.

    Visualize the transformed cuboid model overlaid on the transformed point cloud.

    figure
    pcshow(transformedPtCloud)
    hold on
    plot(transformedModel,Color="red")
    xlabel("X(m)")
    ylabel("Y(m)")
    zlabel("Z(m)")
    title("Transformed Cuboid Model")

    Figure contains an axes object. The axes object with title Transformed Cuboid Model, xlabel X(m), ylabel Y(m) contains 2 objects of type scatter, patch.

    Input Arguments

    collapse all

    Geometric model to transform, specified as a cuboidModel, planeModel, cylinderModel, or sphereModel object.

    Three-dimensional transformation, specified as a rigidtform3d, simtform3d, or transltform3d object.

    Output Arguments

    collapse all

    Transformed geometric model, returned as a cuboidModel, planeModel, cylinderModel, or sphereModel object. The output model has the same object type as the input model.

    Extended Capabilities

    expand all

    C/C++ Code Generation
    Generate C and C++ code using MATLAB® Coder™.

    GPU Code Generation
    Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

    Version History

    Introduced in R2026b

    See Also

    Objects

    Functions