Module org.dyn4j

## Class Ellipse

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

```public class Ellipse
extends AbstractShape
implements Convex, Shape, Transformable, DataContainer```
Implementation of an Ellipse `Convex` `Shape`.

An ellipse must have a width and height greater than zero.

This shape is only supported by the GJK collision detection algorithm

An `UnsupportedOperationException` is thrown when this shape is used with SAT. If you are using or are planning on using the SAT collision detection algorithm, you can use the `Geometry.createPolygonalEllipse(int, double, double)` method to create a half ellipse `Polygon` approximation. Another option is to use the GJK or your own collision detection algorithm for this shape only and use SAT on others.

Since:
3.1.7
Version:
3.4.0
Author:
William Bittle
• ### Field Summary

Fields
Modifier and Type Field Description
`(package private) double` `halfHeight`
The half-height
`(package private) double` `halfWidth`
The half-width
`(package private) Rotation` `rotation`
The local rotation
• ### Fields inherited from class org.dyn4j.geometry.AbstractShape

`center, id, radius, userData`
• ### Constructor Summary

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

All Methods
Modifier and Type Method Description
`boolean` ```contains​(Vector2 point, Transform transform)```
Returns true if the given point is inside this `Shape`.
`AABB` `createAABB​(Transform transform)`
Creates an `AABB` from this `Shape` after applying the given transformation to the shape.
`Mass` `createMass​(double density)`
Creates a `Mass` object using the geometric properties of this `Shape` and the given density.
`Vector2[]` ```getAxes​(Vector2[] foci, Transform transform)```
Returns an array of separating axes to test for this `Shape`.
`Feature` ```getFarthestFeature​(Vector2 vector, Transform transform)```
Returns the `Feature` farthest in the direction of the given vector.
`Vector2` ```getFarthestPoint​(Vector2 vector, Transform transform)```
Returns the point farthest in the direction of the given vector.
`(package private) static Vector2` ```getFarthestPointOnBoundedEllipse​(double xmin, double xmax, double a, double b, Vector2 point)```
Performs a golden section search of the ellipse bounded between the interval [xmin, xmax] for the farthest point from the given point.
`(package private) static Vector2` ```getFarthestPointOnEllipse​(double a, double b, Vector2 point)```
Returns the point on this ellipse farthest from the given point.
`Vector2[]` `getFoci​(Transform transform)`
Returns an array of world space foci points for circular curved edges.
`double` `getHalfHeight()`
Returns the half height.
`double` `getHalfWidth()`
Returns the half width.
`double` `getHeight()`
Returns the height.
`double` `getRadius​(Vector2 center)`
Returns the radius of the shape if the given point was the center for this shape.
`Rotation` `getRotation()`
`double` `getRotationAngle()`
`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`.
`void` ```rotate​(Rotation rotation, double x, double y)```
Rotates the object about the given point.
`java.lang.String` `toString()`
• ### Methods inherited from class org.dyn4j.geometry.AbstractShape

`contains, createAABB, getCenter, getId, getRadius, getUserData, project, rotate, rotate, rotate, rotate, rotate, rotateAboutCenter, setUserData, translate, translate`
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• ### Methods inherited from interface org.dyn4j.DataContainer

`getUserData, setUserData`
• ### Methods inherited from interface org.dyn4j.geometry.Rotatable

`rotate, rotate, rotate, rotate, rotate`
• ### Methods inherited from interface org.dyn4j.geometry.Shape

`contains, createAABB, getCenter, getId, getRadius, project, rotateAboutCenter`
• ### Methods inherited from interface org.dyn4j.geometry.Translatable

`translate, translate`
• ### Field Detail

• #### halfWidth

`final double halfWidth`
The half-width
• #### halfHeight

`final double halfHeight`
The half-height
• #### rotation

`final Rotation rotation`
The local rotation
• ### Constructor Detail

• #### Ellipse

```public Ellipse​(double width,
double height)```
Minimal constructor.

This creates an axis-aligned ellipse fitting inside a rectangle of the given width and height centered at the origin.

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

• #### toString

`public java.lang.String toString()`
Overrides:
`toString` in class `AbstractShape`
• #### getAxes

```public Vector2[] getAxes​(Vector2[] foci,
Transform transform)```
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.

This method is not supported by this shape.

Specified by:
`getAxes` in interface `Convex`
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`[]
Throws:
`java.lang.UnsupportedOperationException` - when called
• #### getFoci

`public Vector2[] getFoci​(Transform transform)`
Returns an array of world space foci points for circular curved edges.

This method returns null if the `Shape` has zero curved edges.

The returned points are in world space.

This method is not supported by this shape.

Specified by:
`getFoci` in interface `Convex`
Parameters:
`transform` - the local to world space `Transform` of this `Convex` `Shape`
Returns:
`Vector2`[]
Throws:
`java.lang.UnsupportedOperationException` - when called
• #### getFarthestPoint

```public Vector2 getFarthestPoint​(Vector2 vector,
Transform transform)```
Description copied from interface: `Convex`
Returns the point farthest in the direction of the given vector. If two points are equally distant along the given `Vector2` the first one is used.

The returned point is in world space.

Specified by:
`getFarthestPoint` in interface `Convex`
Parameters:
`vector` - the direction
`transform` - the local to world space `Transform` of this `Convex` `Shape`
Returns:
`Vector2`
• #### getFarthestFeature

```public Feature getFarthestFeature​(Vector2 vector,
Transform transform)```
Description copied from interface: `Convex`
Returns the `Feature` farthest in the direction of the given vector.

The returned feature is in world space.

Specified by:
`getFarthestFeature` in interface `Convex`
Parameters:
`vector` - the direction
`transform` - the local to world space `Transform` of this `Convex` `Shape`
Returns:
`Feature`
• #### createMass

`public Mass createMass​(double density)`
Description copied from interface: `Shape`
Creates a `Mass` object using the geometric properties of this `Shape` and the given density.
Specified by:
`createMass` in interface `Shape`
Parameters:
`density` - the density in kg/m2
Returns:
`Mass` the `Mass` of this `Shape`

`public double getRadius​(Vector2 center)`
Description copied from interface: `Shape`
Returns the radius of the shape if the given point was the center for this shape.
Specified by:
`getRadius` in interface `Shape`
Parameters:
`center` - the center point
Returns:
double
• #### getFarthestPointOnEllipse

```static final Vector2 getFarthestPointOnEllipse​(double a,
double b,
Vector2 point)```
Returns the point on this ellipse farthest from the given point.

This method assumes that this ellipse is centered on the origin and has it's semi-major axis aligned with the x-axis and its semi-minor axis aligned with the y-axis.

This method performs a Golden Section Search to find the point of maximum distance from the given point.

Parameters:
`a` - the half width of the ellipse
`b` - the half height of the ellipse
`point` - the query point
Returns:
`Vector2`
Since:
3.4.0
• #### getFarthestPointOnBoundedEllipse

```static final Vector2 getFarthestPointOnBoundedEllipse​(double xmin,
double xmax,
double a,
double b,
Vector2 point)```
Performs a golden section search of the ellipse bounded between the interval [xmin, xmax] for the farthest point from the given point.

This method assumes that this ellipse is centered on the origin and has it's semi-major axis aligned with the x-axis and its semi-minor axis aligned with the y-axis.

Parameters:
`xmin` - the minimum x value
`xmax` - the maximum x value
`a` - the half width of the ellipse
`b` - the half height of the ellipse
`point` - the query point
Returns:
`Vector2`
Since:
3.4.0
• #### 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`
Parameters:
`point` - world space point
`transform` - `Transform` for this `Shape`
Returns:
boolean
• #### rotate

```public void rotate​(Rotation rotation,
double x,
double y)```
Description copied from interface: `Rotatable`
Rotates the object about the given point.
Specified by:
`rotate` in interface `Rotatable`
Overrides:
`rotate` in class `AbstractShape`
Parameters:
`rotation` - the `Rotation` representing the rotation amount
`x` - the x coordinate to rotate about
`y` - the y coordinate to rotate about
• #### getRotationAngle

`public double getRotationAngle()`
Returns:
• #### getRotation

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

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

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

`public double getHalfWidth()`
Returns the half width.
Returns:
double
• #### getHalfHeight

`public double getHalfHeight()`
Returns the half height.
Returns:
double