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

voidcheckPoint(Point point, String name)

Checks a Point.

checkNull(point, name);
checkNegative(point.x, name + "'s x");
checkNegative(point.y, name + "'s y");
intcheckWinPossibility(int[][] board, Point p1, Point p2, int playerID)
check Win Possibility
int TwoOpenEndsRetVal = 3;
int xDistance = p1.x - p2.x;
int yDistance = p1.y - p2.y;
int length = (Math.abs(xDistance) > Math.abs(yDistance) ? Math.abs(xDistance) : Math.abs(yDistance)) + 1; 
if (p1.y == p2.y) {
    int openLeft = 0, openRight = 0;
    for (int dx = 1; p1.x - dx >= 0; dx++) {
        if (board[p1.x - dx][p1.y] == 0) { 
...
voidcircleLineIntersection(double theta, double r, double h, double k, Point2D[] result)
circle Line Intersection
if (result.length != 2) {
    (new Exception("result must have length 2!")).printStackTrace();
    return;
double tanTheta = Math.tan(theta);
double a = 1.0 + Math.pow(tanTheta, 2);
double b = -2.0 * h - 2.0 * k * tanTheta;
double c = Math.pow(h, 2) + Math.pow(k, 2) - Math.pow(r, 2);
...
doubleclacGradient(Point2D p1, Point2D p2, Point2D p3)
clac Gradient
double p1x = p1.getX();
double p1y = p1.getY();
double p2x = p2.getX();
double p2y = p2.getY();
double p3x = p3.getX();
double p3y = p3.getY();
return p1x * (p2y - p3y) + p2x * (p3y - p1y) + p3x * (p1y - p2y);
intcleanList(List blueList, Polygon borders)
clean List
int numRemoved = 0;
for (int i = 0; i < blueList.size(); i++) {
    Point currentPoint = blueList.get(i);
    if (borders.contains(currentPoint)) {
        blueList.remove(i);
        i--;
        numRemoved++;
return numRemoved;
Point2DcolinearPoint(Line2D line, Point2D point, double distance)
colinear Point
return colinearPoint(line.getX1(), line.getY1(), line.getX2(), line.getY2(), point.getX(), point.getY(),
        distance);
doublecomputeAngleDEG(@Nonnull Point2D p1, @Nonnull Point2D p2)
compute the angle (direction in degrees) from point 1 to point 2

Note: Goes CCW from south to east to north to west, etc.

return Math.toDegrees(computeAngleRAD(subtract(p1, p2)));
doublecomputeAngleRAD(@Nonnull Point2D p)
compute the angle (direction in radians) for a vector
return Math.atan2(p.getX(), p.getY());
Point2DcomputeBarycenter(Map values)
compute Barycenter
double x = 0, y = 0;
for (Map.Entry<Point2D, Double> e : values.entrySet()) {
    Point2D point = e.getKey();
    double value = e.getValue();
    x += value * point.getX();
    y += value * point.getY();
int size = values.size();
...
doublecomputeEuclideanDistance(Point2D point1, Point2D point2)
Computes the Euclidean distance between two points.
return point1.distance(point2);