- Object
-
- Geometry
-
public final class Geometry extends Object
Contains static methods to perform standard geometric operations.This class can be used to create
Shape
s of varying types via thecreate
* methods. WhileShape
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.- Since:
- 1.0.0
- Version:
- 3.4.0
- Author:
- William Bittle
-
-
Field Summary
Fields Modifier and Type Field Description static double
INV_3
The value of 1/3static 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 Summary
Constructors Constructor Description Geometry()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static List<Vector2>
cleanse(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 newCapsule
bounded by the given rectangle width and height.static Circle
createCircle(double radius)
Returns a newCircle
with the given radius centered on the origin.static Ellipse
createEllipse(double width, double height)
Creates a newEllipse
bounded by the given rectangle width and height.static Triangle
createEquilateralTriangle(double height)
Creates an equilateralTriangle
with the center at the origin.static HalfEllipse
createHalfEllipse(double width, double height)
Creates a newHalfEllipse
bounded by the given rectangle width and height.static HalfEllipse
createHalfEllipseAtOrigin(double width, double height)
Creates a newHalfEllipse
bounded by the given rectangle width and height.static Segment
createHorizontalSegment(double length)
Creates a newSegment
with the given length with the center at the origin.static Triangle
createIsoscelesTriangle(double width, double height)
Creates an isoscelesTriangle
with the center at the origin.static List<Link>
createLinks(List<Vector2> vertices, boolean closed)
Creates a list ofLink
s for the given vertices.static List<Link>
createLinks(Vector2[] vertices, boolean closed)
Creates aLink
chain for the given vertices.static Polygon
createPolygon(Vector2... vertices)
Returns a newPolygon
with the given vertices.static Polygon
createPolygonalCapsule(int count, double width, double height)
Creates a newPolygon
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 newPolygon
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 newPolygon
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 newPolygon
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 newPolygon
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 newPolygon
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 newPolygon
, using the given vertices, centered at the origin.static Rectangle
createRectangle(double width, double height)
Creates a newRectangle
with the given width and height centered at the origin.static Triangle
createRightTriangle(double width, double height)
Creates a right angleTriangle
with the center at the origin.static Triangle
createRightTriangle(double width, double height, boolean mirror)
Creates a right angleTriangle
with the center at the origin.static Segment
createSegment(Vector2 end)
Creates a newSegment
from the origin to the given end pointstatic Segment
createSegment(Vector2 p1, Vector2 p2)
Creates a newSegment
with the given points.static Segment
createSegmentAtOrigin(Vector2 p1, Vector2 p2)
Creates a newSegment
with the given points.static Slice
createSlice(double radius, double theta)
Creates a newSlice
with the given circle radius and arc length theta.static Slice
createSliceAtOrigin(double radius, double theta)
Creates a newSlice
with the given circle radius and arc length theta.static Rectangle
createSquare(double size)
Creates a square (equal height and widthRectangle
) with the given size centered at the origin.static Triangle
createTriangle(Vector2 p1, Vector2 p2, Vector2 p3)
Creates a newTriangle
, using the given points.static Triangle
createTriangleAtOrigin(Vector2 p1, Vector2 p2, Vector2 p3)
Creates a newTriangle
with the given points centered at the origin.static Polygon
createUnitCirclePolygon(int count, double radius)
Returns a newPolygon
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 newPolygon
with count number of points, where the points are evenly distributed around the unit circle.static Segment
createVerticalSegment(double length)
Creates a newSegment
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(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(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(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 <E extends Wound & Convex>
PolygonminkowskiSum(E convex1, E convex2)
Returns the Minkowski Sum of the given convex shapes.static Polygon
minkowskiSum(Circle circle, Polygon polygon, int count)
static Polygon
minkowskiSum(Polygon polygon, double radius, int count)
Returns a new polygon that has been radially expanded.static Polygon
minkowskiSum(Polygon polygon, Circle circle, int count)
static void
reverseWinding(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.
-
-
-
Field Detail
-
TWO_PI
public static final double TWO_PI
2 * PI constant- See Also:
- Constant Field Values
-
INV_3
public static final double INV_3
The value of 1/3- See Also:
- Constant Field Values
-
INV_SQRT_3
public static final double INV_SQRT_3
The value of the inverse of the square root of 3; 1/sqrt(3)
-
-
Method Detail
-
getWinding
public static final double getWinding(List<Vector2> points)
Returns the winding, Clockwise or Counter-Clockwise, for the given list of points of a polygon.This method determines the winding by computing a signed "area".
- Parameters:
points
- the points of a polygon- Returns:
- double negative for Clockwise winding; positive for Counter-Clockwise winding
- Throws:
NullPointerException
- if points is null or an element of points is nullIllegalArgumentException
- if points contains less than 2 elements- Since:
- 2.2.0
-
getWinding
public static final double getWinding(Vector2... points)
Returns the winding, Clockwise or Counter-Clockwise, for the given array of points of a polygon.- Parameters:
points
- the points of a polygon- Returns:
- double negative for Clockwise winding; positive for Counter-Clockwise winding
- Throws:
NullPointerException
- if points is null or an element of points is nullIllegalArgumentException
- if points contains less than 2 elements- Since:
- 2.2.0
-
reverseWinding
public static final void reverseWinding(Vector2... points)
Reverses the order of the polygon points within the given array.This method performs a simple array reverse.
- Parameters:
points
- the polygon points- Throws:
NullPointerException
- if points is null- Since:
- 2.2.0
-
reverseWinding
public static final void reverseWinding(List<Vector2> points)
Reverses the order of the polygon points within the given list.This method performs a simple list reverse.
- Parameters:
points
- the polygon points- Throws:
NullPointerException
- if points is null- Since:
- 2.2.0
-
getAverageCenter
public static final Vector2 getAverageCenter(List<Vector2> points)
Returns the centroid of the given points by performing an average.- Parameters:
points
- the list of points- Returns:
Vector2
the centroid- Throws:
NullPointerException
- if points is null or an element of points is nullIllegalArgumentException
- if points is an empty list
-
getAverageCenter
public static final Vector2 getAverageCenter(Vector2... points)
Returns the centroid of the given points by performing an average.- Parameters:
points
- the array of points- Returns:
Vector2
the centroid- Throws:
NullPointerException
- if points is null or an element of points is nullIllegalArgumentException
- if points is an empty array- See Also:
getAverageCenter(List)
-
getAreaWeightedCenter
public static final Vector2 getAreaWeightedCenter(List<Vector2> points)
Returns the area weighted centroid for the given 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)
- Parameters:
points
- thePolygon
points- Returns:
Vector2
the area weighted centroid- Throws:
NullPointerException
- if points is null or an element of points is nullIllegalArgumentException
- if points is empty
-
getAreaWeightedCenter
public static final Vector2 getAreaWeightedCenter(Vector2... points)
Returns the area weighted centroid for the given points.- Parameters:
points
- thePolygon
points- Returns:
Vector2
the area weighted centroid- Throws:
NullPointerException
- if points is null or an element of points is nullIllegalArgumentException
- if points is empty- See Also:
getAreaWeightedCenter(List)
-
getRotationRadius
public static final double getRotationRadius(Vector2... vertices)
Returns the maximum radius of the given vertices rotated about the origin.If the vertices array is null or empty, zero is returned.
- Parameters:
vertices
- the polygon vertices- Returns:
- double
- Since:
- 3.2.0
- See Also:
getRotationRadius(Vector2, Vector2...)
-
getRotationRadius
public static final double getRotationRadius(Vector2 center, Vector2... vertices)
Returns the maximum radius of the given vertices rotated about the given center.If the vertices array is null or empty, zero is returned. If center is null the origin will be used instead.
- Parameters:
center
- the center pointvertices
- the polygon vertices- Returns:
- double
- Since:
- 3.2.0
-
getCounterClockwiseEdgeNormals
public static final Vector2[] getCounterClockwiseEdgeNormals(Vector2... vertices)
Returns an array of normalized vectors representing the normals of all the edges given the vertices.This method assumes counter-clockwise ordering.
Returns null if the given vertices array is null or empty.
- Parameters:
vertices
- the vertices- Returns:
Vector2
[]- Throws:
NullPointerException
- if vertices contains a null element- Since:
- 3.2.0
-
createCircle
public static final Circle createCircle(double radius)
Returns a newCircle
with the given radius centered on the origin.- Parameters:
radius
- the radius in meters- Returns:
Circle
- Throws:
IllegalArgumentException
- if radius is less than or equal to zero
-
createPolygon
public static final Polygon createPolygon(Vector2... vertices)
Returns a newPolygon
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.- Parameters:
vertices
- the array of vertices- Returns:
Polygon
- Throws:
NullPointerException
- if vertices is null or an element of vertices is nullIllegalArgumentException
- if vertices contains less than 3 non-null vertices- See Also:
to create a new that is centered on the origin
-
createPolygonAtOrigin
public static final Polygon createPolygonAtOrigin(Vector2... vertices)
Returns a newPolygon
, 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.- Parameters:
vertices
- the array of vertices- Returns:
Polygon
- Throws:
NullPointerException
- if vertices is null or an element of vertices is nullIllegalArgumentException
- if vertices contains less than 3 non-null vertices
-
createUnitCirclePolygon
public static final Polygon createUnitCirclePolygon(int count, double radius)
Returns a newPolygon
with count number of points, where the points are evenly distributed around the unit circle. The resultingPolygon
will be centered on the origin.The radius parameter is the distance from the center of the polygon to each vertex.
- Parameters:
count
- the number of verticesradius
- the radius from the center to each vertex in meters- Returns:
Polygon
- Throws:
IllegalArgumentException
- if count is less than 3 or radius is less than or equal to zero- See Also:
createUnitCirclePolygon(int, double, double)
,createPolygonalCircle(int, double)
,createPolygonalCircle(int, double, double)
-
createUnitCirclePolygon
public static final Polygon createUnitCirclePolygon(int count, double radius, double theta)
Returns a newPolygon
with count number of points, where the points are evenly distributed around the unit circle. The resultingPolygon
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.
- Parameters:
count
- the number of verticesradius
- the radius from the center to each vertex in meterstheta
- the vertex angle offset in radians- Returns:
Polygon
- Throws:
IllegalArgumentException
- if count is less than 3 or radius is less than or equal to zero- See Also:
createPolygonalCircle(int, double, double)
-
createSquare
public static final Rectangle createSquare(double size)
Creates a square (equal height and widthRectangle
) with the given size centered at the origin.- Parameters:
size
- the size in meters- Returns:
Rectangle
- Throws:
IllegalArgumentException
- if size is less than or equal to zero
-
createRectangle
public static final Rectangle createRectangle(double width, double height)
Creates a newRectangle
with the given width and height centered at the origin.- Parameters:
width
- the width in metersheight
- the height in meters- Returns:
Rectangle
- Throws:
IllegalArgumentException
- if width or height is less than or equal to zero
-
createTriangle
public static final Triangle createTriangle(Vector2 p1, Vector2 p2, Vector2 p3)
Creates a newTriangle
, 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.- Parameters:
p1
- the first pointp2
- the second pointp3
- the third point- Returns:
Triangle
- Throws:
NullPointerException
- if p1, p2, or p3 is null- See Also:
to create a new that is centered on the origin
-
createTriangleAtOrigin
public static final Triangle createTriangleAtOrigin(Vector2 p1, Vector2 p2, Vector2 p3)
Creates a newTriangle
with the given points centered at the origin.This method makes a copy of the given points to create the
Triangle
.- Parameters:
p1
- the first pointp2
- the second pointp3
- the third point- Returns:
Triangle
- Throws:
NullPointerException
- if p1, p2, or p3 is null
-
createRightTriangle
public static final Triangle createRightTriangle(double width, double height)
Creates a right angleTriangle
with the center at the origin.- Parameters:
width
- the width of the base in metersheight
- the height in meters- Returns:
Triangle
- Throws:
IllegalArgumentException
- if width or height is less than or equal to zero
-
createRightTriangle
public static final Triangle createRightTriangle(double width, double height, boolean mirror)
Creates a right angleTriangle
with the center at the origin.- Parameters:
width
- the width of the base in metersheight
- the height in metersmirror
- true if the triangle should be mirrored along the y-axis- Returns:
Triangle
- Throws:
IllegalArgumentException
- if width or height is less than or equal to zero
-
createEquilateralTriangle
public static final Triangle createEquilateralTriangle(double height)
Creates an equilateralTriangle
with the center at the origin.- Parameters:
height
- the height of the triangle in meters- Returns:
Triangle
- Throws:
IllegalArgumentException
- if height is less than or equal to zero
-
createIsoscelesTriangle
public static final Triangle createIsoscelesTriangle(double width, double height)
Creates an isoscelesTriangle
with the center at the origin.- Parameters:
width
- the width of the base in metersheight
- the height in meters- Returns:
Triangle
- Throws:
IllegalArgumentException
- if width or height is less than or equal to zero
-
createSegment
public static final Segment createSegment(Vector2 p1, Vector2 p2)
Creates a newSegment
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.- Parameters:
p1
- the first pointp2
- the second point- Returns:
Segment
- Throws:
NullPointerException
- if p1 or p2 is null- See Also:
to create a centered on the origin
-
createSegmentAtOrigin
public static final Segment createSegmentAtOrigin(Vector2 p1, Vector2 p2)
Creates a newSegment
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.- Parameters:
p1
- the first pointp2
- the second point- Returns:
Segment
- Throws:
NullPointerException
- if p1 or p2 is null
-
createSegment
public static final Segment createSegment(Vector2 end)
Creates a newSegment
from the origin to the given end pointThis method makes a copy of the given point to create the
Segment
.- Parameters:
end
- the end point- Returns:
Segment
- Throws:
NullPointerException
- if end is null
-
createHorizontalSegment
public static final Segment createHorizontalSegment(double length)
Creates a newSegment
with the given length with the center at the origin.Renamed from createSegment(double).
- Parameters:
length
- the length of the segment in meters- Returns:
Segment
- Throws:
IllegalArgumentException
- if length is less than or equal to zero- Since:
- 2.2.3
-
createVerticalSegment
public static final Segment createVerticalSegment(double length)
Creates a newSegment
with the given length with the center at the origin.- Parameters:
length
- the length of the segment in meters- Returns:
Segment
- Throws:
IllegalArgumentException
- if length is less than or equal to zero- Since:
- 2.2.3
-
createCapsule
public static final Capsule createCapsule(double width, double height)
Creates a newCapsule
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.- Parameters:
width
- the bounding rectangle widthheight
- the bounding rectangle height- Returns:
Capsule
- Throws:
IllegalArgumentException
- if width or height are less than or equal to zero- Since:
- 3.1.5
-
createSlice
public static final Slice createSlice(double radius, double theta)
Creates a newSlice
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 π.
- Parameters:
radius
- the circle radiustheta
- the total arc length in radians- Returns:
Slice
- Throws:
IllegalArgumentException
- if radius is less than or equal to zero; if theta is less than or equal to zero or is greater than π- Since:
- 3.1.5
-
createSliceAtOrigin
public static final Slice createSliceAtOrigin(double radius, double theta)
Creates a newSlice
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 π.
- Parameters:
radius
- the circle radiustheta
- the total arc length in radians- Returns:
Slice
- Throws:
IllegalArgumentException
- if radius is less than or equal to zero; if theta is less than or equal to zero or is greater than π- Since:
- 3.1.5
-
createEllipse
public static final Ellipse createEllipse(double width, double height)
Creates a newEllipse
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.- Parameters:
width
- the bounding rectangle widthheight
- the bounding rectangle height- Returns:
Ellipse
- Throws:
IllegalArgumentException
- if width or height are less than or equal to zero- Since:
- 3.1.5
-
createHalfEllipse
public static final HalfEllipse createHalfEllipse(double width, double height)
Creates a newHalfEllipse
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 withtheta = Math.PI
instead.- Parameters:
width
- the bounding rectangle widthheight
- the bounding rectangle height- Returns:
HalfEllipse
- Throws:
IllegalArgumentException
- if width or height are less than or equal to zero- Since:
- 3.1.5
-
createHalfEllipseAtOrigin
public static final HalfEllipse createHalfEllipseAtOrigin(double width, double height)
Creates a newHalfEllipse
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 withtheta = Math.PI
instead.- Parameters:
width
- the bounding rectangle widthheight
- the bounding rectangle height- Returns:
HalfEllipse
- Throws:
IllegalArgumentException
- if width or height are less than or equal to zero- Since:
- 3.1.5
-
createPolygonalCircle
public static final Polygon createPolygonalCircle(int count, double radius)
Creates a newPolygon
in the shape of a circle with count number of vertices centered on the origin.- Parameters:
count
- the number of vertices to use; must be greater than 2radius
- the radius of the circle; must be greater than zero- Returns:
Polygon
- Throws:
IllegalArgumentException
- thrown if count is less than 3 or the radius is less than or equal to zero- Since:
- 3.1.5
-
createPolygonalCircle
public static final Polygon createPolygonalCircle(int count, double radius, double theta)
Creates a newPolygon
in the shape of a circle with count number of vertices centered on the origin.- Parameters:
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 radians- Returns:
Polygon
- Throws:
IllegalArgumentException
- thrown if count is less than 3 or the radius is less than or equal to zero- Since:
- 3.1.5
-
createPolygonalSlice
public static final Polygon createPolygonalSlice(int count, double radius, double theta)
Creates a newPolygon
in the shape of aSlice
with count number of vertices with the circle center centered on the origin.This method returns a polygon with count + 3 vertices.
- Parameters:
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 zero- Returns:
Polygon
- Throws:
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 zero- Since:
- 3.1.5
-
createPolygonalSliceAtOrigin
public static final Polygon createPolygonalSliceAtOrigin(int count, double radius, double theta)
Creates a newPolygon
in the shape of aSlice
with count number of vertices centered on the origin.This method returns a polygon with count + 3 vertices.
- Parameters:
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 zero- Returns:
Polygon
- Throws:
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 zero- Since:
- 3.1.5
-
createPolygonalEllipse
public static final Polygon createPolygonalEllipse(int count, double width, double height)
Creates a newPolygon
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.
- Parameters:
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 ellipse- Returns:
Polygon
- Throws:
IllegalArgumentException
- thrown if count is less than 4 or the width or height are less than or equal to zero- Since:
- 3.1.5
-
createPolygonalHalfEllipse
public static final Polygon createPolygonalHalfEllipse(int count, double width, double height)
Creates a newPolygon
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.
- Parameters:
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 height- Returns:
Polygon
- Throws:
IllegalArgumentException
- thrown if count is less than 1 or the width or height are less than or equal to zero- Since:
- 3.1.5
-
createPolygonalHalfEllipseAtOrigin
public static final Polygon createPolygonalHalfEllipseAtOrigin(int count, double width, double height)
Creates a newPolygon
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.
- Parameters:
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 height- Returns:
Polygon
- Throws:
IllegalArgumentException
- thrown if count is less than 1 or the width or height are less than or equal to zero- Since:
- 3.1.5
-
createPolygonalCapsule
public static final Polygon createPolygonalCapsule(int count, double width, double height)
Creates a newPolygon
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.
- Parameters:
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 height- Returns:
Polygon
- Since:
- 3.1.5
-
cleanse
public static final List<Vector2> cleanse(List<Vector2> points)
Returns a new list containing the 'cleansed' version of the given listing of polygon 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.
- Parameters:
points
- the list polygon points- Returns:
- List<
Vector2
> - Throws:
NullPointerException
- if points is null or if points contains null elements
-
cleanse
public static final Vector2[] cleanse(Vector2... points)
Returns a new array containing the 'cleansed' version of the given array of polygon points.This method ensures the polygon has CCW winding, removes colinear vertices, and removes coincident vertices.
- Parameters:
points
- the list polygon points- Returns:
Vector2
[]- Throws:
NullPointerException
- if points is null or points contains null elements
-
flipAlongTheXAxis
public static final Polygon flipAlongTheXAxis(Polygon polygon)
Flips the given polygon about its center along the x-axis and returns the result as a new polygon.This method assumes that the line is through the origin.
- Parameters:
polygon
- the polygon to flip- Returns:
Polygon
- Throws:
NullPointerException
- if the given polygon is null- Since:
- 3.1.4
- See Also:
flip(Polygon, Vector2)
,flip(Polygon, Vector2, Vector2)
-
flipAlongTheYAxis
public static final Polygon flipAlongTheYAxis(Polygon polygon)
Flips the given polygon about its center along the y-axis and returns the result as a new polygon.This method assumes that the line is through the origin.
- Parameters:
polygon
- the polygon to flip- Returns:
Polygon
- Throws:
NullPointerException
- if the given polygon is null- Since:
- 3.1.4
- See Also:
flip(Polygon, Vector2)
,flip(Polygon, Vector2, Vector2)
-
flipAlongTheXAxis
public static final 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.- Parameters:
polygon
- the polygon to flippoint
- the point to flip about- Returns:
Polygon
- Throws:
NullPointerException
- if the given polygon is null- Since:
- 3.1.4
- See Also:
flip(Polygon, Vector2)
,flip(Polygon, Vector2, Vector2)
-
flipAlongTheYAxis
public static final 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.- Parameters:
polygon
- the polygon to flippoint
- the point to flip about- Returns:
Polygon
- Throws:
NullPointerException
- if the given polygon is null- Since:
- 3.1.4
- See Also:
flip(Polygon, Vector2)
,flip(Polygon, Vector2, Vector2)
-
flip
public static final Polygon flip(Polygon polygon, Vector2 axis)
Flips the given polygon about the given line and returns the result as a new polygon.This method assumes that the line is through the origin.
- Parameters:
polygon
- the polygon to flipaxis
- the axis to flip about- Returns:
Polygon
- Throws:
NullPointerException
- if the given polygon or axis is nullIllegalArgumentException
- if the given axis is the zero vector- Since:
- 3.1.4
- See Also:
flip(Polygon, Vector2, Vector2)
-
flip
public static final Polygon flip(Polygon polygon, Vector2 axis, Vector2 point)
Flips the given polygon about the given line and returns the result as a new polygon.- Parameters:
polygon
- the polygon to flipaxis
- the axis to flip aboutpoint
- the point to flip about; if null, the polygon center is used- Returns:
Polygon
- Throws:
NullPointerException
- if the given polygon or axis is nullIllegalArgumentException
- if the given axis is the zero vector- Since:
- 3.1.4
-
minkowskiSum
public static final <E extends Wound & Convex> Polygon minkowskiSum(E convex1, E convex2)
Returns the Minkowski Sum of the given convex shapes.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 meansPolygon
s orSegment
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).- Type Parameters:
E
- either aWound
orConvex
type- Parameters:
convex1
- the first convexconvex2
- the second convex- Returns:
Polygon
- Throws:
NullPointerException
- if convex1 or convex2 are nullIllegalArgumentException
- if both convex1 and convex2 areSegment
s and are colinear- Since:
- 3.1.5
-
minkowskiSum
public static final Polygon minkowskiSum(Circle circle, Polygon polygon, int count)
Performs the Minkowski Sum of the givenPolygon
andCircle
.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.
- Parameters:
polygon
- the polygoncircle
- the circle to add to the polygoncount
- the number of vertices to add for each rounded corner; must be greater than zero- Returns:
Polygon
- Throws:
NullPointerException
- if the given polygon or circle is nullIllegalArgumentException
- if the given radius or count is less than or equal to zero- Since:
- 3.1.5
- See Also:
minkowskiSum(Polygon, double, int)
-
minkowskiSum
public static final Polygon minkowskiSum(Polygon polygon, Circle circle, int count)
Performs the Minkowski Sum of the givenPolygon
andCircle
.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.
- Parameters:
polygon
- the polygoncircle
- the circle to add to the polygoncount
- the number of vertices to add for each rounded corner; must be greater than zero- Returns:
Polygon
- Throws:
NullPointerException
- if the given polygon or circle is nullIllegalArgumentException
- if the given radius or count is less than or equal to zero- Since:
- 3.1.5
- See Also:
minkowskiSum(Polygon, double, int)
-
minkowskiSum
public static final Polygon minkowskiSum(Polygon polygon, double radius, int count)
Returns a new polygon that has been radially expanded. This is equivalent to the Minkowski sum of a circle, of the given radius, and the given polygon.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.
- Parameters:
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 zero- Returns:
Polygon
- Throws:
NullPointerException
- if the given polygon is nullIllegalArgumentException
- if the given radius or count is less than or equal to zero- Since:
- 3.1.5
-
scale
public static final Circle scale(Circle circle, double scale)
Returns a scaled version of the given circle.- Parameters:
circle
- the circlescale
- the scale; must be greater than zero- Returns:
Circle
- Throws:
NullPointerException
- if the given circle is nullIllegalArgumentException
- if the given scale is less than or equal to zero- Since:
- 3.1.5
-
scale
public static final Capsule scale(Capsule capsule, double scale)
Returns a scaled version of the given capsule.- Parameters:
capsule
- the capsulescale
- the scale; must be greater than zero- Returns:
Capsule
- Throws:
NullPointerException
- if the given capsule is nullIllegalArgumentException
- if the given scale is less than or equal to zero- Since:
- 3.1.5
-
scale
public static final Ellipse scale(Ellipse ellipse, double scale)
Returns a scaled version of the given ellipse.- Parameters:
ellipse
- the ellipsescale
- the scale; must be greater than zero- Returns:
Ellipse
- Throws:
NullPointerException
- if the given ellipse is nullIllegalArgumentException
- if the given scale is less than or equal to zero- Since:
- 3.1.5
-
scale
public static final HalfEllipse scale(HalfEllipse halfEllipse, double scale)
Returns a scaled version of the given half-ellipse.- Parameters:
halfEllipse
- the half-ellipsescale
- the scale; must be greater than zero- Returns:
HalfEllipse
- Throws:
NullPointerException
- if the given half-ellipse is nullIllegalArgumentException
- if the given scale is less than or equal to zero- Since:
- 3.1.5
-
scale
public static final Slice scale(Slice slice, double scale)
Returns a scaled version of the given slice.- Parameters:
slice
- the slicescale
- the scale; must be greater than zero- Returns:
Slice
- Throws:
NullPointerException
- if the given slice is nullIllegalArgumentException
- if the given scale is less than or equal to zero- Since:
- 3.1.5
-
scale
public static final Polygon scale(Polygon polygon, double scale)
Returns a scaled version of the given polygon.- Parameters:
polygon
- the polygonscale
- the scale; must be greater than zero- Returns:
Polygon
- Throws:
NullPointerException
- if the given polygon is nullIllegalArgumentException
- if the given scale is less than or equal to zero- Since:
- 3.1.5
-
scale
public static final Segment scale(Segment segment, double scale)
Returns a scaled version of the given segment.- Parameters:
segment
- the segmentscale
- the scale; must be greater than zero- Returns:
Segment
- Throws:
NullPointerException
- if the given segment is nullIllegalArgumentException
- if the given scale is less than or equal to zero- Since:
- 3.1.5
-
createLinks
public static final List<Link> createLinks(List<Vector2> vertices, boolean closed)
Creates a list ofLink
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.
- Parameters:
vertices
- the poly-line verticesclosed
- true if the shape should be enclosed- Returns:
- List<
Link
> - Throws:
NullPointerException
- if the list of vertices is null or an element of the vertex list is nullIllegalArgumentException
- if the list of vertices doesn't contain 2 or more elements- Since:
- 3.2.2
-
createLinks
public static final List<Link> createLinks(Vector2[] vertices, boolean closed)
Creates aLink
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.
- Parameters:
vertices
- the poly-line verticesclosed
- true if the shape should be enclosed- Returns:
- List<
Link
> - Throws:
NullPointerException
- if the array of vertices is null or an element of the vertex array is nullIllegalArgumentException
- if the array of vertices doesn't contain 2 or more elements- Since:
- 3.2.2
-
-