Module org.dyn4j

## Class Rectangle

• All Implemented Interfaces:
`DataContainer`, `Convex`, `Rotatable`, `Shape`, `Transformable`, `Translatable`, `Wound`

```public class Rectangle
extends Polygon
implements Convex, Wound, Shape, Transformable, DataContainer```
Implementation of a Rectangle `Convex` `Shape`.

This class represents both axis-aligned and oriented rectangles and squares.

A `Rectangle` must have a width and height greater than zero.

Since:
1.0.0
Version:
3.4.0
Author:
William Bittle
• ### Constructor Summary

Constructors
Constructor Description
```Rectangle​(double width, double height)```
Full constructor.
• ### Method Summary

All Methods
Modifier and Type Method Description
`void` ```computeAABB​(Transform transform, AABB aabb)```
Computes the `AABB` from this `Shape` after applying the given transformation and places the result in the given `AABB`.
`boolean` ```contains​(Vector2 point, Transform transform)```
Returns true if the given point is inside this `Shape`.
`Mass` `createMass​(double density)`
Creates a `Mass` object using the geometric properties of this `Rectangle` and the given density.
`Vector2[]` ```getAxes​(Vector2[] foci, Transform transform)```
Returns an array of separating axes to test for this `Shape`.
`double` `getHeight()`
Returns the height.
`Rotation` `getRotation()`
`double` `getRotationAngle()`
Returns the rotation about the local center in radians in the range [-π, π].
`double` `getWidth()`
Returns the width.
`Interval` ```project​(Vector2 vector, Transform transform)```
Returns the `Interval` of this `Shape` projected onto the given `Vector2` given the `Transform`.
`String` `toString()`
• ### Methods inherited from class Polygon

`getFarthestFeature, getFarthestPoint, getFoci, getNormalIterator, getNormals, getRadius, getVertexIterator, getVertices, rotate, translate`
• ### Methods inherited from class AbstractShape

`computeAABB, contains, createAABB, createAABB, getCenter, getRadius, getUserData, project, rotate, rotate, rotate, rotate, rotate, rotateAboutCenter, setUserData, translate`
• ### Methods inherited from class Object

`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• ### Methods inherited from interface Convex

`getFarthestFeature, getFarthestPoint, getFoci`
• ### Methods inherited from interface DataContainer

`getUserData, setUserData`
• ### Methods inherited from interface Rotatable

`rotate, rotate, rotate, rotate, rotate, rotate`
• ### Methods inherited from interface Shape

`computeAABB, contains, createAABB, createAABB, getCenter, getRadius, getRadius, project, rotateAboutCenter`
• ### Methods inherited from interface Translatable

`translate, translate`
• ### Methods inherited from interface Wound

`getNormalIterator, getNormals, getVertexIterator, getVertices`
• ### Constructor Detail

• #### Rectangle

```public Rectangle​(double width,
double height)```
Full constructor.

The center of the rectangle will be the origin.

A rectangle must have a width and height greater than zero.

Parameters:
`width` - the width
`height` - the height
Throws:
`IllegalArgumentException` - if width or height is less than or equal to zero
• ### Method Detail

• #### toString

`public String toString()`
Overrides:
`toString` in class `Polygon`
• #### getHeight

`public double getHeight()`
Returns the height.
Returns:
double
• #### getWidth

`public double getWidth()`
Returns the width.
Returns:
double
• #### getRotationAngle

`public double getRotationAngle()`
Returns the rotation about the local center in radians in the range [-π, π].
Returns:
Since:
3.0.1
• #### getRotation

`public Rotation getRotation()`
Returns:
the `Rotation` object that represents the local rotation
• #### getAxes

```public Vector2[] getAxes​(Vector2[] foci,
Transform transform)```
Description copied from interface: `Convex`
Returns an array of separating axes to test for this `Shape`.

The `foci` parameter is an array of circular focal points of the other `Shape`.

If foci points are given, this method will return the separating axes for this `Shape`'s voronoi regions also. The points in the foci array are assumed to be in world space.

The returned axes are normalized and in world space.

Specified by:
`getAxes` in interface `Convex`
Overrides:
`getAxes` in class `Polygon`
Parameters:
`foci` - the world space points representing foci of curved `Shape`s; can be null
`transform` - the local to world space `Transform` of this `Convex` `Shape`
Returns:
`Vector2`[]
• #### contains

```public boolean contains​(Vector2 point,
Transform transform)```
Description copied from interface: `Shape`
Returns true if the given point is inside this `Shape`.

If the given point lies on an edge the point is considered to be inside the `Shape`.

The given point is assumed to be in world space.

Specified by:
`contains` in interface `Shape`
Overrides:
`contains` in class `Polygon`
Parameters:
`point` - world space point
`transform` - `Transform` for this `Shape`
Returns:
boolean
• #### createMass

`public Mass createMass​(double density)`
Creates a `Mass` object using the geometric properties of this `Rectangle` and the given density.

m = d * h * w I = m * (h2 + w2) / 12

Specified by:
`createMass` in interface `Shape`
Overrides:
`createMass` in class `Polygon`
Parameters:
`density` - the density in kg/m2
Returns:
`Mass` the `Mass` of this `Rectangle`
• #### computeAABB

```public void computeAABB​(Transform transform,
AABB aabb)```
Description copied from interface: `Shape`
Computes the `AABB` from this `Shape` after applying the given transformation and places the result in the given `AABB`.
Specified by:
`computeAABB` in interface `Shape`
Overrides:
`computeAABB` in class `Polygon`
Parameters:
`transform` - the `Transform` for this `Shape`
`aabb` - the destination `AABB`