org.openimaj.math.geometry.shape

## Class RotatedRectangle

• All Implemented Interfaces:
Cloneable, GeometricObject2d, Shape

```public class RotatedRectangle
extends Object
implements Shape, Cloneable```
A rectangle rotated by an angle.
Author:
Jonathon Hare (jsh2@ecs.soton.ac.uk)
• ### Field Summary

Fields
Modifier and Type Field and Description
`float` `cx`
The x-ordinate of the centroid
`float` `cy`
The y-ordinate of the centroid
`float` `height`
The height of the rotated rectangle (Note that this is different to the height returned by `getHeight()` which is the height of the regular bounding box)
`float` `rotation`
`float` `width`
The width of the rotated rectangle (Note that this is different to the width returned by `getWidth()` which is the width of the regular bounding box)
• ### Constructor Summary

Constructors
Constructor and Description
```RotatedRectangle(double x, double y, double width, double height, double rotation)```
Construct with the given parameters
```RotatedRectangle(float x, float y, float width, float height, float rotation)```
Construct with the given parameters
```RotatedRectangle(Rectangle regRect, float rotation)```
Construct with a regular `Rectangle` rotated about its centroid
• ### Method Summary

All Methods
Modifier and Type Method and Description
`Polygon` `asPolygon()`
Convert the shape to a polygon representation
`double` `calculateArea()`
Calculate the area of the shape
`Point2d` `calculateCentroid()`
Calculate the centroid of the shape
`double` `calculatePerimeter()`
Calculate the perimeter of the shape
`Rectangle` `calculateRegularBoundingBox()`
Compute the regular (oriented to the axes) bounding box of the shape.
`RotatedRectangle` `clone()`
`double` `getHeight()`
`double` `getWidth()`
`double` `intersectionArea(Shape that)`
Calls `Polygon.intersectionArea(Shape, int)` with 1 step per pixel dimension.
`double` ```intersectionArea(Shape that, int nStepsPerDimension)```
Return an estimate for the area of the intersection of this polygon and another polygon.
`boolean` `isConvex()`
Test if the shape is convex.
`boolean` `isInside(Point2d point)`
Test whether the point p is inside the shape.
`double` `maxX()`
`double` `maxY()`
`RotatedRectangle` `minimumBoundingRectangle()`
Compute the minimum size rotated bounding rectangle that contains this shape.
`double` `minX()`
`double` `minY()`
`void` `scale(float sc)`
Scale the shape by the given amount about (0,0).
`void` ```scale(Point2d centre, float sc)```
Scale the shape by the given amount about the given point.
`void` `scaleCentroid(float sc)`
Scale the shape about its centroid.
`String` `toString()`
`Shape` `transform(Jama.Matrix transform)`
Apply a 3x3 transform matrix to a copy of the `GeometricObject2d` and return it
`void` ```translate(float x, float y)```
Translate the shapes position
• ### Methods inherited from class java.lang.Object

`equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• ### Field Detail

• #### width

`public float width`
The width of the rotated rectangle (Note that this is different to the width returned by `getWidth()` which is the width of the regular bounding box)
• #### height

`public float height`
The height of the rotated rectangle (Note that this is different to the height returned by `getHeight()` which is the height of the regular bounding box)
• #### rotation

`public float rotation`
• #### cx

`public float cx`
The x-ordinate of the centroid
• #### cy

`public float cy`
The y-ordinate of the centroid
• ### Constructor Detail

• #### RotatedRectangle

```public RotatedRectangle(Rectangle regRect,
float rotation)```
Construct with a regular `Rectangle` rotated about its centroid
Parameters:
`regRect` - the regular rectangle
`rotation` - the rotation angle in radians
• #### RotatedRectangle

```public RotatedRectangle(double x,
double y,
double width,
double height,
double rotation)```
Construct with the given parameters
Parameters:
`x` - the x-ordinate of the centroid
`y` - the y-ordinate of the centroid
`width` - the width
`height` - the height
`rotation` - the rotation
• #### RotatedRectangle

```public RotatedRectangle(float x,
float y,
float width,
float height,
float rotation)```
Construct with the given parameters
Parameters:
`x` - the x-ordinate of the centroid
`y` - the y-ordinate of the centroid
`width` - the width
`height` - the height
`rotation` - the rotation
• ### Method Detail

• #### calculateRegularBoundingBox

`public Rectangle calculateRegularBoundingBox()`
Description copied from interface: `GeometricObject2d`
Compute the regular (oriented to the axes) bounding box of the shape.
Specified by:
`calculateRegularBoundingBox` in interface `GeometricObject2d`
Returns:
the regular bounding box as [x,y,width,height]
• #### translate

```public void translate(float x,
float y)```
Description copied from interface: `GeometricObject2d`
Translate the shapes position
Specified by:
`translate` in interface `GeometricObject2d`
Parameters:
`x` - x-translation
`y` - y-translation
• #### scale

`public void scale(float sc)`
Description copied from interface: `GeometricObject2d`
Scale the shape by the given amount about (0,0). Scalefactors between 0 and 1 shrink the shape.
Specified by:
`scale` in interface `GeometricObject2d`
Parameters:
`sc` - the scale factor.
• #### scale

```public void scale(Point2d centre,
float sc)```
Description copied from interface: `GeometricObject2d`
Scale the shape by the given amount about the given point. Scalefactors between 0 and 1 shrink the shape.
Specified by:
`scale` in interface `GeometricObject2d`
Parameters:
`centre` - the centre of the scaling operation
`sc` - the scale factor
• #### scaleCentroid

`public void scaleCentroid(float sc)`
Description copied from interface: `GeometricObject2d`
Scale the shape about its centroid. Scalefactors between 0 and 1 shrink the shape.
Specified by:
`scaleCentroid` in interface `GeometricObject2d`
Parameters:
`sc` - the scale factor
• #### calculateCentroid

`public Point2d calculateCentroid()`
Description copied from interface: `GeometricObject2d`
Calculate the centroid of the shape
Specified by:
`calculateCentroid` in interface `GeometricObject2d`
Returns:
the centroid of the shape
• #### minX

`public double minX()`
Specified by:
`minX` in interface `GeometricObject2d`
Returns:
the minimum x-ordinate
• #### minY

`public double minY()`
Specified by:
`minY` in interface `GeometricObject2d`
Returns:
the minimum y-ordinate
• #### maxX

`public double maxX()`
Specified by:
`maxX` in interface `GeometricObject2d`
Returns:
the maximum x-ordinate
• #### maxY

`public double maxY()`
Specified by:
`maxY` in interface `GeometricObject2d`
Returns:
the maximum y-ordinate
• #### getWidth

`public double getWidth()`
Specified by:
`getWidth` in interface `GeometricObject2d`
Returns:
the width of the regular bounding box
• #### getHeight

`public double getHeight()`
Specified by:
`getHeight` in interface `GeometricObject2d`
Returns:
the height of the regular bounding box
• #### isInside

`public boolean isInside(Point2d point)`
Description copied from interface: `Shape`
Test whether the point p is inside the shape.
Specified by:
`isInside` in interface `Shape`
Parameters:
`point` - the point
Returns:
true if the point is inside; false otherwise
• #### calculateArea

`public double calculateArea()`
Description copied from interface: `Shape`
Calculate the area of the shape
Specified by:
`calculateArea` in interface `Shape`
Returns:
the area of the shape
• #### calculatePerimeter

`public double calculatePerimeter()`
Description copied from interface: `Shape`
Calculate the perimeter of the shape
Specified by:
`calculatePerimeter` in interface `Shape`
Returns:
the perimeter of the shape
• #### asPolygon

`public Polygon asPolygon()`
Description copied from interface: `Shape`
Convert the shape to a polygon representation
Specified by:
`asPolygon` in interface `Shape`
Returns:
a polygon representation of the shape
• #### intersectionArea

`public double intersectionArea(Shape that)`
Description copied from interface: `Shape`
Calls `Polygon.intersectionArea(Shape, int)` with 1 step per pixel dimension. Subsequently this function returns the shared whole pixels of this polygon and that.
Specified by:
`intersectionArea` in interface `Shape`
Returns:
intersection area
• #### intersectionArea

```public double intersectionArea(Shape that,
int nStepsPerDimension)```
Description copied from interface: `Shape`
Return an estimate for the area of the intersection of this polygon and another polygon. For each pixel step 1 is added if the point is inside both polygons. The length of a step in each direction is calculated as follows: max(intersectionWidth,intersectionHeight)/ (nStepsPerDimention) The total number of points inside the intersection of the shames is divided by the number of points read and multiplied by the total area of the intersection.
Specified by:
`intersectionArea` in interface `Shape`
Returns:
normalised intersection area
• #### transform

`public Shape transform(Jama.Matrix transform)`
Description copied from interface: `GeometricObject2d`
Apply a 3x3 transform matrix to a copy of the `GeometricObject2d` and return it
Specified by:
`transform` in interface `GeometricObject2d`
Specified by:
`transform` in interface `Shape`
Parameters:
`transform` - 3x3 transform matrix
Returns:
the transformed shape
• #### minimumBoundingRectangle

`public RotatedRectangle minimumBoundingRectangle()`
Description copied from interface: `Shape`
Compute the minimum size rotated bounding rectangle that contains this shape.
Specified by:
`minimumBoundingRectangle` in interface `Shape`
Returns:
the minimum bounding box
• #### clone

`public RotatedRectangle clone()`
Specified by:
`clone` in interface `Shape`
Overrides:
`clone` in class `Object`
Returns:
a copy of the shape
• #### toString

`public String toString()`
Overrides:
`toString` in class `Object`
• #### isConvex

`public boolean isConvex()`
Description copied from interface: `Shape`
Test if the shape is convex.
Specified by:
`isConvex` in interface `Shape`
Returns:
true if the shape is convex; false if non-convex