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

voidassertEDT(String point)
Assert that the current thread is the EDT.
assert isEDT() : "EDT Violation : " + point + " must be called in EDT";
ArrayListbotCorners(Point2D.Double p)
bot Corners
ArrayList<Point2D.Double> corners = new ArrayList<Point2D.Double>();
corners.add(new Point2D.Double(p.x - BOT_HALF_WIDTH, p.y - BOT_HALF_WIDTH));
corners.add(new Point2D.Double(p.x - BOT_HALF_WIDTH, p.y + BOT_HALF_WIDTH));
corners.add(new Point2D.Double(p.x + BOT_HALF_WIDTH, p.y - BOT_HALF_WIDTH));
corners.add(new Point2D.Double(p.x + BOT_HALF_WIDTH, p.y + BOT_HALF_WIDTH));
return corners;
Rectangle2D.DoublebotRect(Point2D.Double botLocation)
bot Rect
Rectangle2D.Double botRect = new Rectangle2D.Double(botLocation.x - 18, botLocation.y - 18, 36, 36);
return botRect;
ArrayListbotSides(Point2D.Double botLocation)
bot Sides
ArrayList<Line2D.Double> botSides = new ArrayList<Line2D.Double>();
botSides.add(
        new Line2D.Double(botLocation.x - 18, botLocation.y - 18, botLocation.x + 18, botLocation.y - 18));
botSides.add(
        new Line2D.Double(botLocation.x + 18, botLocation.y - 18, botLocation.x + 18, botLocation.y + 18));
botSides.add(
        new Line2D.Double(botLocation.x + 18, botLocation.y + 18, botLocation.x - 18, botLocation.y + 18));
botSides.add(
...
Rectanglebound(Point... points)
bound
int smallestX = Integer.MAX_VALUE;
int smallestY = Integer.MAX_VALUE;
int largestX = Integer.MIN_VALUE;
int largestY = Integer.MIN_VALUE;
for (Point point : points) {
    if (point == null) {
        continue;
    if (point.x > largestX)
        largestX = point.x;
    if (point.y > largestY)
        largestY = point.y;
    if (point.x < smallestX)
        smallestX = point.x;
    if (point.y < smallestY)
        smallestY = point.y;
return new Rectangle(smallestX, smallestY, largestX - smallestX, largestY - smallestY);
Rectangle2DboundingBox(Vector points)
bounding Box
double minX = Double.MAX_VALUE;
double minY = Double.MAX_VALUE;
double maxX = Double.MIN_VALUE;
double maxY = Double.MIN_VALUE;
Point2D next;
for (Iterator<Point2D> iterator = points.iterator(); iterator.hasNext();) {
    next = iterator.next();
    minX = Math.min(minX, next.getX());
...
RectangleboundsOf(Collection points)
Report the bounding box for all points
if ((points == null) || points.isEmpty()) {
    return null;
Rectangle bounds = null;
for (Point point : points) {
    if (bounds == null) {
        bounds = new Rectangle(point);
    } else {
...
java.awt.geom.Point2D.Doublecap(java.awt.geom.Point2D.Double p1, java.awt.geom.Point2D.Double p2, double radius)
cap
double angle = 1.5707963267948966D - Math.atan2(p2.x - p1.x, p2.y - p1.y);
java.awt.geom.Point2D.Double p3 = new java.awt.geom.Point2D.Double(p2.x + radius * Math.cos(angle),
        p2.y + radius * Math.sin(angle));
return p3;
Point2Dcentroid(Vector points)
centroid
double sumX = 0;
double sumY = 0;
for (Iterator<Point2D> iterator = points.iterator(); iterator.hasNext();) {
    Point2D next = iterator.next();
    sumX += next.getX();
    sumY += next.getY();
int length = points.size();
...
booleancheckPoint(Point p)
check Point
return clip.contains(p);