> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/flatredball/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flatredball.com/flatredball/api/flatredball/math/geometry/axisalignedrectangle.md).

# AxisAlignedRectangle

### Introduction

The AxisAlignedRectangle is a [PositionedObject](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) which is used for unrotated bounding box collision. This is preferred over [Polygon](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) collision if Sprites are not rotated due to speed and memory usage considerations. AxisAlignedRectangles share many similarities with the other shape classes ([Circle](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php), [Line](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php), and [Polygon](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)). For general information about shapes, see the [ShapeManager wiki entry](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php). For information on using AxisAlignedRectangles in Glue, see [this page](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php). AxisAlignedRectangles do not support being filled-in. They can only render as an outline. To render a solid rectangle, look at using [Sprites](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) with the [Color ColorOperation](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)

### What does "axis aligned" mean?

The "AxisAligned" part of AxisAlignedRectangle indicates that the sides of the rectangle are "axis aligned". In other words, the top, bottom, left, and right are all parallel to either the X or Y axes. ![AxisAligned.png](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-502fee7fced0742c610f0208983d11a57d912dee%2Fmigrated_media-AxisAligned.png?alt=media) AxisAlignedRectangles are always axis aligned for performance reasons. Therefore, if you rotate an AxisAlignedRectangle (set its RotationZ), this will have no impact on the collision behavior or its visible representation. If your game requires rotation, you should use the [Polygon](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) class. Of course, performance will suffer slightly if collision performance is a consideration for your game. For more information on axis alignment and a discussion of axis aligned object rotation and children positions, see [this page](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php).

### AxisAlignedRectangles are [PositionedObjects](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)

The AxisAlignedRectangle class inherits from PositionedObject. This means that all properties which are available to [PositionedObjects](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) (excluding rotation) are available to AxisAlignedRectangles. For more information, see the [PositionedObject page](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php).

### Creating an AxisAlignedRectangle

AxisAlignedRectangles are created through the ShapeManager. The following code creates an AxisAlignedRectangle through the ShapeManager and resizes it: Add the following using statement

```
using FlatRedBall.Math.Geometry;
```

Create the instance:

```
// AxisAlignedRectangles added this way are Visible by default and also managed
// by the ShapeManager.
AxisAlignedRectangle rectangle = ShapeManager.AddAxisAlignedRectangle();
rectangle.ScaleX = 5;
rectangle.ScaleY = 7;
```

![SimpleRectangle.png](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-ba56417e4274defdedc22743b0e5f78a976e3596%2Fmigrated_media-SimpleRectangle.png?alt=media)

### Relationship with ShapeManager

See [ShapeManager wiki entry](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php).

### Move (Solid) Collision

Solid or moving collision can be performed with AxisAlignedRectangles as well as [Polygons](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) and [Circles](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php). The following code creates three AxisAlignedRectangles - one controlled by the player, one which can be pushed, and one which is is immovable. Add the following using statements:

```
using FlatRedBall.Input;
using FlatRedBall.Math.Geometry;
```

Add the following at class scope:

```
AxisAlignedRectangle playerRectangle;
AxisAlignedRectangle movableBlockRectangle;
AxisAlignedRectangle solidRectangle;
```

Add the following in Initialize after Initializing FlatRedBall:

```
 playerRectangle = ShapeManager.AddAxisAlignedRectangle();
 playerRectangle.X = -3;
 playerRectangle.Color = Color.Yellow;

 movableBlockRectangle = ShapeManager.AddAxisAlignedRectangle();
 movableBlockRectangle.Color = Color.Red;

 solidRectangle = ShapeManager.AddAxisAlignedRectangle();
 solidRectangle.ScaleX = solidRectangle.ScaleY = 4;
 solidRectangle.X = 7;
```

Add the following in Update:

```
 InputManager.Keyboard.ControlPositionedObject(playerRectangle);

 // player and movable have the same mass
 playerRectangle.CollideAgainstMove(movableBlockRectangle, .5f, .5f);
 // make the solid infinitely more massive than the player
 playerRectangle.CollideAgainstMove(solidRectangle, 0, 1);
 // make the solid infinitely more massive than the movable
 movableBlockRectangle.CollideAgainstMove(solidRectangle, 0, 1);
```

![SolidCollision.png](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-78d5bbf330b1f39ddf3826f79d315cdc2e9b5950%2Fmigrated_media-SolidCollision.png?alt=media)

### Determining Collision Side

For information on determining which side an object has collided on, see [this page on LastMoveCollisionReposition](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php).

### AxisAlignedRectangle Members

* [FlatRedBall.Math.Geometry.AxisAlignedRectangle.Bottom](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)
* [FlatRedBall.Math.Geometry.AxisAlignedRectangle.CollideAgainst](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)
* [FlatRedBall.Math.Geometry.AxisAlignedRectangle.CollideAgainstBounce](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)
* [FlatRedBall.Math.Geometry.AxisAlignedRectangle.CollideAgainstMove](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)
* [FlatRedBall.Math.Geometry.AxisAlignedRectangle.CollideAgainstMoveSoft](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)
* [FlatRedBall.Math.Geometry.AxisAlignedRectangle.Color](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)
* [FlatRedBall.Math.Geometry.AxisAlignedRectangle.GetRandomPositionInThis](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)
* [FlatRedBall.Math.Geometry.AxisAlignedRectangle.Height](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)
* [FlatRedBall.Math.Geometry.AxisAlignedRectangle.KeepThisInsideOf](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)
* [FlatRedBall.Math.Geometry.AxisAlignedRectangle.LastMoveCollisionReposition](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)
* [FlatRedBall.Math.Geometry.AxisAlignedRectangle.Left](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)
* [FlatRedBall.Math.Geometry.AxisAlignedRectangle.RepositionDirections](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)
* [FlatRedBall.Math.Geometry.AxisAlignedRectangle.Right](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)
* [FlatRedBall.Math.Geometry.AxisAlignedRectangle.Top](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)
* [FlatRedBall.Math.Geometry.AxisAlignedRectangle.Width](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)
* [FlatRedBall.Math.Geometry.AxisAlignedRectangle.Z](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)

### Extra Information

* [Axis Alignment and Rotation](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)
* [Tile Collision](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)

Did this article leave any questions unanswered? Post any question in our [forums](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/forum.md) for a rapid response.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.flatredball.com/flatredball/api/flatredball/math/geometry/axisalignedrectangle.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
