Main Content

extrude

R2026b

Extrude 2-D geometry or specified faces of 3-D geometry

    Description

    h = extrude(g,height) creates a 3-D discrete geometry by extruding a 2-D geometry along the z-axis by the value of height. You can create a stacked multilayered 3-D discrete geometry by specifying height as a vector of thicknesses of the layers.

    example

    h = extrude(g,height,Name=Value) extrudes a 2-D geometry using additional options specified by one or more name-value arguments. For example, you can specify a scaling factor and a twist angle for the extrusion. (since R2026b)

    example

    h = extrude(g,FaceID,height) extrudes specified faces of a 3-D geometry along the direction normal to the faces. Here, FaceID specifies which faces to extrude. You can extrude faces into multiple layers by specifying height as a vector of thicknesses of the layers.

    All of the specified faces must be flat and have the same orientation. The extruded volumes must not intersect with each other or with the existing geometry.

    example

    Examples

    collapse all

    Create a 3-D geometry by extruding a 2-D geometry along the z-axis.

    Import a 2-D geometry.

    g = fegeometry("PlateHolePlanar.stl");

    Plot the geometry and display the face labels.

    pdegplot(g,FaceLabels="on")

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

    Create a 3-D geometry by extruding the 2-D geometry along the z-axis by 5 units.

    g = extrude(g,5)
    g = 
      fegeometry with properties:
    
            NumCells: 1
            NumFaces: 7
            NumEdges: 15
         NumVertices: 10
            Vertices: [10×3 double]
        FeatureAngle: []
                Mesh: []
    
    

    Plot the new geometry and display the face labels.

    pdegplot(g,FaceLabels="on",FaceAlpha=0.5)

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

    Create a stacked multilayered 3-D geometry by extruding a 2-D geometry along the z-axis.

    Import a geometry.

    g = fegeometry("PlateHolePlanar.stl")
    g = 
      fegeometry with properties:
    
            NumCells: 0
            NumFaces: 1
            NumEdges: 5
         NumVertices: 5
            Vertices: [5×3 double]
        FeatureAngle: []
                Mesh: []
    
    

    Plot the geometry and display the face labels.

    pdegplot(g,FaceLabels="on")

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

    Create a 3-D geometry consisting of three blocks with holes stacked on top of each other. The heights of the blocks are 5, 10, and 20 units.

    g = extrude(g,[5,10,20])
    g = 
      fegeometry with properties:
    
            NumCells: 3
            NumFaces: 19
            NumEdges: 35
         NumVertices: 20
            Vertices: [20×3 double]
        FeatureAngle: []
                Mesh: []
    
    

    Plot the new geometry and display the cell labels.

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

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

    Extrude a 2-D geometry that has a vertex added by the addVertex function. The layers of the extruded geometry all have a corresponding vertex, but there are no edges between these vertices.

    Import a geometry.

    g = fegeometry("PlateHolePlanar.stl");

    Plot the geometry and display the vertex labels.

    pdegplot(g,VertexLabels="on")

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

    Add a new vertex on the right edge.

    g = addVertex(g,Coordinates=[10 12]);

    Plot the new geometry and display the vertex labels.

    pdegplot(g,FaceLabels="on",VertexLabels="on")

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

    Create a 3-D geometry consisting of three blocks with holes stacked on top of each other. The heights of the blocks are 5, 10, and 20 units.

    g = extrude(g,[5,10,20])
    g = 
      fegeometry with properties:
    
            NumCells: 3
            NumFaces: 19
            NumEdges: 35
         NumVertices: 24
            Vertices: [24×3 double]
        FeatureAngle: []
                Mesh: []
    
    

    Plot the new geometry and display the vertex labels. The extrude function replicates the added vertex V6 into three new vertices: V12, V18, and V24. It does not create edges between these vertices.

    pdegplot(g,VertexLabels="on",FaceAlpha=0.5)

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

    Extrude a 2-D geometry that has a face added by the addFace function.

    Import a geometry.

    g = importGeometry("PlateHolePlanar.stl");

    Plot the geometry and display the face and edge labels.

    pdegplot(g,FaceLabels="on",EdgeLabels="on")

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

    Fill the hole in the center by adding a face.

    g = addFace(g,5)
    g = 
      DiscreteGeometry with properties:
    
           NumCells: 0
           NumFaces: 2
           NumEdges: 5
        NumVertices: 5
           Vertices: [5×3 double]
    
    

    Plot the modified geometry.

    pdegplot(g,FaceLabels="on")

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

    Create a 3-D geometry by extruding the 2-D geometry along the z-axis by 2 units.

    g = extrude(g,2)
    g = 
      DiscreteGeometry with properties:
    
           NumCells: 2
           NumFaces: 9
           NumEdges: 15
        NumVertices: 10
           Vertices: [10×3 double]
    
    

    Plot the new geometry and display the cell labels.

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

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

    Since R2026b

    Create a 2-D geometry by combining multiple unit squares and then subtracting a unit circle from the resulting geometry. Plot the 2-D geometry.

    gmsquare = fegeometry(@squareg);
    angle = [0 30 60];
    for k = 1:numel(angle)
        gv(k) = rotate(gmsquare,angle(k));
    end
    gmcircle = fegeometry(@circleg);
    gm = subtract(union(gv),gmcircle);
    pdegplot(gm)

    2-D star-shaped geometry with a circular hole at the center

    Extrude the 2-D geometry into a 3-D geometry, tapering the extrusion so that the top face of the resulting 3-D geometry is half the size of its bottom face.

    gm3D = extrude(gm,2,Taper=0.5);

    Plot the result.

    pdegplot(gm3D)

    Extruded 3-D geometry tapered to half size at the top

    To remove the edge on the inner side of the resulting geometry, set the FeatureAngle property of the geometry to 50.

    gm3D.FeatureAngle = 50;
    pdegplot(gm3D)

    Tapered 3-D geometry with inner edge removed using FeatureAngle

    Now extrude the geometry so that the top face of the resulting 3-D geometry is twice the size of its bottom face.

    gm3D = extrude(gm,2,Taper=2);
    gm3D.FeatureAngle = 50;
    pdegplot(gm3D)

    Extruded 3-D geometry tapered to twice the size at the top

    You can also shrink the top face to a single point by setting the Taper value to 0.

    gm3D = extrude(gm,2,Taper=0);
    pdegplot(gm3D)

    Extruded 3-D geometry tapered to a point at the top

    Extrude the 2-D geometry into a 3-D geometry and add a twist of 45 degrees to the extrusion.

    gm3D = extrude(gm,2,Twist=45);
    gm3D.FeatureAngle = 50;
    pdegplot(gm3D)

    Extruded 3-D geometry with a 45-degree twist

    Extrude the geometry and add both tapering and twisting.

    gm3D = extrude(gm,2,Twist=45,Taper=0.5);
    gm3D.FeatureAngle = 50;
    pdegplot(gm3D)

    Extruded 3-D geometry with both tapering and a 45-degree twist

    Extrude specified faces of a 3-D geometry.

    Import the geometry and plot it with the face and edge labels.

    g = fegeometry("PlateHolePlanar.stl");
    pdegplot(g,FaceLabels="on",EdgeLabels="on")

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

    Fill the hole in the center by adding a face. Plot the modified geometry.

    g = addFace(g,5);
    pdegplot(g,FaceLabels="on")

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

    Create a 3-D geometry by extruding the 2-D geometry along the z-axis by 2 units.

    g = extrude(g,2);

    Plot the new geometry with the cell and face labels.

    pdegplot(g,CellLabels="on",Facelabels="on",FaceAlpha=0.5)

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

    Now, extrude the center face of the geometry by 5 units.

    g = extrude(g,4,5);

    Plot the resulting geometry with the cell labels.

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

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

    Now, call extrude again, and this time specify a vector of heights. The function extrudes all specified faces by each of the specified heights, which creates multiple layers.

    g = extrude(g,[1 2],[3 4]);
    pdegplot(g,CellLabels="on",FaceAlpha=0.5)

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

    Input Arguments

    collapse all

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

    Cell heights, specified as a positive real number or a vector of positive real numbers.

    If height is a vector and g is a 2-D geometry, then height(i) specifies the height of the ith layer of a multilayered (stacked) 3-D geometry. Each layer constitutes a new cell.

    If g is a 3-D geometry, the function extrudes all specified faces into several layers, with height(i) specifying the height of the ith layer.

    Example: extrude(g,5.5)

    Faces to extrude in 3-D geometry, specified as a positive real number or a vector of positive real numbers. If height is a vector, then the function extrudes all specified faces into several layers, same as it does for 2-D geometries.

    Name-Value Arguments

    collapse all

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: gm = extrude(gm,2,Twist=90) extrudes the 2-D geometry by 2 and adds a twist of 90 degrees to the extrusion.

    Since R2026b

    Scaling factor for the linear extrusion, specified as a nonnegative number. The value determines how much to scale the top face of the extrusion compared to the bottom face. If the value is 1, the top and bottom faces are the same size. The value 0 shrinks the top face to a single point along the z-direction, and enables you to construct cones and pyramids.

    Example: Taper=0.5

    Data Types: double

    Since R2026b

    Twist angle for linear extrusion, specified as a real number. The value specifies the twist angle in degrees. When viewed from above, the twist goes counterclockwise as you extrude from the bottom to the top.

    Example: Twist=90

    Data Types: double

    Output Arguments

    collapse all

    Resulting geometry, returned as an fegeometry object or a handle.

    • If the original geometry g is an fegeometry object, then h is a new fegeometry object representing the modified geometry. The original geometry g remains unchanged.

    • If the original geometry g is a DiscreteGeometry object, then h is a handle to the modified DiscreteGeometry object g.

    • If g is an AnalyticGeometry object, then h is a handle to a new DiscreteGeometry object. The original geometry g remains unchanged.

    Tips

    • After modifying a geometry, regenerate the mesh to ensure a proper mesh association with the new geometry.

    • If a 2-D geometry has new vertices added by using the addVertex function, extrude replicates the new vertices on each new layer of the extruded 3-D geometry, but it does not connect these vertices by edges.

    • If g is an fegeometry or AnalyticGeometry object, and you want to replace it with the modified geometry, assign the output to the original geometry, for example, g = extrude(g,20).

    • Only 2-D geometry extrusion supports the Taper and Twist name-value arguments.

    Version History

    Introduced in R2020b

    expand all