org.openimaj.math.geometry.shape

## Class Ellipse

• All Implemented Interfaces:
Cloneable, GeometricObject2d, Shape

```public class Ellipse
extends Object
implements Shape, Cloneable```
An ellipse shape
Author:
Sina Samangooei (ss@ecs.soton.ac.uk)
• ### Constructor Summary

Constructors
Constructor and Description
```Ellipse(double x, double y, double major, double minor, double rotation)```
Construct with centroid, semi-major and -minor axes, and rotation.
• ### 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
`Polygon` `calculateOrientedBoundingBox()`
Calculate the oriented bounding box.
`double` `calculatePerimeter()`
Calculate the perimeter of the shape
`Rectangle` `calculateRegularBoundingBox()`
Compute the regular (oriented to the axes) bounding box of the shape.
`Ellipse` `clone()`
`boolean` `equals(Object other)`
`double` `getHeight()`
`double` `getMajor()`
`double` `getMinor()`
`double` `getRotation()`
`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()`
`Jama.Matrix` `normTransformMatrix()`
Get the normalised transform matrix such that the scale of this ellipse is removed (i.e.
`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.
`IndependentPair<Jama.Matrix,Double>` `secondMomentsAndScale()`
`String` `toString()`
`Shape` `transform(Jama.Matrix transform)`
Apply a 3x3 transform matrix to a copy of the `GeometricObject2d` and return it
`Ellipse` `transformAffine(Jama.Matrix transform)`
`Jama.Matrix` `transformAffineCovar(Jama.Matrix transform)`
`Jama.Matrix` `transformMatrix()`
Get the transform matrix required to turn points on a unit circle into the points on this ellipse.
`void` ```translate(float x, float y)```
Translate the shapes position
• ### Methods inherited from class java.lang.Object

`finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• ### Constructor Detail

• #### Ellipse

```public Ellipse(double x,
double y,
double major,
double minor,
double rotation)```
Construct with centroid, semi-major and -minor axes, and rotation.
Parameters:
`x` - x-ordinate of centroid
`y` - y-ordinate of centroid
`major` - semi-major axis length
`minor` - semi-minor axis length
`rotation` - rotation
• ### Method Detail

• #### 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
• #### 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]
• #### calculateOrientedBoundingBox

`public Polygon calculateOrientedBoundingBox()`
Calculate the oriented bounding box. This is the smallest rotated rectangle that will fit around the ellipse.
Returns:
the oriented bounding box.
• #### 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
• #### 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
• #### 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
• #### 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
• #### transformAffineCovar

`public Jama.Matrix transformAffineCovar(Jama.Matrix transform)`
Parameters:
`transform` -
Returns:
transformed ellipse
• #### transformAffine

`public Ellipse transformAffine(Jama.Matrix transform)`
Parameters:
`transform` -
Returns:
transformed ellipse
• #### normTransformMatrix

`public Jama.Matrix normTransformMatrix()`
Get the normalised transform matrix such that the scale of this ellipse is removed (i.e. the semi-major axis is 1)
Returns:
the transform matrix
• #### transformMatrix

`public Jama.Matrix transformMatrix()`
Get the transform matrix required to turn points on a unit circle into the points on this ellipse. This function is used by `asPolygon()`
Returns:
the transform matrix
• #### 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
• #### getMinor

`public double getMinor()`
Returns:
The semi-minor axis length
• #### getMajor

`public double getMajor()`
Returns:
The semi-major axis length
• #### secondMomentsAndScale

`public IndependentPair<Jama.Matrix,Double> secondMomentsAndScale()`
Returns:
The second moment matrix and scale factor.
• #### equals

`public boolean equals(Object other)`
Overrides:
`equals` in class `Object`
• #### clone

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

`public double getRotation()`
Returns:
The rotation of the semi-major axis
• #### toString

`public String toString()`
Overrides:
`toString` in class `Object`
• #### 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
• #### 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
• #### 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