Class GeometricUtilities
java.lang.Object
de.gurkenlabs.litiengine.util.geom.GeometricUtilities
-
Method Summary
Modifier and TypeMethodDescriptionstatic doublecalcRotationAngleInDegrees(double centerX, double centerY, double targetX, double targetY) static doublecalcRotationAngleInDegrees(Point2D centerPt, Point2D targetPt) Calculates the angle from centerPt to targetPt in degrees.static booleancontains(Rectangle2D rectangle, Point2D p) Contains.static doubledistance(double p1X, double p1Y, double p2X, double p2Y) static doublestatic doubledistance(Rectangle2D rect, Point2D p) Distance.static booleanstatic Rectangle2Dextrude(Rectangle2D rect, double ext) static Point2DgetAverageLocation(Point2D... points) static Point2DgetAverageLocation(Collection<Point2D> points) static Point2DgetCenter(double x1, double y1, double x2, double y2) static Point2Dstatic Point2Dstatic Point2DgetCenter(RectangularShape shape) Returns the center of a shape whose geometry is defined by a rectangular frame.static Ellipse2Dstatic Line2D[]getConnectingLines(Point2D point, Point2D[] rectPoints) static List<Line2D.Double> getConstrainingLines(Area area) static floatgetDeltaX(double angle) static doublegetDeltaX(double angle, double delta) static floatgetDeltaY(double angle) static doublegetDeltaY(double angle, double delta) static doublegetDiagonal(Rectangle2D rect) static Point2DgetIntersectionPoint(Line2D lineA, Line2D lineB) Gets the intersection point.static Point2DgetIntersectionPoint(Line2D line, Rectangle2D rectangle) Intersects.getIntersectionPoints(Line2D line, Rectangle2D rectangle) Gets the intersection points.static Line2D[]getLines(Rectangle2D rectangle) Gets the lines.static Point2DgetPerpendicularIntersection(Point2D point, Line2D line) Gets the perpendicular intersection.static Point2DgetPointOnCircle(Point2D center, double radius, double angle) getPoints(Rectangle2D rectangle) Gets the points.getPointsBetweenPoints(Point2D point1, Point2D point2) Gets the points between the specified points using the Bresenham algorithm.static booleanintersects(Ellipse2D a, Ellipse2D b) static booleanintersects(Rectangle2D a, Rectangle2D b) static doublenormalizeAngle(double angle) Normalizes the specified angle to the range between 0-360 degree.static Point2DProject a line from a point with a given length and angle, return the point where the line ends.static Point2DProjects a point from end along the vector (end - start) by the given scalar amount.static Point2D[]rayCastPoints(Point2D point, Rectangle2D rectangle) static ShapescaleRect(Rectangle2D shape, int max) static ShapescaleShape(Shape shape, double scale) static Dimension2DscaleWithRatio(double width, double height, int max) static booleanshapeIntersects(Shape shapeA, Shape shapeB) Shape intersects.static ShapetranslateShape(Shape shape, Point2D newLocation)
-
Method Details
-
calcRotationAngleInDegrees
public static double calcRotationAngleInDegrees(double centerX, double centerY, double targetX, double targetY) -
calcRotationAngleInDegrees
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
Contains.- Parameters:
rectangle- the rectanglep- the p- Returns:
- true, if successful
-
distance
public static double distance(double p1X, double p1Y, double p2X, double p2Y) -
distance
-
distance
Distance.- Parameters:
rect- the rectp- the p- Returns:
- the double
-
extrude
-
equals
-
getConnectingLines
-
getConstrainingLines
-
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
Gets the intersection point.- Parameters:
lineA- the line alineB- the line b- Returns:
- the intersection point
-
getIntersectionPoint
Intersects.- Parameters:
line- the linerectangle- the rectangle- Returns:
- the point2 d
-
getIntersectionPoints
Gets the intersection points.- Parameters:
line- the linerectangle- the rectangle- Returns:
- the intersection points
-
getLines
Gets the lines.- Parameters:
rectangle- the rectangle- Returns:
- the lines
-
getDiagonal
-
getCenter
-
getCenter
-
getCenter
-
getCenter
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:
-
getCircle
-
getAverageLocation
-
getAverageLocation
-
getPerpendicularIntersection
Gets the perpendicular intersection.- Parameters:
point- the pointline- the line- Returns:
- the perpendicular intersection
-
getPointOnCircle
-
getPoints
-
getPoints
Gets the points.- Parameters:
rectangle- the rectangle- Returns:
- the points
-
getPointsBetweenPoints
Gets the points between the specified points using the Bresenham algorithm.- Parameters:
point1- the point1point2- the point2- Returns:
- the points between points
-
intersects
-
intersects
-
project
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
Point2Dwhere the projection ends.
-
project
Projects a point from end along the vector (end - start) by the given scalar amount.- Parameters:
start- the startend- the endscalar- the scalar- Returns:
- the point2 d. double
-
rayCastPoints
-
scaleRect
-
scaleWithRatio
-
scaleShape
-
shapeIntersects
Shape intersects. WARNING: USE THIS METHOD WITH CAUTION BECAUSE IT IS A VERY SLOW WAY OF CALCULATING INTERSECTIONS.- Parameters:
shapeA- the shape ashapeB- the shape b- Returns:
- true, if successful
-
translateShape
-
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.
-