Main Content

Geometry and Mesh

Define a geometry and discretize it using a triangular or tetrahedral mesh

Reconstruct a geometry from STL or mesh data:

  • Import an STL file into MATLAB® by using importGeometry. The STL file format is very common and supported by most CAD software. In case of a planar STL geometry, the toolbox converts it to a 2-D geometry by mapping it to the X-Y plane.

  • Reconstruct a geometry from a mesh by using geometryFromMesh. This function works with triangulated meshes, including planar, volume, and surface triangulation that bounds a closed volume.

Create a geometry:

  • Stack or nest cubes, cylinders, or spheres to create a geometry for a 3-D problem.

  • Extrude a 2-D geometry into a 3-D geometry.

  • Use the constructive solid geometry (CSG) approach, write a geometry function, or use the polyshape function to create a geometry for a 2-D problem. The CSG approach uses a set of solid building blocks (square, rectangle, circle, ellipse, and polygon) and combines them to define complex geometries.

  • Use the PDE Modeler app to create complex 2-D geometries by drawing, overlapping, and rotating basic shapes, such as circles, polygons and so on.

Mesh a geometry by using the generateMesh function. The toolbox uses the finite element method (FEM) to solve PDEs. A PDE model stores the generated mesh as an FEMesh object in its Mesh property. For details, see Mesh Data.


expand all

Creation and Visualization

importGeometryImport 2-D or 3-D geometry from STL data
geometryFromMeshCreate 2-D or 3-D geometry from mesh
geometryFromEdgesCreate 2-D geometry from decomposed geometry matrix
decsgDecompose constructive solid 2-D geometry into minimal regions
multicuboidCreate geometry formed by several cubic cells
multicylinderCreate geometry formed by several cylindrical cells
multisphereCreate geometry formed by several spherical cells
pdegplotPlot PDE geometry


addCellCombine two geometries by adding one inside a cell of another
addFaceFill void regions in 2-D and split cells in 3-D geometry
addVertexAdd a vertex on a geometry boundary
addVoidCreate void regions inside 3-D geometry
rotateRotate geometry
scaleScale geometry
translateTranslate geometry
extrudeVertically extrude 2-D geometry or specified faces of 3-D geometry


cellEdgesFind edges attached to specified cells
cellFacesFind faces attached to specified cells
faceEdgesFind edges attached to specified faces
facesAttachedToEdgesFind faces attached to specified edges
nearestEdgeFind edges nearest to specified point
nearestFaceFind faces nearest to specified point

PDE Modeler App

pdecircDraw circle in PDE Modeler app
pdeellipDraw ellipse in PDE Modeler app
pdepolyDraw polygon in PDE Modeler app
pderectDraw rectangle in PDE Modeler app
generateMeshCreate triangular or tetrahedral mesh
meshQualityEvaluate shape quality of mesh elements
findElementsFind mesh elements in specified region
findNodesFind mesh nodes in specified region
areaArea of 2-D mesh elements
volumeVolume of 3-D mesh elements
pdemeshPlot PDE mesh
pdeplotPlot solution or mesh for 2-D problem
pdeplot3DPlot solution or surface mesh for 3-D problem
pdevizCreate and plot PDE visualization object


csgdelDelete boundaries between subdomains
pdearclInterpolation between parametric representation and arc length
wgeomWrite geometry function to file


adaptmeshCreate adaptive 2-D mesh and solve PDE
initmeshCreate initial 2-D mesh
meshToPet[p,e,t] representation of FEMesh data
jigglemesh(Not recommended) Jiggle internal points of triangular mesh
refinemeshRefine triangular mesh


AnalyticGeometry PropertiesAnalytic 2-D geometry description
DiscreteGeometry PropertiesDiscrete 2-D or 3-D geometry description
FEMesh PropertiesMesh object
PDEVisualization PropertiesPDE visualization of mesh and nodal results


PDE ModelerCreate complex 2-D geometries by drawing, overlapping, and rotating basic shapes



STL File Import

Import a 2-D or 3-D geometry from an STL file.

Geometry from Triangulated Mesh

Reconstruct a geometry from a tetrahedral mesh and from a planar multidomain mesh.

Geometry from polyshape

Reconstruct a geometry from a triangulated mesh created by the MATLAB polyshape function.

Geometry from alphaShape

Reconstruct a geometry from a triangulated surface mesh created by the MATLAB alphaShape function.

2-D Geometry Creation at Command Line

Use constructive solid geometry (CSG) modeling approach to combine basic shapes at the command line.

Parametrized Function for 2-D Geometry Creation

Create a 2-D geometry by using a parametrized function.

Cuboids, Cylinders, and Spheres

Create a 3-D geometry by stacking or nesting three basic volumes.

3-D Multidomain Geometry from 2-D Geometry

Extrude a 2-D geometry imported as an STL file into a 3-D geometry.

Multidomain Geometry Reconstructed from Mesh

Split a single-domain block geometry into two domains.

Sphere in Cube

Create a nested multidomain geometry consisting of a unit sphere and a cube.


Mesh Data

Recommended workflow uses FEMesh objects to represent meshes.

Generate Mesh

Adjust a mesh by using additional arguments of the generateMesh function.

Find Mesh Elements and Nodes by Location

Find mesh elements and nodes by their geometric location or proximity to a particular point or node.

Assess Quality of Mesh Elements

Evaluate the shape quality of mesh elements.

Legacy Mesh

Mesh Data as [p,e,t] Triples

Legacy workflow uses [p,e,t] triples to represent meshes.

Poisson's Equation with Point Source and Adaptive Mesh Refinement

Solve a Poisson's equation with a delta-function point source on the unit disk using the adaptmesh function.