Module org.dyn4j

Class Geometry


  • public final class Geometry
    extends java.lang.Object
    Contains static methods to perform standard geometric operations.

    This class can be used to create Shapes of varying types via the create* methods. While Shapes 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 Shapes.

    Since:
    1.0.0
    Version:
    3.4.0
    Author:
    William Bittle
    • Field Detail

      • INV_SQRT_3

        public static final double INV_SQRT_3
        The value of the inverse of the square root of 3; 1/sqrt(3)
    • Constructor Detail

      • Geometry

        public Geometry()
    • Method Detail

      • getWinding

        public static final double getWinding​(java.util.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:
        java.lang.NullPointerException - if points is null or an element of points is null
        java.lang.IllegalArgumentException - 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:
        java.lang.NullPointerException - if points is null or an element of points is null
        java.lang.IllegalArgumentException - 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:
        java.lang.NullPointerException - if points is null
        Since:
        2.2.0
      • reverseWinding

        public static final void reverseWinding​(java.util.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:
        java.lang.NullPointerException - if points is null
        Since:
        2.2.0
      • getAverageCenter

        public static final Vector2 getAverageCenter​(java.util.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:
        java.lang.NullPointerException - if points is null or an element of points is null
        java.lang.IllegalArgumentException - 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:
        java.lang.NullPointerException - if points is null or an element of points is null
        java.lang.IllegalArgumentException - if points is an empty array
        See Also:
        getAverageCenter(List)
      • getAreaWeightedCenter

        public static final Vector2 getAreaWeightedCenter​(java.util.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 - the Polygon points
        Returns:
        Vector2 the area weighted centroid
        Throws:
        java.lang.NullPointerException - if points is null or an element of points is null
        java.lang.IllegalArgumentException - if points is empty
      • getAreaWeightedCenter

        public static final Vector2 getAreaWeightedCenter​(Vector2... points)
        Returns the area weighted centroid for the given points.
        Parameters:
        points - the Polygon points
        Returns:
        Vector2 the area weighted centroid
        Throws:
        java.lang.NullPointerException - if points is null or an element of points is null
        java.lang.IllegalArgumentException - 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 point
        vertices - 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:
        java.lang.NullPointerException - if vertices contains a null element
        Since:
        3.2.0
      • createCircle

        public static final Circle createCircle​(double radius)
        Returns a new Circle with the given radius centered on the origin.
        Parameters:
        radius - the radius in meters
        Returns:
        Circle
        Throws:
        java.lang.IllegalArgumentException - if radius is less than or equal to zero
      • createPolygon

        public static final Polygon createPolygon​(Vector2... vertices)
        Returns a new 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.

        Parameters:
        vertices - the array of vertices
        Returns:
        Polygon
        Throws:
        java.lang.NullPointerException - if vertices is null or an element of vertices is null
        java.lang.IllegalArgumentException - 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 new 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.

        Parameters:
        vertices - the array of vertices
        Returns:
        Polygon
        Throws:
        java.lang.NullPointerException - if vertices is null or an element of vertices is null
        java.lang.IllegalArgumentException - if vertices contains less than 3 non-null vertices
      • createUnitCirclePolygon

        public static final 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. 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.

        Parameters:
        count - the number of vertices
        radius - the radius from the center to each vertex in meters
        theta - the vertex angle offset in radians
        Returns:
        Polygon
        Throws:
        java.lang.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 width Rectangle) with the given size centered at the origin.
        Parameters:
        size - the size in meters
        Returns:
        Rectangle
        Throws:
        java.lang.IllegalArgumentException - if size is less than or equal to zero
      • createRectangle

        public static final Rectangle createRectangle​(double width,
                                                      double height)
        Creates a new Rectangle with the given width and height centered at the origin.
        Parameters:
        width - the width in meters
        height - the height in meters
        Returns:
        Rectangle
        Throws:
        java.lang.IllegalArgumentException - if width or height is less than or equal to zero
      • createTriangleAtOrigin

        public static final Triangle createTriangleAtOrigin​(Vector2 p1,
                                                            Vector2 p2,
                                                            Vector2 p3)
        Creates a new Triangle 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 point
        p2 - the second point
        p3 - the third point
        Returns:
        Triangle
        Throws:
        java.lang.NullPointerException - if p1, p2, or p3 is null
      • createRightTriangle

        public static final Triangle createRightTriangle​(double width,
                                                         double height)
        Creates a right angle Triangle with the center at the origin.
        Parameters:
        width - the width of the base in meters
        height - the height in meters
        Returns:
        Triangle
        Throws:
        java.lang.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 angle Triangle with the center at the origin.
        Parameters:
        width - the width of the base in meters
        height - the height in meters
        mirror - true if the triangle should be mirrored along the y-axis
        Returns:
        Triangle
        Throws:
        java.lang.IllegalArgumentException - if width or height is less than or equal to zero
      • createEquilateralTriangle

        public static final Triangle createEquilateralTriangle​(double height)
        Creates an equilateral Triangle with the center at the origin.
        Parameters:
        height - the height of the triangle in meters
        Returns:
        Triangle
        Throws:
        java.lang.IllegalArgumentException - if height is less than or equal to zero
      • createIsoscelesTriangle

        public static final Triangle createIsoscelesTriangle​(double width,
                                                             double height)
        Creates an isosceles Triangle with the center at the origin.
        Parameters:
        width - the width of the base in meters
        height - the height in meters
        Returns:
        Triangle
        Throws:
        java.lang.IllegalArgumentException - if width or height is less than or equal to zero
      • createSegment

        public static final Segment createSegment​(Vector2 p1,
                                                  Vector2 p2)
        Creates a new 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.

        Parameters:
        p1 - the first point
        p2 - the second point
        Returns:
        Segment
        Throws:
        java.lang.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 new 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.

        Parameters:
        p1 - the first point
        p2 - the second point
        Returns:
        Segment
        Throws:
        java.lang.NullPointerException - if p1 or p2 is null
      • createSegment

        public static final Segment createSegment​(Vector2 end)
        Creates a new Segment from the origin to the given end point

        This method makes a copy of the given point to create the Segment.

        Parameters:
        end - the end point
        Returns:
        Segment
        Throws:
        java.lang.NullPointerException - if end is null
      • createHorizontalSegment

        public static final Segment createHorizontalSegment​(double length)
        Creates a new Segment 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:
        java.lang.IllegalArgumentException - if length is less than or equal to zero
        Since:
        2.2.3
      • createVerticalSegment

        public static final Segment createVerticalSegment​(double length)
        Creates a new Segment with the given length with the center at the origin.
        Parameters:
        length - the length of the segment in meters
        Returns:
        Segment
        Throws:
        java.lang.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 new 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.

        Parameters:
        width - the bounding rectangle width
        height - the bounding rectangle height
        Returns:
        Capsule
        Throws:
        java.lang.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 new 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 π.

        Parameters:
        radius - the circle radius
        theta - the total arc length in radians
        Returns:
        Slice
        Throws:
        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 π
        Since:
        3.1.5
      • createSliceAtOrigin

        public static final Slice createSliceAtOrigin​(double radius,
                                                      double theta)
        Creates a new 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 π.

        Parameters:
        radius - the circle radius
        theta - the total arc length in radians
        Returns:
        Slice
        Throws:
        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 π
        Since:
        3.1.5
      • createEllipse

        public static final Ellipse createEllipse​(double width,
                                                  double height)
        Creates a new 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.

        Parameters:
        width - the bounding rectangle width
        height - the bounding rectangle height
        Returns:
        Ellipse
        Throws:
        java.lang.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 new 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.

        Parameters:
        width - the bounding rectangle width
        height - the bounding rectangle height
        Returns:
        HalfEllipse
        Throws:
        java.lang.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 new 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.

        Parameters:
        width - the bounding rectangle width
        height - the bounding rectangle height
        Returns:
        HalfEllipse
        Throws:
        java.lang.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 new Polygon 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 2
        radius - the radius of the circle; must be greater than zero
        Returns:
        Polygon
        Throws:
        java.lang.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 new Polygon 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 3
        radius - the radius of the circle; must be greater than zero
        theta - the radial offset for the points in radians
        Returns:
        Polygon
        Throws:
        java.lang.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 new 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.

        Parameters:
        count - the number of vertices to use; must be greater than or equal to 1
        radius - the radius of the circle; must be greater than zero
        theta - the arc length of the slice in radians; must be greater than zero
        Returns:
        Polygon
        Throws:
        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 zero
        Since:
        3.1.5
      • createPolygonalSliceAtOrigin

        public static final Polygon createPolygonalSliceAtOrigin​(int count,
                                                                 double radius,
                                                                 double theta)
        Creates a new 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.

        Parameters:
        count - the number of vertices to use; must be greater than or equal to 1
        radius - the radius of the circle; must be greater than zero
        theta - the arc length of the slice in radians; must be greater than zero
        Returns:
        Polygon
        Throws:
        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 zero
        Since:
        3.1.5
      • createPolygonalEllipse

        public static final 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.

        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 generated
        width - the width of the ellipse
        height - the height of the ellipse
        Returns:
        Polygon
        Throws:
        java.lang.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 new 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.

        Parameters:
        count - the number of vertices to use; must be greater than or equal to 1
        width - the width of the half ellipse
        height - the height of the half ellipse; should be the total height
        Returns:
        Polygon
        Throws:
        java.lang.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 new 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.

        Parameters:
        count - the number of vertices to use; should be even, if not, count - 1 vertices will be generated
        width - the width of the half ellipse
        height - the height of the half ellipse; should be the total height
        Returns:
        Polygon
        Throws:
        java.lang.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 new 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.

        Parameters:
        count - the number of vertices to use for one cap; must be greater than or equal to 1
        width - the bounding rectangle width
        height - the bounding rectangle height
        Returns:
        Polygon
        Since:
        3.1.5
      • cleanse

        public static final 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.

        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:
        java.lang.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:
        java.lang.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:
        java.lang.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:
        java.lang.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 flip
        point - the point to flip about
        Returns:
        Polygon
        Throws:
        java.lang.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 flip
        point - the point to flip about
        Returns:
        Polygon
        Throws:
        java.lang.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 flip
        axis - the axis to flip about
        Returns:
        Polygon
        Throws:
        java.lang.NullPointerException - if the given polygon or axis is null
        java.lang.IllegalArgumentException - 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 flip
        axis - the axis to flip about
        point - the point to flip about; if null, the polygon center is used
        Returns:
        Polygon
        Throws:
        java.lang.NullPointerException - if the given polygon or axis is null
        java.lang.IllegalArgumentException - if the given axis is the zero vector
        Since:
        3.1.4
      • minkowskiSum

        public static final <E extends Wound & ConvexPolygon 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 means Polygons or Segments.

        This method throws an IllegalArgumentException if two Segments are supplied that are colinear (in this case the resulting Minkowski Sum would be another segment rather than a polygon).

        Type Parameters:
        E - either a Wound or Convex type
        Parameters:
        convex1 - the first convex
        convex2 - the second convex
        Returns:
        Polygon
        Throws:
        java.lang.NullPointerException - if convex1 or convex2 are null
        java.lang.IllegalArgumentException - if both convex1 and convex2 are Segments 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 given 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.

        Parameters:
        polygon - the polygon
        circle - the circle to add to the polygon
        count - the number of vertices to add for each rounded corner; must be greater than zero
        Returns:
        Polygon
        Throws:
        java.lang.NullPointerException - if the given polygon or circle is null
        java.lang.IllegalArgumentException - 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 given 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.

        Parameters:
        polygon - the polygon
        circle - the circle to add to the polygon
        count - the number of vertices to add for each rounded corner; must be greater than zero
        Returns:
        Polygon
        Throws:
        java.lang.NullPointerException - if the given polygon or circle is null
        java.lang.IllegalArgumentException - 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 radially
        radius - the radial expansion; must be greater than zero
        count - the number of vertices to add for each rounded corner; must be greater than zero
        Returns:
        Polygon
        Throws:
        java.lang.NullPointerException - if the given polygon is null
        java.lang.IllegalArgumentException - 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 circle
        scale - the scale; must be greater than zero
        Returns:
        Circle
        Throws:
        java.lang.NullPointerException - if the given circle is null
        java.lang.IllegalArgumentException - 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 capsule
        scale - the scale; must be greater than zero
        Returns:
        Capsule
        Throws:
        java.lang.NullPointerException - if the given capsule is null
        java.lang.IllegalArgumentException - 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 ellipse
        scale - the scale; must be greater than zero
        Returns:
        Ellipse
        Throws:
        java.lang.NullPointerException - if the given ellipse is null
        java.lang.IllegalArgumentException - 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-ellipse
        scale - the scale; must be greater than zero
        Returns:
        HalfEllipse
        Throws:
        java.lang.NullPointerException - if the given half-ellipse is null
        java.lang.IllegalArgumentException - 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 slice
        scale - the scale; must be greater than zero
        Returns:
        Slice
        Throws:
        java.lang.NullPointerException - if the given slice is null
        java.lang.IllegalArgumentException - 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 polygon
        scale - the scale; must be greater than zero
        Returns:
        Polygon
        Throws:
        java.lang.NullPointerException - if the given polygon is null
        java.lang.IllegalArgumentException - 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 segment
        scale - the scale; must be greater than zero
        Returns:
        Segment
        Throws:
        java.lang.NullPointerException - if the given segment is null
        java.lang.IllegalArgumentException - if the given scale is less than or equal to zero
        Since:
        3.1.5
      • createLinks

        public static final java.util.List<Link> createLinks​(java.util.List<Vector2> vertices,
                                                             boolean closed)
        Creates a list of Links 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 vertices
        closed - true if the shape should be enclosed
        Returns:
        List<Link>
        Throws:
        java.lang.NullPointerException - if the list of vertices is null or an element of the vertex list is null
        java.lang.IllegalArgumentException - if the list of vertices doesn't contain 2 or more elements
        Since:
        3.2.2
      • createLinks

        public static final java.util.List<Link> createLinks​(Vector2[] vertices,
                                                             boolean closed)
        Creates a 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.

        Parameters:
        vertices - the poly-line vertices
        closed - true if the shape should be enclosed
        Returns:
        List<Link>
        Throws:
        java.lang.NullPointerException - if the array of vertices is null or an element of the vertex array is null
        java.lang.IllegalArgumentException - if the array of vertices doesn't contain 2 or more elements
        Since:
        3.2.2