List of utility methods to do Geometry Algorithm
void | setRevisePoint(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; ... |
double | slopeOfLineBetween(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); |
Rectangle2D | smallestBoundingBox(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); |
Point | snapToGrid(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 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; ... |
double | te 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);
|
double | vecLength(final Point2D v) Calculates the length of a vector. return Math.sqrt(vecLengthSqr(v));
|
Area | verticalParallelogram(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); ... |