---
title: "Rectangle"
language: "en"
type: "Symbol"
summary: "Rectangle[{xmin, ymin}, {xmax, ymax}] represents an axis-aligned filled rectangle from {xmin, ymin} to {xmax, ymax}. Rectangle[{xmin, ymin}] corresponds to a unit square with its bottom-left corner at {xmin, ymin}."
keywords: 
- graphics rectangle
- square
- rectangle
- graphics square
- polygon
- rectangle
- rectangle
canonical_url: "https://reference.wolfram.com/language/ref/Rectangle.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Graphics Objects"
    link: "https://reference.wolfram.com/language/guide/GraphicsObjects.en.md"
  - 
    title: "Basic Geometric Regions"
    link: "https://reference.wolfram.com/language/guide/GeometricSpecialRegions.en.md"
  - 
    title: "Plane Geometry"
    link: "https://reference.wolfram.com/language/guide/PlaneGeometry.en.md"
  - 
    title: "Polygons"
    link: "https://reference.wolfram.com/language/guide/Polygons.en.md"
  - 
    title: "Symbolic Graphics Language"
    link: "https://reference.wolfram.com/language/guide/SymbolicGraphicsLanguage.en.md"
related_functions: 
  - 
    title: "Polygon"
    link: "https://reference.wolfram.com/language/ref/Polygon.en.md"
  - 
    title: "Parallelogram"
    link: "https://reference.wolfram.com/language/ref/Parallelogram.en.md"
  - 
    title: "Cuboid"
    link: "https://reference.wolfram.com/language/ref/Cuboid.en.md"
  - 
    title: "Raster"
    link: "https://reference.wolfram.com/language/ref/Raster.en.md"
  - 
    title: "Inset"
    link: "https://reference.wolfram.com/language/ref/Inset.en.md"
  - 
    title: "GraphicsGrid"
    link: "https://reference.wolfram.com/language/ref/GraphicsGrid.en.md"
  - 
    title: "Rotate"
    link: "https://reference.wolfram.com/language/ref/Rotate.en.md"
  - 
    title: "BoundingRegion"
    link: "https://reference.wolfram.com/language/ref/BoundingRegion.en.md"
---
# Rectangle

Rectangle[{xmin, ymin}, {xmax, ymax}] represents an axis-aligned filled rectangle from {xmin, ymin} to {xmax, ymax}.

Rectangle[{xmin, ymin}] corresponds to a unit square with its bottom-left corner at {xmin, ymin}.

## Details and Options

* ``Rectangle`` can be used as a geometric region and a graphics primitive.

* ``Rectangle`` represents the region $\left\{\{x,y\}\left|x_{\text{\textit{min}}}\leq x\leq x_{\text{\textit{max}}}\land y_{\text{\textit{min}}}\leq y\leq y_{\text{\textit{$\max
$}}}\right.\right\}$.

[image]

* ``Rectangle[]`` is equivalent to ``Rectangle[{0, 0}]``. »

* ``Rectangle`` can be used in ``Graphics``.

* In graphics, the points ``{xi, yi}`` can be ``Scaled``, ``Offset``, ``ImageScaled``, and ``Dynamic`` expressions.

* The option ``RoundingRadius -> r`` can be used to specify rounded corners rendered using circles of radius ``r``.

* Graphics rendering is affected by directives such as ``FaceForm``, ``EdgeForm`` and color.

* ``CanonicalizePolygon`` can be used to convert a rectangle to an explicit ``Polygon`` object.

---

## Examples (42)

### Basic Examples (5)

A unit square:

```wl
In[1]:= Graphics[Rectangle[]]

Out[1]= [image]
```

---

Two squares:

```wl
In[1]:= Graphics[{Red, Rectangle[{0, 0}], Blue, Rectangle[{0.5, 0.5}]}]

Out[1]= [image]
```

---

Various rectangles:

```wl
In[1]:= Graphics[{Red, Rectangle[{0, 0}, {1, 3}], Blue, Rectangle[{2, 1}, {4, 2}]}]

Out[1]= [image]
```

---

Differently styled rectangles:

```wl
In[1]:= {Graphics[{Pink, Rectangle[]}], Graphics[{EdgeForm[Thick], Pink, Rectangle[]}], Graphics[{EdgeForm[Dashed], Pink, Rectangle[]}], Graphics[{EdgeForm[Directive[Thick, Dashed, Blue]], Pink, Rectangle[]}]}

Out[1]= {[image], [image], [image], [image]}
```

---

Area and centroid:

```wl
In[1]:= Area[Rectangle[{x1, y1}, {x2, y2}]]

Out[1]= (x1 - x2) (y1 - y2)

In[2]:= RegionCentroid[Rectangle[{x1, y1}, {x2, y2}]]

Out[2]= {(x1 + x2/2), (y1 + y2/2)}
```

### Scope (17)

#### Graphics (7)

##### Specification (3)

---

A unit square:

```wl
In[1]:= Graphics[Rectangle[{1, 1}]]

Out[1]= [image]
```

---

A rectangle parallel to each axis:

```wl
In[1]:= Graphics[Rectangle[{0, 0}, {2, 1}]]

Out[1]= [image]
```

---

Short form for a unit cube with corner at the origin:

```wl
In[1]:= Graphics[Rectangle[], Frame -> True]

Out[1]= [image]
```

##### Styling (1)

---

Color directives specify the face colors of rectangles:

```wl
In[1]:= Table[Graphics[{c, Rectangle[]}], {c, {Red, Green, Blue, Yellow}}]

Out[1]= {[image], [image], [image], [image]}
```

``FaceForm`` and ``EdgeForm`` can be used to specify the styles of the interior and boundary of a rectangle:

```wl
In[2]:= Graphics[{FaceForm[Pink], EdgeForm[Directive[Thick, Dashed, Blue]], Rectangle[]}]

Out[2]= [image]
```

##### Coordinates (3)

Use ``Scaled`` coordinates:

```wl
In[1]:= Graphics[Rectangle[Scaled[{0, .4}], Scaled[{1, .6}]], Frame -> True, PlotRange -> {{0, 10}, {0, 10}}]

Out[1]= [image]
```

---

Use ``ImageScaled`` coordinates:

```wl
In[1]:= Graphics[Rectangle[ImageScaled[{0, .4}], ImageScaled[{1, .6}]], Frame -> True, PlotRange -> {{0, 10}, {0, 10}}]

Out[1]= [image]
```

---

Use ``Offset`` coordinates:

```wl
In[1]:= Graphics[Rectangle[Offset[{10, 20}, {0, 0}], Offset[{-10, -20}, {1, 1}]], Frame -> True]

Out[1]= [image]
```

#### Regions (10)

Embedding dimension:

```wl
In[1]:= RegionEmbeddingDimension[Rectangle[{Subscript[x, min], Subscript[y, min]}, {Subscript[x, max], Subscript[y, max]}]]

Out[1]= 2
```

Geometric dimension:

```wl
In[2]:= RegionDimension[Rectangle[{Subscript[x, min], Subscript[y, min]}, {Subscript[x, max], Subscript[y, max]}]]

Out[2]= 2
```

---

Point membership test:

```wl
In[1]:= ℛ = Rectangle[{0, 0}];

In[2]:= {RegionMember[ℛ, {0, 1}], RegionMember[ℛ, {0, 2}]}

Out[2]= {True, False}
```

Get conditions for point membership:

```wl
In[3]:= RegionMember[ℛ, {x, y}]

Out[3]= (x | y)∈ℝ && 0 ≤ x ≤ 1 && 0 ≤ y ≤ 1
```

---

Area:

```wl
In[1]:= ℛ = Rectangle[{0, 0}];

In[2]:= {Area[ℛ], RegionMeasure[ℛ]}

Out[2]= {1, 1}
```

Centroid:

```wl
In[3]:= c = RegionCentroid[ℛ]

Out[3]= {(1/2), (1/2)}

In[4]:= Graphics[{{Pink, ℛ}, {Black, Point[c]}}]

Out[4]= [image]
```

---

Distance from a point:

```wl
In[1]:= ℛ = Rectangle[{-1, -1}, {1, 1}];

In[2]:= {RegionDistance[ℛ, {2, 3}], RegionDistance[ℛ, {1, 0}]}

Out[2]= {Sqrt[5], 0}
```

Plot it:

```wl
In[3]:= {Plot3D[RegionDistance[ℛ, {x, y}], {x, -2, 2}, {y, -2, 2}, MeshFunctions -> {#3&}, Mesh -> 5, Exclusions -> Norm[{x, y}, ∞] == 1], ContourPlot[Evaluate@RegionDistance[ℛ, {x, y}], {x, -3, 3}, {y, -3, 3}, Contours -> {{0.5, Red}, {1, Green}, {1.5, Blue}}]}

Out[3]= [image]
```

---

Signed distance from a point:

```wl
In[1]:= ℛ = Rectangle[{-1, -1}, {1, 1}];

In[2]:= {SignedRegionDistance[ℛ, {2, 3}], SignedRegionDistance[ℛ, {0, 0}]}

Out[2]= {Sqrt[5], -1}
```

Plot it:

```wl
In[3]:= Plot3D[SignedRegionDistance[ℛ, {x, y}], {x, -2, 2}, {y, -2, 2}, MeshFunctions -> {#3&}, Mesh -> {{0}}, MeshShading -> {Red, Green}, Exclusions -> Norm[{x, y}, ∞] == 1]

Out[3]= [image]
```

---

Nearest point in the region:

```wl
In[1]:= ℛ = Rectangle[{1, 2}, {3, 4}];

In[2]:= RegionNearest[ℛ, {5, 6}]

Out[2]= {3, 4}
```

Nearest points:

```wl
In[3]:=
pts = Table[{2, 3} + 4{Cos[k 2 π / 16], Sin[k 2π / 16]}, {k, 0., 15}];
nst = RegionNearest[ℛ, #]& /@ pts;

In[4]:= Legended[Graphics[{{Gray, ℛ}, {Thin, Gray, Line[Transpose[{pts, nst}]]}, {Red, Point[pts]}, {Blue, Point[nst]}}], PointLegend[{Red, Blue}, {"start", "nearest"}]]

Out[4]= [image]
```

---

A rectangle is bounded:

```wl
In[1]:= ℛ = Rectangle[{0, 0}, {1, 1}];

In[2]:= BoundedRegionQ[ℛ]

Out[2]= True
```

Get its bounds:

```wl
In[3]:= rr = RegionBounds[ℛ]

Out[3]= {{0, 1}, {0, 1}}
```

---

``Integrate`` over a rectangle:

```wl
In[1]:= ℛ = Rectangle[{Subscript[x, min], Subscript[y, min]}, {Subscript[x, max], Subscript[y, max]}];

In[2]:= Integrate[x y, {x, y}∈ℛ]

Out[2]=
ConditionalExpression[(1/4)*(Subscript[x, max]^2 - Subscript[x, min]^2)*
  (Subscript[y, max]^2 - Subscript[y, min]^2), Subscript[x, max] - Subscript[x, min] > 0 && 
  Subscript[y, max] - Subscript[y, min] > 0]
```

---

Optimize over a rectangle:

```wl
In[1]:= ℛ = Rectangle[{1, 2}, {3, 4}];

In[2]:= Minimize[{x y - x, {x, y}∈ℛ}, {x, y}]

Out[2]= {1, {x -> 1, y -> 2}}
```

---

Solve equations in a rectangle:

```wl
In[1]:= ℛ = Rectangle[{1, 2}, {3, 4}];

In[2]:= Reduce[x^2 + y^2 == 7 && {x, y}∈ℛ, {x, y}]

Out[2]= 1 ≤ x ≤ Sqrt[3] && y == Sqrt[7 - x^2]
```

### Options (1)

#### RoundingRadius (1)

Use rounded corners:

```wl
In[1]:= Graphics[Rectangle[{0, 0}, {2, 1}, RoundingRadius -> 0.3]]

Out[1]= [image]

In[2]:= Table[Graphics[Rectangle[{0, 0}, {2, 1}, RoundingRadius -> m], PlotLabel -> m], {m, {0, .1, 2, .5}}]

Out[2]= {[image], [image], [image], [image]}
```

### Applications (6)

A simple bar chart:

```wl
In[1]:= data = RandomReal[{3, 10}, {10, 2}];

In[2]:=
Graphics[{EdgeForm[Black], Blue, 
	Table[{Blue, Rectangle[{i - .4, 0}, {i, data[[i, 1]]}], Red, Rectangle[{i + .4, 0}, {i, data[[i, 2]]}]}, {i, 10}]}, AspectRatio -> 1 / GoldenRatio, Frame -> True]

Out[2]= [image]
```

---

Golden rectangle:

```wl
In[1]:=
gr[0] := {{0, 0}, {1, -1}};
gr[n_] := Module[{ϕ = GoldenRatio, a, b, c, d}, {{a, b}, {c, d}} = gr[n - 1];
	Switch[Mod[n, 4], 0, {{a, d}, {a + ϕ ^ -n, d - ϕ ^ -n}}, 1, {{c, d + ϕ ^ -n}, {c + ϕ ^ -n, d}}, 2, {{c - ϕ ^ -n, b + ϕ ^ -n}, {c, b}}, 3, {{a - ϕ ^ -n, b}, {a, b - ϕ ^ -n}}]];

In[2]:= Graphics[{EdgeForm[Opacity[.5]], Table[{ColorData[24, k + 1], Rectangle@@gr[k]}, {k, 0, 8}]}]

Out[2]= [image]
```

---

Square wheel:

```wl
In[1]:= Animate[With[{q = Quotient[θ, π / 2], m = Mod[θ, π / 2]}, Graphics[{EdgeForm[Black], LightGray, Rotate[Rectangle[{q, 0}], -m, {q + 1, 0}]}, Axes -> {True, False}, PlotRange -> {{-.5, 5.5}, {-0.5, 1.5}}, ImageSize -> 350]], {θ, 0, 2Pi}, AnimationRunning -> False, AnimationDirection -> ForwardBackward, DefaultDuration -> 2]

Out[1]= DynamicModule[«7»]
```

---

The trajectory of the square wheel:

```wl
In[1]:= Graphics[{EdgeForm[Black], FaceForm[LightGray], Table[With[{q = Quotient[θ, π / 2], m = Mod[θ, π / 2]}, Rotate[Rectangle[{q, 0}], -m, {q + 1, 0}]], {θ, 0, 2Pi, Pi / 12}]}, Axes -> {True, False}, PlotRange -> {{-.5, 5.5}, {-0.5, 1.5}}, ImageSize -> 350]

Out[1]= [image]
```

---

A ``Rectangle`` with equal side lengths is a square:

```wl
In[1]:= SquareRegion[{x_, y_}, r_] := Rectangle[{x, y}, {x + r, y + r}]

In[2]:= SquareRegion[{1, 2}, 3]

Out[2]= Rectangle[{1, 2}, {4, 5}]
```

Visualize it:

```wl
In[3]:= Region[%]

Out[3]= [image]
```

---

Maximize the area of a rectangle with a fixed perimeter:

```wl
In[1]:=
r = Rectangle[{0, 0}, {x, y}];
Maximize[{Area[r], 2x + 2y == 4 && 0 < x && 0 < y}, {x, y}, Reals]

Out[1]= {1, {x -> 1, y -> 1}}
```

The resulting rectangle is a square:

```wl
In[2]:= Region[r /. {x -> 1, y -> 1}]

Out[2]= [image]
```

Indeed, it will always be a square:

```wl
In[3]:= Assuming[p > 0, Simplify[Maximize[{Area[r], 2x + 2y == p && 0 < x && 0 < y}, {x, y}, Reals]]]

Out[3]= {(p^2/16), {x -> (p/4), y -> (p/4)}}
```

### Properties & Relations (9)

Use ``Rotate`` to get all possible rectangles:

```wl
In[1]:= Graphics[{Pink, Rotate[Rectangle[{0, 0}, {4, 3}], 30Degree]}, Frame -> True]

Out[1]= [image]
```

---

``Rectangle`` is a special case of ``Cuboid``:

```wl
In[1]:=
Subscript[ℛ, 1] = Cuboid[{0, 0}, {1, 1}];
Subscript[ℛ, 2] = Rectangle[{0, 0}, {1, 1}];

In[2]:= RegionEqual[Subscript[ℛ, 1], Subscript[ℛ, 2]]

Out[2]= True
```

---

``Rectangle`` is a special case of ``Parallelogram``:

```wl
In[1]:=
Subscript[ℛ, 1] = Parallelogram[{0, 0}, {{1, 0}, {0, 1}}];
Subscript[ℛ, 2] = Rectangle[{0, 0}, {1, 1}];

In[2]:= RegionEqual[Subscript[ℛ, 1], Subscript[ℛ, 2]]

Out[2]= True
```

---

``Rectangle`` is a special case of ``Polygon``:

```wl
In[1]:=
Subscript[ℛ, 1] = Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}];
Subscript[ℛ, 2] = Rectangle[{0, 0}, {1, 1}];

In[2]:= RegionEqual[Subscript[ℛ, 1], Subscript[ℛ, 2]]

Out[2]= True
```

---

``Rectangle`` is the union of two ``Triangle`` objects:

```wl
In[1]:= Subscript[ℛ, 1] = Rectangle[{0, 0}, {1, 1}];

In[2]:=
t1 = Triangle[{{0, 0}, {1, 0}, {1, 1}}];
t2 = Triangle[{{1, 1}, {0, 1}, {0, 0}}];
Subscript[ℛ, 2] = RegionUnion[t1, t2];

In[3]:= RegionEqual[Subscript[ℛ, 1], Subscript[ℛ, 2]]

Out[3]= True

In[4]:= Region[Subscript[ℛ, 2]]

Out[4]= [image]
```

---

``ImplicitRegion`` can represent any ``Rectangle`` region:

```wl
In[1]:=
Subscript[ℛ, 1] = ImplicitRegion[0 ≤ x ≤ 1 && 0 ≤ y ≤ 1, {x, y}];
Subscript[ℛ, 2] = Rectangle[{0, 0}, {1, 1}];

In[2]:= RegionEqual[Subscript[ℛ, 1], Subscript[ℛ, 2]]

Out[2]= True
```

---

``ParametricRegion`` can represent any ``Rectangle`` region:

```wl
In[1]:=
Subscript[ℛ, 1] = ParametricRegion[{u, v}, {{u, 0, 1}, {v, 0, 1}}];
Subscript[ℛ, 2] = Rectangle[{0, 0}, {1, 1}];

In[2]:= RegionEqual[Subscript[ℛ, 1], Subscript[ℛ, 2]]

Out[2]= True
```

---

``MeshRegion`` can represent any ``Rectangle`` region:

```wl
In[1]:= MeshRegion[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, Polygon[{1, 2, 3, 4}]]

Out[1]= [image]

In[2]:= RegionEqual[%, Rectangle[]]

Out[2]= True
```

---

``BoundaryMeshRegion`` can represent any ``Rectangle`` region:

```wl
In[1]:= BoundaryMeshRegion[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, Line[{1, 2, 3, 4, 1}]]

Out[1]= [image]

In[2]:= RegionEqual[%, Rectangle[]]

Out[2]= True
```

### Possible Issues (1)

``RoundingRadius`` only affects ``Graphics``:

```wl
In[1]:= RegionMeasure[Rectangle[{0, 0}, {1, 1}, RoundingRadius -> 1 / 3]]

Out[1]= 1

In[2]:=
{DiscretizeGraphics[Rectangle[{0, 0}, {1, 1}, RoundingRadius -> 1 / 3]], 
	Graphics[Rectangle[{0, 0}, {1, 1}, RoundingRadius -> 1 / 3]]}

Out[2]= {[image], [image]}
```

### Neat Examples (3)

A collection of random squares:

```wl
In[1]:= Graphics[{EdgeForm[Black], Table[{Hue[RandomReal[]], Rotate[Rectangle[RandomReal[2, 2]], RandomReal[2Pi]]}, {20}]}]

Out[1]= [image]
```

---

A color wheel:

```wl
In[1]:= Animate[Graphics[{EdgeForm[Opacity[.5]], Table[{Hue[(t + k) / 20, 1, .9], Rotate[Rectangle[{1, -Sin[Pi / 20]}, {1 + 2Sin[Pi / 20], Sin[Pi / 20]}], 2Pi t / 20, {0, 0}]}, {t, 20}]}], {k, 1, 20}, AnimationRunning -> False]

Out[1]= DynamicModule[«7»]
```

---

Digital petals:

```wl
In[1]:= Graphics[Table[{EdgeForm[Opacity[.6]], Hue[(-11 + q + 10 r) / 72], With[{t = 2Pi q / 12}, Rotate[Rectangle[(8 - r)({Cos[t], Sin[t]} - 1 / 4), (8 - r)({Cos[t], Sin[t]} + 1 / 4)], t + Pi / 4]]}, {r, 6}, {q, 12}]]

Out[1]= [image]
```

## See Also

* [`Polygon`](https://reference.wolfram.com/language/ref/Polygon.en.md)
* [`Parallelogram`](https://reference.wolfram.com/language/ref/Parallelogram.en.md)
* [`Cuboid`](https://reference.wolfram.com/language/ref/Cuboid.en.md)
* [`Raster`](https://reference.wolfram.com/language/ref/Raster.en.md)
* [`Inset`](https://reference.wolfram.com/language/ref/Inset.en.md)
* [`GraphicsGrid`](https://reference.wolfram.com/language/ref/GraphicsGrid.en.md)
* [`Rotate`](https://reference.wolfram.com/language/ref/Rotate.en.md)
* [`BoundingRegion`](https://reference.wolfram.com/language/ref/BoundingRegion.en.md)

## Related Guides

* [Graphics Objects](https://reference.wolfram.com/language/guide/GraphicsObjects.en.md)
* [Basic Geometric Regions](https://reference.wolfram.com/language/guide/GeometricSpecialRegions.en.md)
* [Plane Geometry](https://reference.wolfram.com/language/guide/PlaneGeometry.en.md)
* [`Polygons`](https://reference.wolfram.com/language/guide/Polygons.en.md)
* [Symbolic Graphics Language](https://reference.wolfram.com/language/guide/SymbolicGraphicsLanguage.en.md)

## History

* Introduced in 1988 (1.0) \| Updated in 1996 (3.0) ▪ [2014 (10.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn100.en.md) ▪ [2019 (12.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn120.en.md)