Main Content

intersect

Boolean intersection of 3-D geometries

Since R2025a

    Description

    g3 = intersect(g1,g2) returns the overlapping part of the 3-D geometries g1 and g2 as the combined geometry g3.

    Boolean intersection of a cube and a sphere resulting in a one-eighth piece of the sphere

    example

    In R2026a: g3 = intersect(gv) returns the Boolean intersection of all geometries specified by the vector gv. The resulting geometry g3 consists of points that belong to every geometry specified in gv.

    example

    Examples

    collapse all

    Find a Boolean intersection of a cylinder and a cuboid.

    Create and plot a hollow cylinder geometry.

    gcyl = multicylinder([3 4],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);

    Find the intersection of the geometries by using the Boolean intersection operation.

    g = intersect(gcyl,gcube);

    Plot the resulting geometry with cell labels.

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

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

    Since R2026a

    Intersect multiple cubes.

    Create a geometry representing a unit cube.

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

    Create a vector of geometries by rotating the cube by 30 and 60 degrees.

    angle = [0 30 60];
    for k = 1:numel(angle)
        gv(k) = rotate(gmcube,angle(k));
    end

    Find the intersection of the geometries specified in the vector.

    gm = intersect(gv);

    Plot the result.

    pdegplot(gm)

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

    The resulting geometry has one face wrapped around the side. To create a geometry with multiple faces, first create a triangulation object from the resulting geometry gm.

    tr = triangulation(gm);

    Convert the triangulation object back to an fegeometry object, and specify a small FeatureAngle value, such as, 15 degrees. The default value is 44 degrees.

    gm = fegeometry(tr,FeatureAngle=15);
    pdegplot(gm)

    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 or a vector of fegeometry objects.

    3-D geometry, specified as an fegeometry object or a vector of fegeometry objects.

    Since R2026a

    3-D geometries to intersect, specified as a vector of fegeometry objects.

    Output Arguments

    collapse all

    Combined geometry, returned as an fegeometry object.

    Limitations

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

    Tips

    • When creating a geometry, intersect uses the default threshold of 44 degrees for the dihedral angle between adjacent triangles. If the angle between the triangles exceeds the threshold, the edge becomes a topological (feature) edge separating two faces. If the angle does not exceed the threshold, intersect does not create a topological edge with two separate faces, unless the function can create the edge based on other criteria. Instead, intersect creates one face.

      To use a different feature angle value, create a triangulation object from the resulting geometry g3, and then convert the object back to an fegeometry object. Specify the value of the FeatureAngle argument as a number between 10 and 90. The specified FeatureAngle value represents degrees.

      tr = triangulation(g3);
      g3 = fegeometry(tr,FeatureAngle=15)

      The triangulation function accepts only single-domain geometries, so g3 must have one cell.

    Version History

    Introduced in R2025a

    expand all

    See Also

    Functions

    Objects