DataContainer
, Convex
, Rotatable
, Shape
, Transformable
, Translatable
public class Capsule extends AbstractShape implements Convex, Shape, Transformable, DataContainer
Convex
Shape
.
A capsule can be described as a rectangle with two half circle caps on both ends. A capsule is created
by specifying the bounding rectangle of the entire Shape
.
If the height is larger than the width the caps will be on the top and bottom of the shape. Otherwise the caps are on the left and right ends of the shape.
A capsule's width and height must be larger than zero and cannot be equal. A Circle
should be used
instead of an equal width/height capsule for both performance and stability.
Constructor | Description |
---|---|
Capsule(double width,
double height) |
Minimal constructor.
|
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) |
|
Mass |
createMass(double density) |
|
Vector2[] |
getAxes(Vector2[] foci,
Transform transform) |
Returns an array of separating axes to test for this
Shape . |
double |
getCapRadius() |
Returns the end cap radius.
|
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.
|
Vector2[] |
getFoci(Transform transform) |
Returns an array of world space foci points for circular curved edges.
|
double |
getLength() |
Returns the length of the capsule.
|
double |
getRadius(Vector2 center) |
Returns the radius of the shape if the given point was the
center for this shape.
|
double |
getRotation() |
Returns the rotation about the local center in radians in the range [-π, π].
|
Interval |
project(Vector2 vector,
Transform transform) |
|
void |
rotate(double theta,
double x,
double y) |
Rotates the object about the given coordinates.
|
java.lang.String |
toString() |
|
void |
translate(double x,
double y) |
Translates the object the given amounts in the respective directions.
|
contains, createAABB, getCenter, getId, getRadius, getUserData, hashCode, project, rotate, rotate, rotateAboutCenter, setUserData, translate
getUserData, setUserData
contains, createAABB, getCenter, getId, getRadius, project, rotateAboutCenter
translate
public Capsule(double width, double height)
Creates an axis-aligned capsule centered on the origin with the caps on ends of the larger dimension.
width
- the bounding rectangle widthheight
- the bounding rectangle heightjava.lang.IllegalArgumentException
- thrown if width or height are less than or equal to zero or if the width and height are near equalpublic java.lang.String toString()
toString
in class AbstractShape
public Vector2[] getAxes(Vector2[] foci, Transform transform)
Convex
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.
public Vector2[] getFoci(Transform transform)
Convex
This method returns null if the Shape
has zero curved edges.
The returned points are in world space.
public Vector2 getFarthestPoint(Vector2 vector, Transform transform)
Convex
Vector2
the first one is used.
The returned point is in world space.
public Feature getFarthestFeature(Vector2 vector, Transform transform)
Convex
Feature
farthest in the direction of the given vector.
The returned feature is in world space.
public Interval project(Vector2 vector, Transform transform)
Shape
public Mass createMass(double density)
Shape
createMass
in interface Shape
density
- the density in kg/m2Mass
the Mass
of this Shape
public double getRadius(Vector2 center)
Shape
public boolean contains(Vector2 point, Transform transform)
Shape
public void rotate(double theta, double x, double y)
Rotatable
rotate
in interface Rotatable
rotate
in class AbstractShape
theta
- the angle of rotation in radiansx
- the x coordinate to rotate abouty
- the y coordinate to rotate aboutpublic void translate(double x, double y)
Translatable
translate
in interface Translatable
translate
in class AbstractShape
x
- the translation in the x directiony
- the translation in the y directionpublic double getRotation()
public double getLength()
The length is the largest dimension of the capsule's bounding rectangle.
public double getCapRadius()