union
Description
Examples
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")
Create and plot a single cuboid geometry.
gcube = multicuboid(sqrt(50),sqrt(50),10); pdegplot(gcube)

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)
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")
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")
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")
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")
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")
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")
Input Arguments
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.

Output Arguments
Merged geometry, returned as an fegeometry
            object.
Limitations
- unionworks only on 3-D geometries. Use- decsgto merge 2-D geometries.
Version History
Introduced in R2025a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
