主要内容

intersect

R2026b

Boolean intersection of geometries

Since R2025a

    Description

    g3 = intersect(g1,g2) returns the overlapping part of the 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

    All geometries must be either 2-D or 3-D. The function does not support a mix of 2-D and 3-D geometries.

    example

    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. (since R2026a)

    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.

    Since R2026b

    Find a Boolean intersection of a square and a circle.

    Create and plot the geometries of a square and a circle.

    gsquare = fegeometry(@squareg);
    gcircle = fegeometry(@circleg);
    gcircle = translate(gcircle,[0 0.5]);
    pdegplot(gsquare)
    hold on
    pdegplot(gcircle)
    hold off

    Figure contains an axes object. The axes object contains 2 objects of type line.

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

    g = intersect(gsquare,gcircle);

    Plot the resulting geometry.

    pdegplot(g)

    Figure contains an axes object. The axes object contains an object of type line.

    Input Arguments

    collapse all

    Geometry, specified as an fegeometry object, DiscreteGeometry object, AnalyticGeometry object, or a vector of fegeometry, DiscreteGeometry, or AnalyticGeometry objects.

    Geometry, specified as an fegeometry object, DiscreteGeometry object, AnalyticGeometry object, or a vector of fegeometry, DiscreteGeometry, or AnalyticGeometry objects.

    Since R2026a

    Geometries to intersect, specified as a vector of fegeometry, DiscreteGeometry, or AnalyticGeometry objects.

    Output Arguments

    collapse all

    Combined geometry, returned as an fegeometry object. Note that intersect returns an fegeometry object when input arguments are AnalyticGeometry or DiscreteGeometry objects.

    Tips

    • When creating a 3-D 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.

    • Boolean operations on AnalyticGeometry or DiscreteGeometry objects return an fegeometry object.

    Version History

    Introduced in R2025a

    expand all