Class GeometricUtilities

java.lang.Object
de.gurkenlabs.litiengine.util.geom.GeometricUtilities

public class GeometricUtilities
extends java.lang.Object
  • Method Summary

    Modifier and TypeMethodDescription
    static doublecalcRotationAngleInDegrees​(double centerX, double centerY, double targetX, double targetY) 
    static doublecalcRotationAngleInDegrees​(java.awt.geom.Point2D centerPt, java.awt.geom.Point2D targetPt)
    Calculates the angle from centerPt to targetPt in degrees.
    static booleancontains​(java.awt.geom.Rectangle2D rectangle, java.awt.geom.Point2D p)
    Contains.
    static doubledistance​(double p1X, double p1Y, double p2X, double p2Y) 
    static doubledistance​(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2) 
    static doubledistance​(java.awt.geom.Rectangle2D rect, java.awt.geom.Point2D p)
    Distance.
    static booleanequals​(java.awt.geom.Point2D point1, java.awt.geom.Point2D point2, double epsilon) 
    static java.awt.geom.Rectangle2Dextrude​(java.awt.geom.Rectangle2D rect, double ext) 
    static java.awt.geom.Point2DgetAveragePosition​(java.awt.geom.Point2D... points) 
    static java.awt.geom.Point2DgetAveragePosition​(java.util.Collection<java.awt.geom.Point2D> points) 
    static java.awt.geom.Point2DgetCenter​(double x1, double y1, double x2, double y2) 
    static java.awt.geom.Point2DgetCenter​(java.awt.geom.Line2D line) 
    static java.awt.geom.Point2DgetCenter​(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2) 
    static java.awt.geom.Point2DgetCenter​(java.awt.geom.RectangularShape shape)
    Returns the center of a shape whose geometry is defined by a rectangular frame.
    static java.awt.geom.Ellipse2DgetCircle​(java.awt.geom.Point2D center, double radius) 
    static java.awt.geom.Line2D[]getConnectingLines​(java.awt.geom.Point2D point, java.awt.geom.Point2D[] rectPoints) 
    static java.util.List<java.awt.geom.Line2D.Double>getConstrainingLines​(java.awt.geom.Area area) 
    static floatgetDeltaX​(double angle) 
    static doublegetDeltaX​(double angle, double delta) 
    static floatgetDeltaY​(double angle) 
    static doublegetDeltaY​(double angle, double delta) 
    static doublegetDiagonal​(java.awt.geom.Rectangle2D rect) 
    static java.awt.geom.Point2DgetIntersectionPoint​(java.awt.geom.Line2D lineA, java.awt.geom.Line2D lineB)
    Gets the intersection point.
    static java.awt.geom.Point2DgetIntersectionPoint​(java.awt.geom.Line2D line, java.awt.geom.Rectangle2D rectangle)
    Intersects.
    static java.util.List<java.awt.geom.Point2D>getIntersectionPoints​(java.awt.geom.Line2D line, java.awt.geom.Rectangle2D rectangle)
    Gets the intersection points.
    static java.awt.geom.Line2D[]getLines​(java.awt.geom.Rectangle2D rectangle)
    Gets the lines.
    static java.awt.geom.Point2DgetPerpendicularIntersection​(java.awt.geom.Point2D point, java.awt.geom.Line2D line)
    Gets the perpendicular intersection.
    static java.awt.geom.Point2DgetPointOnCircle​(java.awt.geom.Point2D center, double radius, double angle) 
    static java.util.List<java.awt.geom.Point2D>getPoints​(java.awt.geom.Path2D path) 
    static java.util.List<java.awt.geom.Point2D>getPoints​(java.awt.geom.Rectangle2D rectangle)
    Gets the points.
    static java.util.List<java.awt.geom.Point2D>getPointsBetweenPoints​(java.awt.geom.Point2D point1, java.awt.geom.Point2D point2)
    Gets the points between the specified points using the Bresenham algorithm.
    static booleanintersects​(java.awt.geom.Ellipse2D a, java.awt.geom.Ellipse2D b) 
    static booleanintersects​(java.awt.geom.Rectangle2D a, java.awt.geom.Rectangle2D b) 
    static doublenormalizeAngle​(double angle)
    Normalizes the specified angle to the range between 0-360 degree.
    static java.awt.geom.Point2Dproject​(java.awt.geom.Point2D start, double angle, double delta)
    Project a line from a point with a given length and angle, return the point where the line ends.
    static java.awt.geom.Point2Dproject​(java.awt.geom.Point2D start, java.awt.geom.Point2D end, double scalar)
    Projects a point from end along the vector (end - start) by the given scalar amount.
    static java.awt.geom.Point2D[]rayCastPoints​(java.awt.geom.Point2D point, java.awt.geom.Rectangle2D rectangle) 
    static java.awt.ShapescaleRect​(java.awt.geom.Rectangle2D shape, int max) 
    static java.awt.ShapescaleShape​(java.awt.Shape shape, double scale) 
    static java.awt.geom.Dimension2DscaleWithRatio​(double width, double height, int max) 
    static booleanshapeIntersects​(java.awt.Shape shapeA, java.awt.Shape shapeB)
    Shape intersects.
    static java.awt.ShapetranslateShape​(java.awt.Shape shape, java.awt.geom.Point2D newLocation) 

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • calcRotationAngleInDegrees

      public static double calcRotationAngleInDegrees​(double centerX, double centerY, double targetX, double targetY)
    • calcRotationAngleInDegrees

      public static double calcRotationAngleInDegrees​(java.awt.geom.Point2D centerPt, java.awt.geom.Point2D targetPt)
      Calculates the angle from centerPt to targetPt in degrees. The return should range from [0,360), rotating CLOCKWISE, 0 and 360 degrees represents NORTH, 90 degrees represents EAST, etc... Assumes all points are in the same coordinate space. If they are not, you will need to call SwingUtilities.convertPointToScreen or equivalent on all arguments before passing them to this function.
      Parameters:
      centerPt - Point we are rotating around.
      targetPt - Point we want to calcuate the angle to.
      Returns:
      angle in degrees. This is the angle from centerPt to targetPt.
    • contains

      public static boolean contains​(java.awt.geom.Rectangle2D rectangle, java.awt.geom.Point2D p)
      Contains.
      Parameters:
      rectangle - the rectangle
      p - the p
      Returns:
      true, if successful
    • distance

      public static double distance​(double p1X, double p1Y, double p2X, double p2Y)
    • distance

      public static double distance​(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
    • distance

      public static double distance​(java.awt.geom.Rectangle2D rect, java.awt.geom.Point2D p)
      Distance.
      Parameters:
      rect - the rect
      p - the p
      Returns:
      the double
    • extrude

      public static java.awt.geom.Rectangle2D extrude​(java.awt.geom.Rectangle2D rect, double ext)
    • equals

      public static boolean equals​(java.awt.geom.Point2D point1, java.awt.geom.Point2D point2, double epsilon)
    • getConnectingLines

      public static java.awt.geom.Line2D[] getConnectingLines​(java.awt.geom.Point2D point, java.awt.geom.Point2D[] rectPoints)
    • getConstrainingLines

      public static java.util.List<java.awt.geom.Line2D.Double> getConstrainingLines​(java.awt.geom.Area area)
    • getDeltaX

      public static float getDeltaX​(double angle)
    • getDeltaY

      public static float getDeltaY​(double angle)
    • getDeltaX

      public static double getDeltaX​(double angle, double delta)
    • getDeltaY

      public static double getDeltaY​(double angle, double delta)
    • getIntersectionPoint

      public static java.awt.geom.Point2D getIntersectionPoint​(java.awt.geom.Line2D lineA, java.awt.geom.Line2D lineB)
      Gets the intersection point.
      Parameters:
      lineA - the line a
      lineB - the line b
      Returns:
      the intersection point
    • getIntersectionPoint

      public static java.awt.geom.Point2D getIntersectionPoint​(java.awt.geom.Line2D line, java.awt.geom.Rectangle2D rectangle)
      Intersects.
      Parameters:
      line - the line
      rectangle - the rectangle
      Returns:
      the point2 d
    • getIntersectionPoints

      public static java.util.List<java.awt.geom.Point2D> getIntersectionPoints​(java.awt.geom.Line2D line, java.awt.geom.Rectangle2D rectangle)
      Gets the intersection points.
      Parameters:
      line - the line
      rectangle - the rectangle
      Returns:
      the intersection points
    • getLines

      public static java.awt.geom.Line2D[] getLines​(java.awt.geom.Rectangle2D rectangle)
      Gets the lines.
      Parameters:
      rectangle - the rectangle
      Returns:
      the lines
    • getDiagonal

      public static double getDiagonal​(java.awt.geom.Rectangle2D rect)
    • getCenter

      public static java.awt.geom.Point2D getCenter​(java.awt.geom.Line2D line)
    • getCenter

      public static java.awt.geom.Point2D getCenter​(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
    • getCenter

      public static java.awt.geom.Point2D getCenter​(double x1, double y1, double x2, double y2)
    • getCenter

      public static java.awt.geom.Point2D getCenter​(java.awt.geom.RectangularShape shape)
      Returns the center of a shape whose geometry is defined by a rectangular frame. Works for any subclass of RectuangularShape, including:

      Arc2D
      Ellipse2D
      Rectangle2D
      RoundRectangle2D

      Parameters:
      shape - the shape to retrieve the center of
      Returns:
      a Point2D representing the center of the shape
      See Also:
      RectangularShape
    • getCircle

      public static java.awt.geom.Ellipse2D getCircle​(java.awt.geom.Point2D center, double radius)
    • getAveragePosition

      public static java.awt.geom.Point2D getAveragePosition​(java.util.Collection<java.awt.geom.Point2D> points)
    • getAveragePosition

      public static java.awt.geom.Point2D getAveragePosition​(java.awt.geom.Point2D... points)
    • getPerpendicularIntersection

      public static java.awt.geom.Point2D getPerpendicularIntersection​(java.awt.geom.Point2D point, java.awt.geom.Line2D line)
      Gets the perpendicular intersection.
      Parameters:
      point - the point
      line - the line
      Returns:
      the perpendicular intersection
    • getPointOnCircle

      public static java.awt.geom.Point2D getPointOnCircle​(java.awt.geom.Point2D center, double radius, double angle)
    • getPoints

      public static java.util.List<java.awt.geom.Point2D> getPoints​(java.awt.geom.Path2D path)
    • getPoints

      public static java.util.List<java.awt.geom.Point2D> getPoints​(java.awt.geom.Rectangle2D rectangle)
      Gets the points.
      Parameters:
      rectangle - the rectangle
      Returns:
      the points
    • getPointsBetweenPoints

      public static java.util.List<java.awt.geom.Point2D> getPointsBetweenPoints​(java.awt.geom.Point2D point1, java.awt.geom.Point2D point2)
      Gets the points between the specified points using the Bresenham algorithm.
      Parameters:
      point1 - the point1
      point2 - the point2
      Returns:
      the points between points
    • intersects

      public static boolean intersects​(java.awt.geom.Rectangle2D a, java.awt.geom.Rectangle2D b)
    • intersects

      public static boolean intersects​(java.awt.geom.Ellipse2D a, java.awt.geom.Ellipse2D b)
    • project

      public static java.awt.geom.Point2D project​(java.awt.geom.Point2D start, double angle, double delta)
      Project a line from a point with a given length and angle, return the point where the line ends.
      Parameters:
      start - The starting point of the projection.
      angle - The angle of the projection in degrees.
      delta - The distance between starting point and end point.
      Returns:
      The Point2D where the projection ends.
    • project

      public static java.awt.geom.Point2D project​(java.awt.geom.Point2D start, java.awt.geom.Point2D end, double scalar)
      Projects a point from end along the vector (end - start) by the given scalar amount.
      Parameters:
      start - the start
      end - the end
      scalar - the scalar
      Returns:
      the point2 d. double
    • rayCastPoints

      public static java.awt.geom.Point2D[] rayCastPoints​(java.awt.geom.Point2D point, java.awt.geom.Rectangle2D rectangle)
    • scaleRect

      public static java.awt.Shape scaleRect​(java.awt.geom.Rectangle2D shape, int max)
    • scaleWithRatio

      public static java.awt.geom.Dimension2D scaleWithRatio​(double width, double height, int max)
    • scaleShape

      public static java.awt.Shape scaleShape​(java.awt.Shape shape, double scale)
    • shapeIntersects

      public static boolean shapeIntersects​(java.awt.Shape shapeA, java.awt.Shape shapeB)
      Shape intersects. WARNING: USE THIS METHOD WITH CAUTION BECAUSE IT IS A VERY SLOW WAY OF CALCULATING INTERSECTIONS.
      Parameters:
      shapeA - the shape a
      shapeB - the shape b
      Returns:
      true, if successful
    • translateShape

      public static java.awt.Shape translateShape​(java.awt.Shape shape, java.awt.geom.Point2D newLocation)
    • normalizeAngle

      public static double normalizeAngle​(double angle)
      Normalizes the specified angle to the range between 0-360 degree.
      Parameters:
      angle - The angle that will be normalized.
      Returns:
      The normalized angle.