discretizes a 2D or 3D graphic g into a MeshRegion.
DiscretizeGraphics[g,patt]
discretizes only the elements in g that match the pattern patt.
DiscretizeGraphics
discretizes a 2D or 3D graphic g into a MeshRegion.
DiscretizeGraphics[g,patt]
discretizes only the elements in g that match the pattern patt.
Details and Options
- DiscretizeGraphics discretizes graphics into a disjoint union of piecewise linear cells used in MeshRegion.
- The graphic g can be Graphics, Graphics3D, or individual graphics primitives.
- DiscretizeGraphics effectively treats multiple primitives in Graphics and Graphics3D as a union operation.
- The discretization is exact when g contains only bounded piecewise linear primitives; otherwise, it is an approximation.
- Bounded piecewise linear primitives in Graphics (these can be represented exactly):
-
Point[…] point (0D) Line[…] line (1D) Triangle[…] filled triangle (2D) Polygon[…] filled polygon (2D) Rectangle[…] filled rectangle (2D) Parallelogram[…] filled parallelogram (0D, 1D, or 2D) Simplex[…] simplex (0D, 1D, or 2D) - In addition, SSSTriangle, SASTriangle, ASATriangle, and AASTriangle evaluate to Triangle and can be represented exactly.
- Unbounded piecewise linear primitives in Graphics (only a finite range can be represented):
-
HalfLine[…] half-line or ray (1D) InfiniteLine[…] infinite line (1D) HalfPlane[…] half-space (2D) ConicHullRegion[…] linear cone (0D, 1D, or 2D) - Nonlinear primitives in Graphics (only an approximation can be represented):
-
Circle[…] circle, ellipse, sectors (1D) Disk[…] disk, filled ellipse, sectors (2D) BezierCurve[…] Bezier spline curve (1D) BSplineCurve[…] B-spline curve (1D) JoinedCurve[…] joined curve segments (1D) FilledCurve[…] filled closed curve (2D) - In addition, Circumsphere evaluates to Sphere and can be represented approximately.
- Bounded piecewise linear primitives in Graphics3D (these can be represented exactly):
-
Point[…] point (0D) Line[…] line (1D) Triangle[…] filled triangle (2D) Polygon[…] filled polygon (2D) Cuboid[…] filled cuboid (3D) Parallelepiped[…] filled parallelepiped (0D, 1D, 2D, or 3D) Tetrahedron[…] filled tetrahedron (3D) Hexahedron[…] filled hexahedron (3D) Pyramid[…] filled pyramid (3D) Prism[…] filled prism (3D) Simplex[…] simplex (0D, 1D, 2D, or 3D) - Unbounded piecewise linear primitives in Graphics3D (only a finite range can be represented):
-
HalfLine[…] half-line or ray (1D) InfiniteLine[…] infinite line (1D) HalfPlane[…] plane bounded in one direction (2D) InfinitePlane[…] infinite plane (3D) ConicHullRegion[…] linear cone (0D, 1D, 2D, or 3D) - Nonlinear primitives in Graphics3D (only an approximation can be represented):
-
BezierCurve[…] Bezier curve (1D) BSplineCurve[…] B-spline curve (1D) JoinedCurve[…] joined curve segments (1D) BSplineSurface[…] B-spline surface (2D) Sphere[…] sphere (2D) Ball[…] ball or filled sphere (3D) Ellipsoid[…] filled ellipsoid (3D) Cylinder[…] filled cylinder (3D) Cone[…] filled cone (3D) - In addition, Circumsphere evaluates to Sphere and can be represented approximately.
- DiscretizeGraphics has the same options as MeshRegion, with the following additions and changes:
-
AccuracyGoal Automatic digits of accuracy sought MaxCellMeasure Automatic maximum cell measure MeshQualityGoal Automatic quality goal for mesh cells Method Automatic method to use MeshRefinementFunction None function that returns True if a mesh cell needs refinement PlotRange Automatic the range to include PerformanceGoal $PerformanceGoal whether to consider speed or quality PrecisionGoal Automatic digits of precision sought - With AccuracyGoal->a and PrecisionGoal->p, an attempt will be made to keep the maximum distance between the region reg or the discretized region dreg and any point in RegionSymmetricDifference[reg,dreg] to less than
, where
is the length of the diagonal of the plot range.
Examples
open all close allBasic Examples (3)
Discretize a 2D special region including Circle:
DiscretizeGraphics[Graphics[{Circle[]}]]DiscretizeGraphics[Graphics[{Parallelogram[{0, 0}, {{1, 1}, {1, 0}}]}]]Discretize 3D special regions including Cone:
DiscretizeGraphics[Graphics3D[{Cone[]}]]DiscretizeGraphics[Graphics3D[{Prism[{{1, 0, 1}, {0, 0, 0}, {2, 0, 0}, {1, 2, 1}, {0, 2, 0}, {2, 2, 0}}]}]]Discretize a whole 2D Graphics scene, where multiple primitives are taken as a union:
DiscretizeGraphics[[image]]Area[%]Scope (16)
Graphics (9)
Discretize a 2D special region including Circle:
DiscretizeGraphics[Graphics[{Circle[]}]]DiscretizeGraphics[Graphics[{Parallelogram[{0, 0}, {{1, 1}, {1, 0}}]}]]Discretize Graphics with GraphicsComplex containing Point, Line, and Polygon:
v = {{0, 0}, {3, 0}, {3, 3}, {0, 3}};g = Graphics /@ {GraphicsComplex[v, Point[{1, 2, 3, 4}]], GraphicsComplex[v, Line[{1, 2, 3, 4, 1}]], GraphicsComplex[v, Polygon[{1, 2, 3, 4}]]}DiscretizeGraphics /@ gDiscretize Graphics with GraphicsComplex containing Rectangle, Circle, and Disk:
v = {{0, 0}, {2, 0}, {2, 2}, {0, 2}};g = Graphics /@ {GraphicsComplex[v, Rectangle /@ {1, 2, 3, 4}], GraphicsComplex[v, Circle /@ {1, 2, 3, 4}], GraphicsComplex[v, Disk /@ {1, 2, 3, 4}]}DiscretizeGraphics /@ gDiscretize only those primitives that match a pattern:
g = Graphics[{Brown, Disk[{-1, 0}, 2], LightBlue, Rectangle[{0, -2}, {4, 2}], Red, Point[{6, 1}], Circle[{5, 0}, 2], Line[{{-4, 0}, {8, 0}}]}]DiscretizeGraphics[g, _Circle | _Rectangle]Discretize primitives with dimension less than 2:
DiscretizeGraphics[g, x_ /; RegionDimension[x] < 2]Discretize All primitives:
DiscretizeGraphics[g, All]Bounded piecewise linear Graphics primitives can be represented exactly:
g = Graphics[{Orange, Triangle[{{-1, 1}, {0, 2}, {1, 1}}], Blue, Rectangle[{-1, 0}], Yellow, Simplex[2], Brown, Parallelogram[{2, 0}, {{-1, 0}, {-1, 1}}], Purple, Polygon[{{2, 1}, {4, 0}, {3, 1}, {4, 2}}]}]DiscretizeGraphics[g]Unbounded piecewise linear Graphics primitives can only be represented within a finite range:
p = {InfiniteLine[{0, 0}, {1, 1}], HalfLine[{0, 0}, {-1, 1}], HalfPlane[{{1, 0}, {2, 1}}, {1, -1}], ConicHullRegion[{{-1, 0}}, {{-1, -1}, {-1, 1}}]};g = Graphics[p, PlotRange -> {{-3, 3}, {-1.5, 1.5}}]DiscretizeGraphics[g]Nonlinear Graphics primitives can only be approximately represented:
g = Graphics[{BSplineCurve[{{0, 0}, {1, -1}, {2, -1}, {3, 0}, {4, -2}, {5, 0}}], Circle[{2, 1}]}]DiscretizeGraphics[g]Graphics involving GraphicsComplex:
v = Table[15{Cos[t], Sin[t]}, {t, 0, 4Pi, 4Pi / 5}];g = Graphics[GraphicsComplex[v, {Orange, Line[{1, 4, 2, 5, 3, 1}], Polygon[{1, 2, 3, 4, 5}]}]]DiscretizeGraphics[g]Use MaxCellMeasure to control the level of discretization:
g = Graphics[{Disk[{0, 0}], Circle[{1, 0}]}]Table[DiscretizeGraphics[g, MaxCellMeasure -> {"Length" -> m}], {m, {0.9, 0.6, 0.3}}]Graphics3D (7)
Discretize 3D special regions including Cone:
DiscretizeGraphics[Graphics3D[{Cone[]}]]DiscretizeGraphics[Graphics3D[{Prism[{{1, 0, 1}, {0, 0, 0}, {2, 0, 0}, {1, 2, 1}, {0, 2, 0}, {2, 2, 0}}]}]]Discretize Graphics3D with GraphicsComplex containing Point, Line, and Polygon:
v = {{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}};
i = {{1, 2, 5}, {2, 3, 5}, {3, 4, 5}, {4, 1, 5}};g = Graphics3D /@ {GraphicsComplex[v, {PointSize@Large, Point[Range@5]}], GraphicsComplex[v, Line[i]], GraphicsComplex[v, Polygon[i]]}DiscretizeGraphics /@ gDiscretize a whole Graphics3D scene, where multiple primitives are taken as a union:
DiscretizeGraphics[[image]]Volume[%]Discretize only those primitives that match a pattern:
p = {Point[Tuples[{0, 1}, 3]], Table[Line[{{x, -0.5, 0}, {x, -2, 0}}], {x, 2, 6}],
Triangle[{{6, 0, 0}, {4.5, 0, 0}, {5, 2, 0}}], Cone[{{3, 1, 0}, {3, 1, 2}}]};g = Graphics3D[p, Boxed -> False]DiscretizeGraphics[g, _Line | _Cone]Discretize primitives with dimension less than 2:
DiscretizeGraphics[g, x_ /; RegionDimension[x] < 2]Discretize All primitives:
DiscretizeGraphics[g, All]Bounded piecewise linear Graphics3D primitives can be represented exactly:
p = {Point[{-3, 0, 0}], Line[{{-2.5, 0, 0}, {-1.5, 0, 0}}], Triangle[{{-1.2, 0, 0}, {-0.5, 0, 0}, {-1, 1, 0}}], Parallelepiped[{0, 0, 0}, {{1, 0, 0}, {1, 1, 0}, {0, 1, 1}}]};g = Graphics3D[p, Boxed -> False]DiscretizeGraphics[g]Unbounded Graphics3D primitives can only be represented within a finite range:
p = {InfiniteLine[{0, 0, 0}, {1, 0, 0}], HalfLine[{0, 0, 0}, {0, 0, -1}], InfinitePlane[{0, 0, -2}, {{1, 0, 0}, {0, 1, 0}}], HalfPlane[{{-1 / 2, 0, -2}, {-1 / 2, 1, -2}}, {-1, 0, 1}],
ConicHullRegion[{{0, 0, 0}}, {{1, 1, 0}, {0, 1, 1}, {1, 0, 1}}]};g = Graphics3D[p, Boxed -> False, PlotRange -> {{-3, 3}, {-3, 3}, {-6, 3}}]DiscretizeGraphics[g]Nonlinear Graphics3D primitives can only be approximately represented:
g = Graphics3D[{Cylinder[{{2, 2, 0}, {2, 2, 2}}, 1], Sphere[{3, 3, 1}], BSplineSurface[Table[{i, j, RandomReal[{-1, 0}]}, {i, 5}, {j, 5}]]}]DiscretizeGraphics[g]Options (24)
AccuracyGoal (1)
MaxCellMeasure (6)
Discretize with a maximum cell area of 0.1:
mr = DiscretizeGraphics[Graphics[{Disk[{0, 0}], Circle[{1, 0}]}], MaxCellMeasure -> 0.1]This gives the area of the cells:
AnnotationValue[{mr, 2}, MeshCellMeasure]Discretize with a maximum cell volume of 0.1:
g = Graphics3D[{Cylinder[{{2, 2, 0}, {2, 2, 2}}, 1], Sphere[{3, 3, 1}]}]mr = DiscretizeGraphics[g, MaxCellMeasure -> 0.1]A Histogram of the cell volumes:
Histogram[AnnotationValue[{mr, 3}, MeshCellMeasure]]Compare different length settings:
g = Graphics[{Circle[{0, 0}], Circle[{1, 0}]}]Table[DiscretizeGraphics[g, MaxCellMeasure -> {"Length" -> m}], {m, {0.8, 0.1, 0.05}}]Compare different area settings:
g = Graphics[{Disk[{0, 0}], Disk[{1, 0}]}]Table[DiscretizeGraphics[g, MaxCellMeasure -> {"Area" -> m}], {m, {0.4, 0.2, 0.05}}]Compare different face area settings:
g = Graphics3D[{Cylinder[{{2, 2, 0}, {2, 2, 2}}, 1], Sphere[{3, 3, 1}]}]Table[DiscretizeGraphics[g, MaxCellMeasure -> {"Area" -> m}], {m, {1, 0.1, 0.01}}]Compare different volume settings:
g = Graphics3D[{Ball[]}]Table[DiscretizeGraphics[g, MaxCellMeasure -> {"Volume" -> m}], {m, {0.3, 0.01, 0.001}}]MeshCellHighlight (2)
MeshCellHighlight allows you to specify highlighting for parts of a MeshRegion:
DiscretizeGraphics[Graphics[Disk[]], MeshCellHighlight -> {{1, All} -> Red, {0, All} -> Green}]Individual cells can be highlighted using their cell index:
DiscretizeGraphics[Graphics[Line[{{{0, 0}, {1, 0}}, {{1, 0}, {2, 0}}}]], MeshCellHighlight -> {{1, 1} -> {Thick, Red}, {1, 2} -> {Dashed, Green}}]DiscretizeGraphics[Graphics[Line[{{{0, 0}, {1, 0}}, {{1, 0}, {2, 0}}}]], MeshCellHighlight -> {Line[{1, 2}] -> {Thick, Red}, Line[{2, 3}] -> {Dashed, Green}}]MeshCellLabel (3)
MeshCellLabel can be used to label parts of a MeshRegion:
DiscretizeGraphics[Graphics[Point[{{0, 0}, {1, 0}, {2, 0}}]], MeshCellLabel -> {0 -> "Index"}]Label the vertices and edges of a parallelogram:
DiscretizeGraphics[Graphics[{Parallelogram[{0, 0}, {{1, 1}, {1, 0}}]}], MeshCellLabel -> {0 -> "Index", 1 -> "Index"}]Individual cells can be labeled using their cell index:
DiscretizeGraphics[Graphics[Line[{{{0, 0}, {1, 0}}, {{1, 0}, {2, 0}}}]], MeshCellLabel -> {{1, 1} -> "x", {1, 2} -> "y"}]DiscretizeGraphics[Graphics[Line[{{{0, 0}, {1, 0}}, {{1, 0}, {2, 0}}}]], MeshCellLabel -> {Line[{1, 2}] -> "x", Line[{2, 3}] -> "y"}]MeshCellMarker (1)
MeshCellMarker can be used to assign values to parts of a MeshRegion:
DiscretizeGraphics[Graphics[Point[{{0, 0}, {1, 0}, {2, 0}}]], MeshCellMarker -> {{0, 1} -> 1, {0, 2} -> 2, {0, 3} -> 3}]Use MeshCellLabel to show the markers:
DiscretizeGraphics[Graphics[Point[{{0, 0}, {1, 0}, {2, 0}}]], MeshCellMarker -> {{0, 1} -> 1, {0, 2} -> 2, {0, 3} -> 3}, MeshCellLabel -> {0 -> "Marker"}]MeshCellShapeFunction (2)
MeshCellShapeFunction allows you to specify functions for parts of a MeshRegion:
DiscretizeGraphics[Graphics[Line[{{0, 0}, {2, 0}, {1, Sqrt[3]}, {0, 0}}]], MeshCellShapeFunction -> {0 -> (Disk[#, .1]&)}]Individual cells can be drawn using their cell index:
DiscretizeGraphics[Graphics[Line[{{0, 0}, {2, 0}, {1, Sqrt[3]}, {0, 0}}]], MeshCellShapeFunction -> {{0, 1} -> (Disk[#, .1]&), {0, 2} -> (Disk[#, {.1, .2}]&)}]DiscretizeGraphics[Graphics[Line[{{0, 0}, {2, 0}, {1, Sqrt[3]}, {0, 0}}]], MeshCellShapeFunction -> {Point[1] -> (Disk[#, .1]&), Point[2] -> (Disk[#, {.1, .2}]&)}]MeshCellStyle (2)
MeshCellStyle allows you to specify styling for parts of a MeshRegion:
DiscretizeGraphics[Graphics[Disk[]], MeshCellStyle -> {{1, All} -> Red, {0, All} -> Green}]Individual cells can be highlighted using their cell index:
DiscretizeGraphics[Graphics[Line[{{{0, 0}, {1, 0}}, {{1, 0}, {2, 0}}}]], MeshCellStyle -> {{1, 1} -> {Thick, Red}, {1, 2} -> {Dashed, Green}}]DiscretizeGraphics[Graphics[Line[{{{0, 0}, {1, 0}}, {{1, 0}, {2, 0}}}]], MeshCellStyle -> {Line[{1, 2}] -> {Thick, Red}, Line[{2, 3}] -> {Dashed, Green}}]PlotRange (4)
Automatic includes the entire range of a finite region:
g = Graphics[{Triangle[], Circle[{-1, -1}]}];DiscretizeGraphics[g, PlotRange -> Automatic]Automatic includes a partial range of an infinite region:
g = Graphics[{HalfLine[{0, 0}, {-1, 1}], HalfPlane[{{1, 0}, {2, 1}}, {1, -1}]}];DiscretizeGraphics[g, PlotRange -> Automatic]Explicit settings are respected:
g = Graphics[{Disk[{0, 0}], Circle[{1.5, 0}]}, PlotRange -> {{-1, 3}, {-1, 1}}]DiscretizeGraphics[g]DiscretizeGraphics[g, PlotRange -> {{0, 3}, {0, 1}}]g = Graphics[{Circle[], HalfPlane[{{1, 0}, {2, 1}}, {1, -1}]}];DiscretizeGraphics[g, PlotRange -> {{-3, 3}, {-3, 3}}]Clipping a solid primitive results in a solid primitive; otherwise, interiors are exposed:
g = Graphics3D[{Ball[], Sphere[{2, 0, 0}]}]DiscretizeGraphics[g, PlotRange -> {{-1, 3}, {0.1, 1}, {-2, 2}}]PlotTheme (2)
Use a theme with grid lines and a legend:
DiscretizeGraphics[Graphics3D[Pyramid[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}]], PlotTheme -> "Detailed"]DiscretizeGraphics[Graphics[Disk[]], PlotTheme -> "Detailed"]Use a theme to draw a wireframe:
DiscretizeGraphics[Graphics3D[Pyramid[{{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}, {1, 1, 2}}]], PlotTheme -> "Lines"]DiscretizeGraphics[Graphics[Disk[]], PlotTheme -> "Lines"]PrecisionGoal (1)
Compare the results for each setting of PrecisionGoal:
g = Graphics3D[{Cylinder[{{2, 2, 0}, {2, 2, 2}}, 1], Sphere[{3, 3, 1}]}]{mr2, mr3} = Table[DiscretizeGraphics[g, PrecisionGoal -> n], {n, {1, 3}}]Applications (4)
Compute the length of a curve by converting it to a geometric region:
g = KnotData["Trefoil", "KnotDiagram"];ℛ = DiscretizeGraphics[g]//QuietArcLength[ℛ]Compute the surface area of a graphic by converting it to a geometric region:
p = PolyhedronData["Dodecahedron"];ℛ = DiscretizeGraphics[p]Area[ℛ]Convert Text to a geometric region:
t = Text[Style["π", Bold]]DiscretizeGraphics[t, _Text, MaxCellMeasure -> 0.1]Convert a country polygon to a geometric region:
DiscretizeGraphics[CountryData["France", "Polygon"]]Properties & Relations (9)
Multiple primitives are interpreted as a union:
g = Graphics[{Rectangle[], Circle[], Line[{{1, -1}, {-1, 1}}]}]DiscretizeGraphics[g]Bounded linear primitives can be exactly discretized:
g = Graphics[{Line[{{1, -1}, {-1, 1}}], Triangle[], Rectangle[{-1, -1}, {0, 0}]}]DiscretizeGraphics[g]Unbounded linear primitives can only be represented within a finite range:
g = Graphics[{InfiniteLine[{0, 0}, {1, 1}], HalfPlane[{{1, 0}, {2, 1}}, {1, -1}]}, PlotRange -> {{-1.5, 2.75}, {-1.5, 1.5}}]DiscretizeGraphics[g]Nonlinear primitives can only be approximately discretized:
g = Graphics[Table[Circle[{0, 0}, r], {r, {1, 4, 7}}]]DiscretizeGraphics[g]Use BoundaryDiscretizeGraphics to get a BoundaryMeshRegion representation:
g = Graphics[{Brown, Disk[{1.5, 1}], Orange, Rectangle[]}]{br, mr} = {BoundaryDiscretizeGraphics[g], DiscretizeGraphics[g]}{BoundaryMeshRegionQ[br], MeshRegionQ[mr]}DiscretizeRegion can be used to discretize any RegionQ object:
DiscretizeRegion[ImplicitRegion[x ^ 2 - y ^ 2 ≤ 1, {{x, -2, 2}, {y, -2, 2}}]]DiscretizeGraphics can be used to discretize Graphics and Graphics3D objects:
DiscretizeGraphics[Graphics[{BezierCurve[{{0, 1}, {1, 1}, {2, -1}, {5, 1}}], Circle[]}]]They can both discretize special regions that are also graphics primitives:
{DiscretizeRegion[Disk[]], DiscretizeGraphics[Disk[]]}Graphics primitives that are also geometric regions can be used without discretization:
r = Disk[{0, 0}, 1];RegionQ[r]Compute directly with the region:
Area[r]Or with its discretized version:
Area[DiscretizeGraphics[r]]Rasterize discretizes any rendered expression to Graphics containing a Raster object:
g = Graphics[{Disk[{0, 0}], Circle[{1, 0}]}]Rasterize[g, RasterSize -> {30, 20}, ImageSize -> 100]Image discretizes any rendered expression to an Image object:
g = Graphics[{Disk[{0, 0}], Circle[{1, 0}]}]Image[g, ImageSize -> {30, 20}, Magnification -> 4]See Also
BoundaryDiscretizeGraphics DiscretizeRegion MeshRegion BoundaryDiscretizeRegion FindMeshDefects RepairMesh RegionImage
Function Repository: GraphicsMetricGraph
Related Guides
Text
Wolfram Research (2014), DiscretizeGraphics, Wolfram Language function, https://reference.wolfram.com/language/ref/DiscretizeGraphics.html (updated 2015).
CMS
Wolfram Language. 2014. "DiscretizeGraphics." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/DiscretizeGraphics.html.
APA
Wolfram Language. (2014). DiscretizeGraphics. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DiscretizeGraphics.html
BibTeX
@misc{reference.wolfram_2026_discretizegraphics, author="Wolfram Research", title="{DiscretizeGraphics}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/DiscretizeGraphics.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_discretizegraphics, organization={Wolfram Research}, title={DiscretizeGraphics}, year={2015}, url={https://reference.wolfram.com/language/ref/DiscretizeGraphics.html}, note=[Accessed: 13-June-2026]}