public final class Geometry
extends java.lang.Object
This class can be used to create Shape
s of varying types via the create
* methods.
While Shape
s can be created using their constructors as well, the methods here can place their
centers on the origin and also make copies of the given input to avoid reuse issues.
This class also contains various helper methods for cleaning vector arrays and lists and performing
various operations on Shape
s.
Modifier and Type | Field and Description |
---|---|
static double |
INV_3
The value of 1/3
|
static double |
INV_SQRT_3
The value of the inverse of the square root of 3; 1/sqrt(3)
|
static double |
TWO_PI
2 * PI constant
|
Constructor and Description |
---|
Geometry() |
Modifier and Type | Method and Description |
---|---|
static java.util.List<Vector2> |
cleanse(java.util.List<Vector2> points)
Returns a new list containing the 'cleansed' version of the given listing of polygon points.
|
static Vector2[] |
cleanse(Vector2... points)
Returns a new array containing the 'cleansed' version of the given array of polygon points.
|
static Capsule |
createCapsule(double width,
double height)
Creates a new
Capsule bounded by the given rectangle width and height. |
static Circle |
createCircle(double radius)
Returns a new
Circle with the given radius centered on the origin. |
static Ellipse |
createEllipse(double width,
double height)
Creates a new
Ellipse bounded by the given rectangle width and height. |
static Triangle |
createEquilateralTriangle(double height)
Creates an equilateral
Triangle with the center at the origin. |
static HalfEllipse |
createHalfEllipse(double width,
double height)
Creates a new
HalfEllipse bounded by the given rectangle width and height. |
static HalfEllipse |
createHalfEllipseAtOrigin(double width,
double height)
Creates a new
HalfEllipse bounded by the given rectangle width and height. |
static Segment |
createHorizontalSegment(double length)
Creates a new
Segment with the given length with the center
at the origin. |
static Triangle |
createIsoscelesTriangle(double width,
double height)
Creates an isosceles
Triangle with the center at the origin. |
static java.util.List<Link> |
createLinks(java.util.List<Vector2> vertices,
boolean closed)
Creates a list of
Link s for the given vertices. |
static java.util.List<Link> |
createLinks(Vector2[] vertices,
boolean closed)
Creates a
Link chain for the given vertices. |
static Polygon |
createPolygon(Vector2... vertices)
Returns a new
Polygon with the given vertices. |
static Polygon |
createPolygonalCapsule(int count,
double width,
double height)
Creates a new
Polygon in the shape of a capsule using count number of vertices on each
cap, centered on the origin. |
static Polygon |
createPolygonalCircle(int count,
double radius)
Creates a new
Polygon in the shape of a circle with count number of vertices centered
on the origin. |
static Polygon |
createPolygonalCircle(int count,
double radius,
double theta)
Creates a new
Polygon in the shape of a circle with count number of vertices centered
on the origin. |
static Polygon |
createPolygonalEllipse(int count,
double width,
double height)
Creates a new
Polygon in the shape of an ellipse with count number of vertices centered
on the origin. |
static Polygon |
createPolygonalHalfEllipse(int count,
double width,
double height)
Creates a new
Polygon in the shape of a half ellipse with count number of vertices with the
base at the origin. |
static Polygon |
createPolygonalHalfEllipseAtOrigin(int count,
double width,
double height)
Creates a new
Polygon in the shape of a half ellipse with count number of vertices centered
on the origin. |
static Polygon |
createPolygonalSlice(int count,
double radius,
double theta)
|
static Polygon |
createPolygonalSliceAtOrigin(int count,
double radius,
double theta)
|
static Polygon |
createPolygonAtOrigin(Vector2... vertices)
Returns a new
Polygon , using the given vertices, centered at the origin. |
static Rectangle |
createRectangle(double width,
double height)
Creates a new
Rectangle with the given width and height centered at the origin. |
static Triangle |
createRightTriangle(double width,
double height)
Creates a right angle
Triangle with the center at the origin. |
static Triangle |
createRightTriangle(double width,
double height,
boolean mirror)
Creates a right angle
Triangle with the center at the origin. |
static Segment |
createSegment(Vector2 end)
Creates a new
Segment from the origin to the given end point |
static Segment |
createSegment(Vector2 p1,
Vector2 p2)
Creates a new
Segment with the given points. |
static Segment |
createSegmentAtOrigin(Vector2 p1,
Vector2 p2)
Creates a new
Segment with the given points. |
static Slice |
createSlice(double radius,
double theta)
Creates a new
Slice with the given circle radius and arc length theta. |
static Slice |
createSliceAtOrigin(double radius,
double theta)
Creates a new
Slice with the given circle radius and arc length theta. |
static Rectangle |
createSquare(double size)
Creates a square (equal height and width
Rectangle ) with the given size
centered at the origin. |
static Triangle |
createTriangle(Vector2 p1,
Vector2 p2,
Vector2 p3)
Creates a new
Triangle , using the given points. |
static Triangle |
createTriangleAtOrigin(Vector2 p1,
Vector2 p2,
Vector2 p3)
Creates a new
Triangle with the given points centered at the origin. |
static Polygon |
createUnitCirclePolygon(int count,
double radius)
Returns a new
Polygon with count number of points, where the
points are evenly distributed around the unit circle. |
static Polygon |
createUnitCirclePolygon(int count,
double radius,
double theta)
Returns a new
Polygon with count number of points, where the
points are evenly distributed around the unit circle. |
static Segment |
createVerticalSegment(double length)
Creates a new
Segment with the given length with the center
at the origin. |
static Polygon |
flip(Polygon polygon,
Vector2 axis)
Flips the given polygon about the given line and returns the result
as a new polygon.
|
static Polygon |
flip(Polygon polygon,
Vector2 axis,
Vector2 point)
Flips the given polygon about the given line and returns the result
as a new polygon.
|
static Polygon |
flipAlongTheXAxis(Polygon polygon)
Flips the given polygon about its center along the x-axis and
returns the result as a new polygon.
|
static Polygon |
flipAlongTheXAxis(Polygon polygon,
Vector2 point)
Flips the given polygon about the given point along the x-axis and
returns the result as a new polygon.
|
static Polygon |
flipAlongTheYAxis(Polygon polygon)
Flips the given polygon about its center along the y-axis and
returns the result as a new polygon.
|
static Polygon |
flipAlongTheYAxis(Polygon polygon,
Vector2 point)
Flips the given polygon about the given point along the y-axis and
returns the result as a new polygon.
|
static Vector2 |
getAreaWeightedCenter(java.util.List<Vector2> points)
Returns the area weighted centroid for the given points.
|
static Vector2 |
getAreaWeightedCenter(Vector2... points)
Returns the area weighted centroid for the given points.
|
static Vector2 |
getAverageCenter(java.util.List<Vector2> points)
Returns the centroid of the given points by performing an average.
|
static Vector2 |
getAverageCenter(Vector2... points)
Returns the centroid of the given points by performing an average.
|
static Vector2[] |
getCounterClockwiseEdgeNormals(Vector2... vertices)
Returns an array of normalized vectors representing the normals of all the
edges given the vertices.
|
static double |
getRotationRadius(Vector2... vertices)
Returns the maximum radius of the given vertices rotated about the origin.
|
static double |
getRotationRadius(Vector2 center,
Vector2... vertices)
Returns the maximum radius of the given vertices rotated about the given center.
|
static double |
getWinding(java.util.List<Vector2> points)
Returns the winding, Clockwise or Counter-Clockwise, for the given
list of points of a polygon.
|
static double |
getWinding(Vector2... points)
Returns the winding, Clockwise or Counter-Clockwise, for the given
array of points of a polygon.
|
static Polygon |
minkowskiSum(Circle circle,
Polygon polygon,
int count)
|
static <E extends Wound & Convex> |
minkowskiSum(E convex1,
E convex2)
Returns the Minkowski Sum of the given convex shapes.
|
static Polygon |
minkowskiSum(Polygon polygon,
Circle circle,
int count)
|
static Polygon |
minkowskiSum(Polygon polygon,
double radius,
int count)
Returns a new polygon that has been radially expanded.
|
static void |
reverseWinding(java.util.List<Vector2> points)
Reverses the order of the polygon points within the given list.
|
static void |
reverseWinding(Vector2... points)
Reverses the order of the polygon points within the given array.
|
static Capsule |
scale(Capsule capsule,
double scale)
Returns a scaled version of the given capsule.
|
static Circle |
scale(Circle circle,
double scale)
Returns a scaled version of the given circle.
|
static Ellipse |
scale(Ellipse ellipse,
double scale)
Returns a scaled version of the given ellipse.
|
static HalfEllipse |
scale(HalfEllipse halfEllipse,
double scale)
Returns a scaled version of the given half-ellipse.
|
static Polygon |
scale(Polygon polygon,
double scale)
Returns a scaled version of the given polygon.
|
static Segment |
scale(Segment segment,
double scale)
Returns a scaled version of the given segment.
|
static Slice |
scale(Slice slice,
double scale)
Returns a scaled version of the given slice.
|
public static final double TWO_PI
public static final double INV_3
public static final double INV_SQRT_3
public static final double getWinding(java.util.List<Vector2> points)
This method determines the winding by computing a signed "area".
points
- the points of a polygonjava.lang.NullPointerException
- if points is null or an element of points is nulljava.lang.IllegalArgumentException
- if points contains less than 2 elementspublic static final double getWinding(Vector2... points)
points
- the points of a polygonjava.lang.NullPointerException
- if points is null or an element of points is nulljava.lang.IllegalArgumentException
- if points contains less than 2 elementspublic static final void reverseWinding(Vector2... points)
This method performs a simple array reverse.
points
- the polygon pointsjava.lang.NullPointerException
- if points is nullpublic static final void reverseWinding(java.util.List<Vector2> points)
This method performs a simple list reverse.
points
- the polygon pointsjava.lang.NullPointerException
- if points is nullpublic static final Vector2 getAverageCenter(java.util.List<Vector2> points)
points
- the list of pointsVector2
the centroidjava.lang.NullPointerException
- if points is null or an element of points is nulljava.lang.IllegalArgumentException
- if points is an empty listpublic static final Vector2 getAverageCenter(Vector2... points)
points
- the array of pointsVector2
the centroidjava.lang.NullPointerException
- if points is null or an element of points is nulljava.lang.IllegalArgumentException
- if points is an empty arraygetAverageCenter(List)
public static final Vector2 getAreaWeightedCenter(java.util.List<Vector2> points)
A Polygon
's centroid must be computed by the area weighted method since the
average method can be bias to one side if there are more points on that one
side than another.
Finding the area of a Polygon
can be done by using the following
summation:
0.5 * ∑(xi * yi + 1 - xi + 1 * yi)
Finding the area weighted centroid can be done by using the following summation:1 / (6 * A) * ∑(pi + pi + 1) * (xi * yi + 1 - xi + 1 * yi)
public static final Vector2 getAreaWeightedCenter(Vector2... points)
points
- the Polygon
pointsVector2
the area weighted centroidjava.lang.NullPointerException
- if points is null or an element of points is nulljava.lang.IllegalArgumentException
- if points is emptygetAreaWeightedCenter(List)
public static final double getRotationRadius(Vector2... vertices)
If the vertices array is null or empty, zero is returned.
vertices
- the polygon verticesgetRotationRadius(Vector2, Vector2...)
public static final double getRotationRadius(Vector2 center, Vector2... vertices)
If the vertices array is null or empty, zero is returned. If center is null the origin will be used instead.
center
- the center pointvertices
- the polygon verticespublic static final Vector2[] getCounterClockwiseEdgeNormals(Vector2... vertices)
This method assumes counter-clockwise ordering.
Returns null if the given vertices array is null or empty.
vertices
- the verticesVector2
[]java.lang.NullPointerException
- if vertices contains a null elementpublic static final Circle createCircle(double radius)
Circle
with the given radius centered on the origin.radius
- the radius in metersCircle
java.lang.IllegalArgumentException
- if radius is less than or equal to zeropublic static final Polygon createPolygon(Vector2... vertices)
Polygon
with the given vertices.
This method makes a copy of both the array and the vertices within the array to
create the new Polygon
.
The center of the Polygon
will be computed using the area weighted method.
vertices
- the array of verticesPolygon
java.lang.NullPointerException
- if vertices is null or an element of vertices is nulljava.lang.IllegalArgumentException
- if vertices contains less than 3 non-null verticesto create a new {@link Polygon} that is centered on the origin
public static final Polygon createPolygonAtOrigin(Vector2... vertices)
Polygon
, using the given vertices, centered at the origin.
This method makes a copy of both the array and the vertices within the array to
create the new Polygon
.
This method translates the Polygon
vertices so that the center is at the origin.
vertices
- the array of verticesPolygon
java.lang.NullPointerException
- if vertices is null or an element of vertices is nulljava.lang.IllegalArgumentException
- if vertices contains less than 3 non-null verticespublic static final Polygon createUnitCirclePolygon(int count, double radius)
Polygon
with count number of points, where the
points are evenly distributed around the unit circle. The resulting Polygon
will be centered on the origin.
The radius parameter is the distance from the center of the polygon to each vertex.
count
- the number of verticesradius
- the radius from the center to each vertex in metersPolygon
java.lang.IllegalArgumentException
- if count is less than 3 or radius is less than or equal to zerocreateUnitCirclePolygon(int, double, double)
,
createPolygonalCircle(int, double)
,
createPolygonalCircle(int, double, double)
public static final Polygon createUnitCirclePolygon(int count, double radius, double theta)
Polygon
with count number of points, where the
points are evenly distributed around the unit circle. The resulting Polygon
will be centered on the origin.
The radius parameter is the distance from the center of the polygon to each vertex.
The theta parameter is a vertex angle offset used to rotate all the vertices by the given amount.
count
- the number of verticesradius
- the radius from the center to each vertex in meterstheta
- the vertex angle offset in radiansPolygon
java.lang.IllegalArgumentException
- if count is less than 3 or radius is less than or equal to zerocreatePolygonalCircle(int, double, double)
public static final Rectangle createSquare(double size)
Rectangle
) with the given size
centered at the origin.size
- the size in metersRectangle
java.lang.IllegalArgumentException
- if size is less than or equal to zeropublic static final Rectangle createRectangle(double width, double height)
Rectangle
with the given width and height centered at the origin.width
- the width in metersheight
- the height in metersRectangle
java.lang.IllegalArgumentException
- if width or height is less than or equal to zeropublic static final Triangle createTriangle(Vector2 p1, Vector2 p2, Vector2 p3)
Triangle
, using the given points.
This method makes a copy of the given points to create the Triangle
.
The center of the Triangle
will be computed using the area weighted method.
p1
- the first pointp2
- the second pointp3
- the third pointTriangle
java.lang.NullPointerException
- if p1, p2, or p3 is nullto create a new {@link Triangle} that is centered on the origin
public static final Triangle createTriangleAtOrigin(Vector2 p1, Vector2 p2, Vector2 p3)
Triangle
with the given points centered at the origin.
This method makes a copy of the given points to create the Triangle
.
p1
- the first pointp2
- the second pointp3
- the third pointTriangle
java.lang.NullPointerException
- if p1, p2, or p3 is nullpublic static final Triangle createRightTriangle(double width, double height)
Triangle
with the center at the origin.width
- the width of the base in metersheight
- the height in metersTriangle
java.lang.IllegalArgumentException
- if width or height is less than or equal to zeropublic static final Triangle createRightTriangle(double width, double height, boolean mirror)
Triangle
with the center at the origin.width
- the width of the base in metersheight
- the height in metersmirror
- true if the triangle should be mirrored along the y-axisTriangle
java.lang.IllegalArgumentException
- if width or height is less than or equal to zeropublic static final Triangle createEquilateralTriangle(double height)
Triangle
with the center at the origin.height
- the height of the triangle in metersTriangle
java.lang.IllegalArgumentException
- if height is less than or equal to zeropublic static final Triangle createIsoscelesTriangle(double width, double height)
Triangle
with the center at the origin.width
- the width of the base in metersheight
- the height in metersTriangle
java.lang.IllegalArgumentException
- if width or height is less than or equal to zeropublic static final Segment createSegment(Vector2 p1, Vector2 p2)
Segment
with the given points.
This method makes a copy of the given points to create the Segment
.
The center of the Segment
will be the average of the two points.
p1
- the first pointp2
- the second pointSegment
java.lang.NullPointerException
- if p1 or p2 is nullto create a {@link Segment} centered on the origin
public static final Segment createSegmentAtOrigin(Vector2 p1, Vector2 p2)
Segment
with the given points.
This method makes a copy of the given points to create the Segment
.
This method translates the Segment
vertices so that the center is at the origin.
p1
- the first pointp2
- the second pointSegment
java.lang.NullPointerException
- if p1 or p2 is nullpublic static final Segment createSegment(Vector2 end)
Segment
from the origin to the given end point
This method makes a copy of the given point to create the Segment
.
end
- the end pointSegment
java.lang.NullPointerException
- if end is nullpublic static final Segment createHorizontalSegment(double length)
Segment
with the given length with the center
at the origin.
Renamed from createSegment(double).
length
- the length of the segment in metersSegment
java.lang.IllegalArgumentException
- if length is less than or equal to zeropublic static final Segment createVerticalSegment(double length)
Segment
with the given length with the center
at the origin.length
- the length of the segment in metersSegment
java.lang.IllegalArgumentException
- if length is less than or equal to zeropublic static final Capsule createCapsule(double width, double height)
Capsule
bounded by the given rectangle width and height.
The capsule will be axis-aligned and centered on the origin with the caps on the ends of the largest dimension.
If width and height are equal use a Circle
shape instead.
width
- the bounding rectangle widthheight
- the bounding rectangle heightCapsule
java.lang.IllegalArgumentException
- if width or height are less than or equal to zeropublic static final Slice createSlice(double radius, double theta)
Slice
with the given circle radius and arc length theta.
A Slice
is an arbitrary slice of a circle. The specified radius is the radius
of the circle. The slice will be positioned with the circle center on the origin.
Theta is the total arc length of the slice specified in radians. Theta is halved, putting half the arc length below the x-axis and half above.
Theta cannot be greater than π.
radius
- the circle radiustheta
- the total arc length in radiansSlice
java.lang.IllegalArgumentException
- if radius is less than or equal to zero; if theta is less than or equal to zero or is greater than πpublic static final Slice createSliceAtOrigin(double radius, double theta)
Slice
with the given circle radius and arc length theta.
A Slice
is an arbitrary slice of a circle. The specified radius is the radius
of the circle. The slice will be positioned with the centroid at the origin.
Theta is the total arc length of the slice specified in radians. Theta is halved, putting half the arc length below the x-axis and half above.
Theta cannot be greater than π.
radius
- the circle radiustheta
- the total arc length in radiansSlice
java.lang.IllegalArgumentException
- if radius is less than or equal to zero; if theta is less than or equal to zero or is greater than πpublic static final Ellipse createEllipse(double width, double height)
Ellipse
bounded by the given rectangle width and height.
The ellipse will be axis-aligned and centered on the origin.
If width and height are equal use a Circle
shape instead.
width
- the bounding rectangle widthheight
- the bounding rectangle heightEllipse
java.lang.IllegalArgumentException
- if width or height are less than or equal to zeropublic static final HalfEllipse createHalfEllipse(double width, double height)
HalfEllipse
bounded by the given rectangle width and height.
The ellipse will be axis-aligned with the base of the half ellipse on the x-axis. The given height is the height of the half, not the height of the full ellipse.
If width and height are equal use a Slice
shape with theta = Math.PI
instead.
width
- the bounding rectangle widthheight
- the bounding rectangle heightHalfEllipse
java.lang.IllegalArgumentException
- if width or height are less than or equal to zeropublic static final HalfEllipse createHalfEllipseAtOrigin(double width, double height)
HalfEllipse
bounded by the given rectangle width and height.
The ellipse will be axis-aligned with the base of the half ellipse on the x-axis. The given height is the height of the half, not the height of the full ellipse.
If width and height are equal use a Slice
shape with theta = Math.PI
instead.
width
- the bounding rectangle widthheight
- the bounding rectangle heightHalfEllipse
java.lang.IllegalArgumentException
- if width or height are less than or equal to zeropublic static final Polygon createPolygonalCircle(int count, double radius)
Polygon
in the shape of a circle with count number of vertices centered
on the origin.count
- the number of vertices to use; must be greater than 2radius
- the radius of the circle; must be greater than zeroPolygon
java.lang.IllegalArgumentException
- thrown if count is less than 3 or the radius is less than or equal to zeropublic static final Polygon createPolygonalCircle(int count, double radius, double theta)
Polygon
in the shape of a circle with count number of vertices centered
on the origin.count
- the number of vertices to use; must be greater than or equal to 3radius
- the radius of the circle; must be greater than zerotheta
- the radial offset for the points in radiansPolygon
java.lang.IllegalArgumentException
- thrown if count is less than 3 or the radius is less than or equal to zeropublic static final Polygon createPolygonalSlice(int count, double radius, double theta)
Polygon
in the shape of a Slice
with count number of vertices with the
circle center centered on the origin.
This method returns a polygon with count + 3 vertices.
count
- the number of vertices to use; must be greater than or equal to 1radius
- the radius of the circle; must be greater than zerotheta
- the arc length of the slice in radians; must be greater than zeroPolygon
java.lang.IllegalArgumentException
- thrown if count is less than 1 or the radius is less than or equal to zero or theta is less than or equal to zeropublic static final Polygon createPolygonalSliceAtOrigin(int count, double radius, double theta)
Polygon
in the shape of a Slice
with count number of vertices centered on the origin.
This method returns a polygon with count + 3 vertices.
count
- the number of vertices to use; must be greater than or equal to 1radius
- the radius of the circle; must be greater than zerotheta
- the arc length of the slice in radians; must be greater than zeroPolygon
java.lang.IllegalArgumentException
- thrown if count is less than 1 or the radius is less than or equal to zero or theta is less than or equal to zeropublic static final Polygon createPolygonalEllipse(int count, double width, double height)
Polygon
in the shape of an ellipse with count number of vertices centered
on the origin.
The count should be greater than or equal to 4 and a multiple of 2. If not, the returned polygon will have count - 1 vertices.
count
- the number of vertices to use; must be greater than or equal to 4; should be even, if not, count - 1 vertices will be generatedwidth
- the width of the ellipseheight
- the height of the ellipsePolygon
java.lang.IllegalArgumentException
- thrown if count is less than 4 or the width or height are less than or equal to zeropublic static final Polygon createPolygonalHalfEllipse(int count, double width, double height)
Polygon
in the shape of a half ellipse with count number of vertices with the
base at the origin.
Returns a polygon with count + 2 vertices.
The height is the total height of the half not the half height.
count
- the number of vertices to use; must be greater than or equal to 1width
- the width of the half ellipseheight
- the height of the half ellipse; should be the total heightPolygon
java.lang.IllegalArgumentException
- thrown if count is less than 1 or the width or height are less than or equal to zeropublic static final Polygon createPolygonalHalfEllipseAtOrigin(int count, double width, double height)
Polygon
in the shape of a half ellipse with count number of vertices centered
on the origin.
Returns a polygon with count + 2 vertices.
The height is the total height of the half not the half height.
count
- the number of vertices to use; should be even, if not, count - 1 vertices will be generatedwidth
- the width of the half ellipseheight
- the height of the half ellipse; should be the total heightPolygon
java.lang.IllegalArgumentException
- thrown if count is less than 1 or the width or height are less than or equal to zeropublic static final Polygon createPolygonalCapsule(int count, double width, double height)
Polygon
in the shape of a capsule using count number of vertices on each
cap, centered on the origin. The caps will be on the ends of the largest dimension.
The returned polygon will have 4 + 2 * count number of vertices.
count
- the number of vertices to use for one cap; must be greater than or equal to 1width
- the bounding rectangle widthheight
- the bounding rectangle heightPolygon
public static final java.util.List<Vector2> cleanse(java.util.List<Vector2> points)
This method ensures the polygon has CCW winding, removes colinear vertices, and removes coincident vertices.
If the given list is empty, the list is returned.
points
- the list polygon pointsVector2
>java.lang.NullPointerException
- if points is null or if points contains null elementspublic static final Vector2[] cleanse(Vector2... points)
This method ensures the polygon has CCW winding, removes colinear vertices, and removes coincident vertices.
points
- the list polygon pointsVector2
[]java.lang.NullPointerException
- if points is null or points contains null elementspublic static final Polygon flipAlongTheXAxis(Polygon polygon)
This method assumes that the line is through the origin.
polygon
- the polygon to flipPolygon
java.lang.NullPointerException
- if the given polygon is nullflip(Polygon, Vector2)
,
flip(Polygon, Vector2, Vector2)
public static final Polygon flipAlongTheYAxis(Polygon polygon)
This method assumes that the line is through the origin.
polygon
- the polygon to flipPolygon
java.lang.NullPointerException
- if the given polygon is nullflip(Polygon, Vector2)
,
flip(Polygon, Vector2, Vector2)
public static final Polygon flipAlongTheXAxis(Polygon polygon, Vector2 point)
polygon
- the polygon to flippoint
- the point to flip aboutPolygon
java.lang.NullPointerException
- if the given polygon is nullflip(Polygon, Vector2)
,
flip(Polygon, Vector2, Vector2)
public static final Polygon flipAlongTheYAxis(Polygon polygon, Vector2 point)
polygon
- the polygon to flippoint
- the point to flip aboutPolygon
java.lang.NullPointerException
- if the given polygon is nullflip(Polygon, Vector2)
,
flip(Polygon, Vector2, Vector2)
public static final Polygon flip(Polygon polygon, Vector2 axis)
This method assumes that the line is through the origin.
polygon
- the polygon to flipaxis
- the axis to flip aboutPolygon
java.lang.NullPointerException
- if the given polygon or axis is nulljava.lang.IllegalArgumentException
- if the given axis is the zero vectorflip(Polygon, Vector2, Vector2)
public static final Polygon flip(Polygon polygon, Vector2 axis, Vector2 point)
polygon
- the polygon to flipaxis
- the axis to flip aboutpoint
- the point to flip about; if null, the polygon center is usedPolygon
java.lang.NullPointerException
- if the given polygon or axis is nulljava.lang.IllegalArgumentException
- if the given axis is the zero vectorpublic static final <E extends Wound & Convex> Polygon minkowskiSum(E convex1, E convex2)
This method computes the Minkowski Sum in O(n + m) time where n and m are the number of vertices of the first and second convex respectively.
This method accepts any Convex
Wound
shape which basically means
Polygon
s or Segment
s.
This method throws an IllegalArgumentException if two Segment
s are supplied
that are colinear (in this case the resulting Minkowski Sum would be another segment
rather than a polygon).
E
- either a Wound
or Convex
typeconvex1
- the first convexconvex2
- the second convexPolygon
java.lang.NullPointerException
- if convex1 or convex2 are nulljava.lang.IllegalArgumentException
- if both convex1 and convex2 are Segment
s and are colinearpublic static final Polygon minkowskiSum(Circle circle, Polygon polygon, int count)
Polygon
and Circle
.
Use the count parameter to specify the number of vertices to use per round corner.
If the given polygon has n number of vertices, the returned polygon will have n * 2 + n * count number of vertices.
This method is O(n) where n is the number of vertices in the given polygon.
polygon
- the polygoncircle
- the circle to add to the polygoncount
- the number of vertices to add for each rounded corner; must be greater than zeroPolygon
java.lang.NullPointerException
- if the given polygon or circle is nulljava.lang.IllegalArgumentException
- if the given radius or count is less than or equal to zerominkowskiSum(Polygon, double, int)
public static final Polygon minkowskiSum(Polygon polygon, Circle circle, int count)
Polygon
and Circle
.
Use the count parameter to specify the number of vertices to use per round corner.
If the given polygon has n number of vertices, the returned polygon will have n * 2 + n * count number of vertices.
This method is O(n) where n is the number of vertices in the given polygon.
polygon
- the polygoncircle
- the circle to add to the polygoncount
- the number of vertices to add for each rounded corner; must be greater than zeroPolygon
java.lang.NullPointerException
- if the given polygon or circle is nulljava.lang.IllegalArgumentException
- if the given radius or count is less than or equal to zerominkowskiSum(Polygon, double, int)
public static final Polygon minkowskiSum(Polygon polygon, double radius, int count)
Use the count parameter to specify the number of vertices to use per round corner.
If the given polygon has n number of vertices, the returned polygon will have n * 2 + n * count number of vertices.
This method is O(n) where n is the number of vertices in the given polygon.
polygon
- the polygon to expand radiallyradius
- the radial expansion; must be greater than zerocount
- the number of vertices to add for each rounded corner; must be greater than zeroPolygon
java.lang.NullPointerException
- if the given polygon is nulljava.lang.IllegalArgumentException
- if the given radius or count is less than or equal to zeropublic static final Circle scale(Circle circle, double scale)
circle
- the circlescale
- the scale; must be greater than zeroCircle
java.lang.NullPointerException
- if the given circle is nulljava.lang.IllegalArgumentException
- if the given scale is less than or equal to zeropublic static final Capsule scale(Capsule capsule, double scale)
capsule
- the capsulescale
- the scale; must be greater than zeroCapsule
java.lang.NullPointerException
- if the given capsule is nulljava.lang.IllegalArgumentException
- if the given scale is less than or equal to zeropublic static final Ellipse scale(Ellipse ellipse, double scale)
ellipse
- the ellipsescale
- the scale; must be greater than zeroEllipse
java.lang.NullPointerException
- if the given ellipse is nulljava.lang.IllegalArgumentException
- if the given scale is less than or equal to zeropublic static final HalfEllipse scale(HalfEllipse halfEllipse, double scale)
halfEllipse
- the half-ellipsescale
- the scale; must be greater than zeroHalfEllipse
java.lang.NullPointerException
- if the given half-ellipse is nulljava.lang.IllegalArgumentException
- if the given scale is less than or equal to zeropublic static final Slice scale(Slice slice, double scale)
slice
- the slicescale
- the scale; must be greater than zeroSlice
java.lang.NullPointerException
- if the given slice is nulljava.lang.IllegalArgumentException
- if the given scale is less than or equal to zeropublic static final Polygon scale(Polygon polygon, double scale)
polygon
- the polygonscale
- the scale; must be greater than zeroPolygon
java.lang.NullPointerException
- if the given polygon is nulljava.lang.IllegalArgumentException
- if the given scale is less than or equal to zeropublic static final Segment scale(Segment segment, double scale)
segment
- the segmentscale
- the scale; must be greater than zeroSegment
java.lang.NullPointerException
- if the given segment is nulljava.lang.IllegalArgumentException
- if the given scale is less than or equal to zeropublic static final java.util.List<Link> createLinks(java.util.List<Vector2> vertices, boolean closed)
Link
s for the given vertices.
If the closed parameter is true, an extra link is created joining the last and first vertices in the list.
vertices
- the poly-line verticesclosed
- true if the shape should be enclosedLink
>java.lang.NullPointerException
- if the list of vertices is null or an element of the vertex list is nulljava.lang.IllegalArgumentException
- if the list of vertices doesn't contain 2 or more elementspublic static final java.util.List<Link> createLinks(Vector2[] vertices, boolean closed)
Link
chain for the given vertices.
If the closed parameter is true, an extra link is created joining the last and first vertices in the array.
vertices
- the poly-line verticesclosed
- true if the shape should be enclosedLink
>java.lang.NullPointerException
- if the array of vertices is null or an element of the vertex array is nulljava.lang.IllegalArgumentException
- if the array of vertices doesn't contain 2 or more elements