Java Utililty Methods Geometry Algorithm

List of utility methods to do Geometry Algorithm

Description

The list of methods to do Geometry Algorithm are organized into topic(s).

Method

voidsetRevisePoint(Point2D.Double revisePoint, Point2D.Double startPoint)
set Revise Point
int MARGIN = 50;
if (startPoint.x <= 0) {
    revisePoint.x = (-startPoint.x) + MARGIN;
} else if (MARGIN < startPoint.x) {
    revisePoint.x = MARGIN - startPoint.x;
if (startPoint.y <= 0) {
    revisePoint.y = (-startPoint.y) + MARGIN;
...
doubleslopeOfLineBetween(Point2D.Double p1, Point2D.Double p2)
Computes slope between two points.
if (p1.equals(p2)) {
    return Double.NaN;
} else if (p1.x == p2.x) {
    return Double.POSITIVE_INFINITY;
} else {
    return (p2.y - p1.y) / (p2.x - p1.x);
Rectangle2DsmallestBoundingBox(java.awt.Point.Double[] points)
Returns the smalles BoundingBox, which contains a number of Poins
double minX = points[0].x;
double minY = points[0].y;
double maxX = points[0].x;
double maxY = points[0].y;
for (java.awt.Point.Double p : points) {
    if (p.x < minX) {
        minX = p.x;
    if (p.y < minY) {
        minY = p.y;
    if (p.x > maxX) {
        maxX = p.x;
    if (p.y > maxY) {
        maxY = p.y;
return new Rectangle.Double(minX, minY, maxX - minX, maxY - minY);
PointsnapToGrid(Point original, double gridSpacing)
Returns a point on the grid as specified by the gridSpacing.
Point result = new Point(original);
result.x = (int) (gridSpacing * Math.round(result.x / gridSpacing));
result.y = (int) (gridSpacing * Math.round(result.y / gridSpacing));
return result;
Point[]starRunner(int[][] screen, int x, int y, List blueList)
star Runner
if (x < 0 || y < 0 || x >= screen.length || y >= screen[0].length)
    return new Point[0];
Color pixelColor = new Color(screen[x][y], true);
if (!(pixelColor.getBlue() == 255 && pixelColor.getGreen() == 0 && pixelColor.getRed() == 0)) {
    Point[] containerArr = { new Point(x, y) };
    return containerArr;
boolean didEndSoon = false;
...
doublete static double t(Point2D.Double original, Point2D.Double endpt1, Point2D.Double endpt2)
t
return ((endpt1.x - original.x) * (endpt1.x - endpt2.x) + (endpt1.y - original.y) * (endpt1.y - endpt2.y))
        / endpt1.distanceSq(endpt2);
doublevecLength(final Point2D v)
Calculates the length of a vector.
return Math.sqrt(vecLengthSqr(v));
AreaverticalParallelogram(Point2D top, Point2D bottom, double width)
Create a parallelogram mostly vertical, where top and bottom sides are short and horizontal.
final double dx = width / 2; 
final Path2D path = new Path2D.Double();
path.moveTo(top.getX() - dx, top.getY()); 
path.lineTo(top.getX() + dx + 1, top.getY()); 
path.lineTo(bottom.getX() + dx + 1, bottom.getY() + 1); 
path.lineTo(bottom.getX() - dx, bottom.getY() + 1); 
path.closePath();
return new Area(path);
...