Main Content

union

Boolean union of 3-D geometries

Since R2025a

    Description

    g3 = union(g1,g2) merges 3-D geometries g1 and g2 into one geometry g3.

    Boolean union of a cube and a sphere resulting in both geometries fused together.

    example

    g3 = union(g1,g2,KeepBoundaries=boundaries) specifies whether the function preserves the boundaries of the geometries when merging them.

    example

    Examples

    collapse all

    Merge geometries representing a cylinder and a cuboid into one geometry.

    Create and plot a hollow cylinder geometry.

    gcyl = multicylinder([4 5],10,Void=[true false]);
    pdegplot(gcyl,CellLabels="on")

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

    Create and plot a single cuboid geometry.

    gcube = multicuboid(sqrt(50),sqrt(50),10);
    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.

    gcyl = fegeometry(gcyl);
    gcube = fegeometry(gcube);

    Merge the geometries into one by using the Boolean union operation.

    g = union(gcyl,gcube);

    Plot the resulting geometry.

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

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

    Create a geometry representing a heat sink with the base plate and 12 cylindrical fins.

    First, create and plot a geometry of the base.

    gBase = multicuboid(0.01,0.008,0.0005);
    gBase = translate(gBase,[0.005,0.004,0]);
    gBase = fegeometry(gBase);
    pdegplot(gBase,CellLabels="on")

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

    Create a geometry representing one fin.

    gFin = multicylinder(0.0005,0.005);
    gFin = fegeometry(gFin);

    Now, create a geometry representing 12 fins by shifting the original fin to locations on top of the base and adding the fin to the geometry each time.

    g = fegeometry;
    for i = 0.002:0.002:0.008
       for j = 0.002:0.002:0.006
        gFinT = translate(gFin,[i,j,0.0005]);
        g = union(g,gFinT);
       end
    end

    Plot the fins.

    pdegplot(g,CellLabels="on")

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

    Merge the geometry of the base with the geometry of the fins by using the Boolean union operation.

    g = union(g,gBase);

    Plot the resulting heat sink geometry.

    pdegplot(g,CellLabels="on")

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

    Merge two cubes into one geometry while preserving the original boundaries.

    Create a geometry of a unit cube.

    g1 = fegeometry(multicuboid(1,1,1));

    Create the second cube by moving the original cube along the z-axis.

    g2 = translate(g1,[0 0 0.7]);

    Merge two geometries into one by using the Boolean union operation. By default, the union function does not preserve any boundaries that become internal in the merged geometry. Plot the resulting geometry.

    g = union(g1,g2);
    pdegplot(g,FaceAlpha=0.3,CellLabels="on")

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

    Merge the same two geometries, but this time use the KeepBoundaries argument to preserve all boundaries of both geometries. Plot the resulting geometries.

    g = union(g1,g2,KeepBoundaries=[true true]);
    pdegplot(g,FaceAlpha=0.3,CellLabels="on")

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

    Merge the geometries again. This time, specify that the merged geometry must preserve all boundaries of the second geometry (g2) but not the boundaries of the first geometry (g1) that become internal in the merged geometry. Plot the resulting geometry.

    g = union(g1,g2,KeepBoundaries=[false true]);
    pdegplot(g,FaceAlpha=0.3,CellLabels="on")

    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.

    Geometry boundaries to preserve, specified as a vector of two logical values. The values indicate whether the boundaries of the geometries g1 and g2 must appear in the merged geometry g3. For example, KeepBoundaries=[false true] specifies that the merged geometry must preserve all boundaries of the second geometry (g2) but not the boundaries of the first geometry (g1) that become internal in the merged geometry.

    Merging a square and a circle by default results in a geometry without inner boundaries. Merging the same shapes while keeping the circle boundary results in a geometry with an inner boundary.

    Output Arguments

    collapse all

    Merged geometry, returned as an fegeometry object.

    Limitations

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

    Version History

    Introduced in R2025a

    See Also

    Functions

    Objects