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

Point[]perpendicular(Point a, Point z, double aDist, double size, boolean clockwise)
Calculates a perpendicular line to a given line.
double x = z.x - a.x, y = z.y - a.y;
double lineLength = Math.hypot(x, y);
double dx = x / lineLength, dy = y / lineLength;
double x1 = a.x + dx * aDist, y1 = a.y + dy * aDist;
if (!clockwise) {
    dx *= -1;
    dy *= -1;
double x2 = x1 + dy * size, y2 = y1 - dx * size;
Point p1 = new Point((int) x1, (int) y1);
Point p2 = new Point((int) x2, (int) y2);
return new Point[] { p1, p2 };
doubleperpendicularScalarProjection(Point2D.Double projVec, Point2D.Double dir)
Computes component of first vector that is perpendicular to the second vector
return Math.sqrt(projVec.distanceSq(0, 0) - pow(scalarProjection(projVec, dir), 2));
doubleplotBezier(GeneralPath path, @Nonnull Point2D p0, @Nonnull Point2D p1, @Nonnull Point2D p2, @Nonnull Point2D p3, int depth, double displacement)
plot Bezier
double result;
double l01 = distance(p0, p1);
double l12 = distance(p1, p2);
double l23 = distance(p2, p3);
double l03 = distance(p0, p3);
double flatness = (l01 + l12 + l23) / l03;
if ((depth > 12) || (flatness <= 1.001)) {
    Point2D vO = normalize(orthogonal(subtract(p3, p0)), displacement);
...
Pointplus(Point point1, Point point2)
plus
return new Point(point1.x + point2.x, point1.y + point2.y);
Point2D.DoublepolarPointAtInfinity(double angle)
Creates a point-at-infinity using a specified angle.
return new Point2D.Double(Double.POSITIVE_INFINITY, angle);
PointpolarToPoint(double angle, double fx, double fy)
polar To Point
double si = Math.sin(angle);
double co = Math.cos(angle);
return new Point((int) (fx * co + 0.5D), (int) (fy * si + 0.5D));
doublepositiveAngleBetween3Points(Point2D.Double p1, Point2D.Double p2, Point2D.Double p3)
Computes angle between three points.
if (isInfinite(p2)) {
    return 0;
double angleDiff = (isInfinite(p3) ? p3.y : positiveAngle(p3.x - p2.x, p3.y - p2.y))
        - (isInfinite(p1) ? p1.y : positiveAngle(p1.x - p2.x, p1.y - p2.y));
if (angleDiff < 0) {
    angleDiff += 2 * Math.PI;
return angleDiff;
doublepreciseFrontBumperOffset(Point2D.Double sourceLocation, Point2D.Double botLocation)
precise Front Bumper Offset
return sourceLocation.distance(botLocation) - distancePointToBot(sourceLocation, botLocation);
booleanpreprocess(Point2D pa, Point2D pb, Point2D pc)
Return false when two of the points are the same, because the area would be 0.
if ((pa.getX() == pb.getX()) && (pa.getY() == pb.getY())) {
    return false;
} else if ((pa.getX() == pc.getX()) && (pa.getY() == pc.getY())) {
    return false;
} else if ((pb.getX() == pc.getX()) && (pb.getY() == pc.getY())) {
    return false;
} else {
    return true;
...
doubleprodEscalar(Point2D p1, Point2D p2)
prod Escalar
double d = p1.getX() * p2.getX() + p1.getY() * p2.getY();
return d;