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

doublecomputePolygonArea(Point2D[] pts)
Computes the area of the specified polygon.
int n = pts.length;
double area = 0.0;
for (int i = 0; i < n - 1; i++) {
    area += (pts[i].getX() * pts[i + 1].getY()) - (pts[i + 1].getX() * pts[i].getY());
area += (pts[n - 1].getX() * pts[0].getY()) - (pts[0].getX() * pts[n - 1].getY());
area *= 0.5;
return area;
...
voidcoordinateSplit(Point2D.Double[] aPoints, double[] aX, double[] aY)
Stores the coordinates of the given points in separate arrays.
final int count = aPoints.length;
if (aX.length < count || aY.length < count) {
    throw new ArrayIndexOutOfBoundsException(count);
for (int i = 0; i < count; ++i) {
    final Point2D.Double point = aPoints[i];
    aX[i] = point.x;
    aY[i] = point.y;
...
double[]cornersToWorldFile(Point2D[] esq, Dimension size)
corners To World File
double a = 0, b = 0, c = 0, d = 0, e = 0, f = 0;
double x1 = esq[0].getX(), y1 = esq[0].getY();
double x2 = esq[1].getX(), y2 = esq[1].getY();
double x3 = esq[2].getX(), y3 = esq[2].getY();
double x4 = esq[3].getX(), y4 = esq[3].getY();
a = Math.abs(Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) / size.getWidth());
e = -Math.abs(Math.sqrt((x1 - x4) * (x1 - x4) + (y1 - y4) * (y1 - y4)) / size.getHeight());
c = x1;
...
booleancurvedLineHit(Point point, Point startPoint, Point endPoint, Point controlPoint1, Point controlPoint2, float padding)
Find the square of the distance between the point and a point on the curve (u).
Point a[] = new Point[4]; 
double c[] = new double[7]; 
double u;
double tolerance = padding + 1 / 2;
double delta;
double minDelta;
int i;
tolerance *= tolerance;
...
Point2DderivativeOfCubicBezier(Point2D p0, Point2D p1, Point2D p2, Point2D p3, double t)
Computes derivative of cubic bezier at specified point
double ax = 3 * p1.getX() - 3 * p2.getX() - p0.getX() + p3.getX();
double bx = 3 * (p0.getX() - 2 * p1.getX() + p2.getX());
double cx = 3 * (p1.getX() - p0.getX());
double ay = 3 * p1.getY() - 3 * p2.getY() - p0.getY() + p3.getY();
double by = 3 * (p0.getY() - 2 * p1.getY() + p2.getY());
double cy = 3 * (p1.getY() - p0.getY());
double x = 3 * ax * t * t + 2 * bx * t + cx;
double y = 3 * ay * t * t + 2 * by * t + cy;
...
PointderiveLocation(Point origin, double radius)
derive Location
return new Point((int) ((origin.getX() - radius) + (Math.random() * 2 * radius)),
        (int) ((origin.getY() - radius) + (Math.random() * 2 * radius)));
PointdetermineConnectionPoint(Point wayPoint, Polygon polygon)

Help function:

This function determine the connection point on polygon, Which is the nearest point to the given point.

double shortestDistance = Double.MAX_VALUE;
Point connectionPoint = new Point();
for (int i = 0; i < polygon.npoints; i++) {
    Point start = new Point(polygon.xpoints[i], polygon.ypoints[i]);
    Point end = new Point(polygon.xpoints[(i + 1) % polygon.npoints],
            polygon.ypoints[(i + 1) % polygon.npoints]);
    double distance = Double.MAX_VALUE;
    if (dot(start, end, wayPoint) >= 0) {
...
Point2D.DoubledirectVincenty(Point2D.Double point, double brng, double distance)
Calculate a destination point given a start point, a bearing angle and a distance.
double a = 6378137, b = 6356752.3142, f = 1 / 298.257223563;
double s = distance;
double alpha1 = brng * Math.PI / 180;
double sinAlpha1 = Math.sin(alpha1);
double cosAlpha1 = Math.cos(alpha1);
double tanU1 = (1 - f) * Math.tan(point.y * Math.PI / 180);
double cosU1 = 1 / Math.sqrt((1 + tanU1 * tanU1)), sinU1 = tanU1 * cosU1;
double sigma1 = Math.atan2(tanU1, cosAlpha1);
...
doubledot(@Nonnull Point2D pA, @Nonnull Point2D pB)
dot product of two points (vectors)
return (pA.getX() * pB.getX() + pA.getY() * pB.getY());
doubledot(final Point2D a, final Point2D b)
Calculates the dot product of two vectors.
return a.getX() * b.getX() + a.getY() * b.getY();