returns True if reg2 is contained within reg1.

Details and Options

  • The region reg2 is contained within reg1 if every point that belongs to reg2 also belongs to reg1.
  • If all regi are parameter-free regions, i.e. ConstantRegionQ[regi] is True, the regions are point sets, and typically True or False is returned.
  • If some regi depend on parameters, i.e. ConstantRegionQ[regi] is False, then regi represents a family of regions, and RegionWithin will attempt to compute conditions on parameters such that reg2 is contained within reg1.
  • The following options can be given:
  • Assumptions$Assumptionsassumptions to make about parameters
    GenerateConditionsFalsewhether to generate conditions on parameters


open allclose all

Basic Examples  (2)

Test whether a region is contained within another:

Visualize them:

Generate conditions for which a region is contained within another:

Scope  (15)

Basic Uses  (3)

Test for membership:

Show a region is not within another:

Find conditions that make a region a subset of another:

Basic Regions  (4)

Regions in including Line and Interval:




Regions in including Point:



Disk and Ellipsoid:

Rectangle and RegularPolygon:

Regions in including Point:



Cuboid and Hexahedron:

Ball and Ellipsoid:

Tetrahedron and Simplex:

Regions in including Cuboid and Parallelepiped in :

Ellipsoid and Ball in :

Formula Regions  (4)

Implicit regions:

Parametric regions:

Compare two formula regions:

Nonconstant formula regions:

Mesh Regions  (3)

Compare MeshRegion in :

In :

In :

Compare BoundaryMeshRegion in :

In :

In :

Compare MeshRegion with BoundaryMeshRegion in :

In :

Derived Regions  (1)

Compare BooleanRegion:

Options  (2)

Assumptions  (1)

Find all disks that contain the unit circle:

Find only the positive radii:

GenerateConditions  (1)

Find when the unit disk lies within an implicitly described annulus:

Show the conditions for which the result is valid:

Explicitly allow for degenerate cases:

Applications  (7)

All convex combinations of points lie within their convex hull:

Find the largest disk contained in a given triangle:

Approximate the largest axes-aligned ellipse contained in the triangle:

Find the smallest disk that contains a given triangle:

Find the smallest axes-aligned ellipse that contains the triangle:

Find all countries that lie completely within the Caribbean Sea:

The polygons of each country:

Select the countries whose polygons lie within the Caribbean Sea:

Verify the results:

View these countries on a map:

Find and visualize all positions where a unit rectangle lies within an annulus:

Perform a random walk inside a region:

Define a function to walk a point in a random direction, staying inside a region:

Simulate a random walk from an initial point:

Visualize the walk:

Use RegionWithin as a partial ordering to visualize concentric disks:

Disks with larger radii can completely cover other disks:

Sort the regions according to membership:

Visualize the rearranged disks:

Properties & Relations  (5)

Use RegionMember to test the membership of a point:

Use RegionWithin to test the membership of a region:

When 2 is within 1, all points in 2 are members of 1:

Check if two regions are equal:

For nonempty regions, RegionDisjoint returns False when RegionWithin returns True:

Use FindInstance to find points that violate the subset condition:

Use RandomPoint to find a uniform sampling of points that violate the subset condition:

Use Reduce to find where the subset condition is violated:

Introduced in 2017