- Object
-
- AbstractShape
-
- Ellipse
-
- All Implemented Interfaces:
DataContainer
,Convex
,Rotatable
,Shape
,Transformable
,Translatable
public class Ellipse extends AbstractShape implements Convex, Shape, Transformable, DataContainer
Implementation of an EllipseConvex
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 theGeometry.createPolygonalEllipse(int, double, double)
method to create a half ellipsePolygon
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
-
-
Constructor Summary
Constructors Constructor Description Ellipse(double width, double height)
Minimal constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
computeAABB(Transform transform, AABB aabb)
boolean
contains(Vector2 point, Transform transform)
Returns true if the given point is inside thisShape
.Mass
createMass(double density)
Vector2[]
getAxes(Vector2[] foci, Transform transform)
Returns an array of separating axes to test for thisShape
.Feature
getFarthestFeature(Vector2 vector, Transform transform)
Returns theFeature
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.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()
Returns the rotation about the local center in radians.double
getWidth()
Returns the width.Interval
project(Vector2 vector, Transform transform)
void
rotate(Rotation rotation, double x, double y)
Rotates the object about the given point.String
toString()
-
Methods inherited from class AbstractShape
computeAABB, contains, createAABB, createAABB, getCenter, getRadius, getUserData, project, rotate, rotate, rotate, rotate, rotate, rotateAboutCenter, setUserData, translate, translate
-
Methods inherited from interface DataContainer
getUserData, setUserData
-
Methods inherited from interface Shape
computeAABB, contains, createAABB, createAABB, getCenter, getRadius, project, rotateAboutCenter
-
Methods inherited from interface Translatable
translate, translate
-
-
-
-
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 widthheight
- the height- Throws:
IllegalArgumentException
- if either the width or height is less than or equal to zero
-
-
Method Detail
-
toString
public String toString()
- Overrides:
toString
in classAbstractShape
-
getAxes
public Vector2[] getAxes(Vector2[] foci, Transform transform)
Returns an array of separating axes to test for thisShape
.The
foci
parameter is an array of circular focal points of the otherShape
.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.
-
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.
-
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 givenVector2
the first one is used.The returned point is in world space.
-
getFarthestFeature
public Feature getFarthestFeature(Vector2 vector, Transform transform)
Description copied from interface:Convex
Returns theFeature
farthest in the direction of the given vector.The returned feature is in world space.
-
project
public Interval project(Vector2 vector, Transform transform)
Description copied from interface:Shape
-
computeAABB
public void computeAABB(Transform transform, AABB aabb)
Description copied from interface:Shape
Computes theAABB
from thisShape
after applying the given transformation and places the result in the givenAABB
.- Specified by:
computeAABB
in interfaceShape
- Parameters:
transform
- theTransform
for thisShape
aabb
- the destinationAABB
-
createMass
public Mass createMass(double density)
Description copied from interface:Shape
- Specified by:
createMass
in interfaceShape
- Parameters:
density
- the density in kg/m2- Returns:
Mass
theMass
of thisShape
-
getRadius
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.
-
contains
public boolean contains(Vector2 point, Transform transform)
Description copied from interface:Shape
-
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 interfaceRotatable
- Overrides:
rotate
in classAbstractShape
- Parameters:
rotation
- theRotation
representing the rotation amountx
- the x coordinate to rotate abouty
- the y coordinate to rotate about
-
getRotationAngle
public double getRotationAngle()
Returns the rotation about the local center in radians.- Returns:
- double the rotation in radians
-
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
-
-