Main Content

subtract

Boolean subtraction of one 3-D geometry from another

Since R2025a

    Description

    g3 = subtract(g1,g2) subtracts a 3-D geometry g2 from a 3-D geometry g1.

    Boolean subtraction of a sphere from a cube resulting in a cube with a cutout piece.

    example

    Examples

    collapse all

    Cut out a quarter of a sphere by subtracting a cube from it.

    Create and plot a geometry of a sphere.

    gsphere = multisphere(5);
    pdegplot(gsphere)

    Figure contains an axes object. The axes object contains 5 objects of type quiver, text, patch.

    Create and plot a geometry of a cuboid.

    gcube = multicuboid(5,5,10);
    gcube = translate(gcube,[2.5 -2.5 -5]);
    figure
    pdegplot(gcube)

    Figure contains an axes object. The axes object contains 6 objects of type quiver, text, patch, line.

    Convert both geometries to fegeometry objects.

    gsphere = fegeometry(gsphere);
    gcube = fegeometry(gcube);

    Subtract the cuboid from the sphere using the Boolean subtraction operation.

    g = subtract(gsphere,gcube);

    Plot the resulting geometry.

    figure
    pdegplot(g,CellLabels="on",FaceAlpha=0.3)

    Figure contains an axes object. The axes object contains 6 objects of type quiver, text, patch, line.

    Subtract a cube from a larger sphere by using the Boolean subtraction operation.

    Create and plot a geometry of a sphere.

    gsphere = multisphere(5);
    pdegplot(gsphere)

    Figure contains an axes object. The axes object contains 5 objects of type quiver, text, patch.

    Create and plot a geometry of a cube.

    gcube = multicuboid(6,6,6,Zoffset=-3);
    figure
    pdegplot(gcube)

    Figure contains an axes object. The axes object contains 6 objects of type quiver, text, patch, line.

    Convert both geometries to fegeometry objects.

    gsphere = fegeometry(gsphere);
    gcube = fegeometry(gcube);

    Subtract the cube from the sphere using the Boolean subtraction operation.

    g = subtract(gsphere,gcube);

    Plot the resulting geometry.

    figure
    pdegplot(g,CellLabels="on",FaceAlpha=0.3)

    Figure contains an axes object. The axes object contains 6 objects of type quiver, text, patch, line.

    Input Arguments

    collapse all

    3-D geometry, specified as an fegeometry object.

    3-D geometry, specified as an fegeometry object.

    Output Arguments

    collapse all

    Combined geometry, returned as an fegeometry object.

    Limitations

    • subtract works only on 3-D geometries. Use decsg to subtract 2-D geometries.

    Version History

    Introduced in R2025a

    See Also

    Functions

    Objects