List of utility methods to do Geometry Algorithm
Point | makeNeighbor(Point theHex, int direction) This method will return a point that is the neighbor of the given point in the given direction. int colPolarity = (theHex.x & 0x01); return new Point(theHex.x + neighborCols[direction], theHex.y + neighborRows[colPolarity][direction]); |
int | manhattanDistance(Point a, Point b) Calculate manhattan distance between two locations. return Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
|
Point | mirrorMoveVertically(Point move, int size) mirror Move Vertically return new Point((size - 1) - move.x, move.y); |
Point2D.Double | nearestColinearPoint(final double x1, final double y1, final double x2, final double y2, double x, double y) Returns the point on the given line segment which is closest to the given point . final double slope = (y2 - y1) / (x2 - x1); if (!Double.isInfinite(slope)) { final double y0 = (y2 - slope * x2); x = ((y - y0) * slope + x) / (slope * slope + 1); y = x * slope + y0; } else { x = x2; if (x1 <= x2) { if (x < x1) x = x1; if (x > x2) x = x2; } else { if (x > x1) x = x1; if (x < x2) x = x2; if (y1 <= y2) { if (y < y1) y = y1; if (y > y2) y = y2; } else { if (y > y1) y = y1; if (y < y2) y = y2; return new Point2D.Double(x, y); |
Point2D | nearestColinearPoint(final Line2D segment, final Point2D point) nearest Colinear Point return nearestColinearPoint(segment.getX1(), segment.getY1(), segment.getX2(), segment.getY2(),
point.getX(), point.getY());
|
Point2D | nearestPointOnLine(Line2D l, Point2D p, boolean clampToSegment, Point2D dest) nearest Point On Line if (dest == null) { dest = new Point2D.Double(); double apx = p.getX() - l.getX1(); double apy = p.getY() - l.getY1(); double abx = l.getX2() - l.getX1(); double aby = l.getY2() - l.getY1(); double ab2 = abx * abx + aby * aby; ... |
Point2D | newZeroPoint() new Zero Point return newPoint2D(0.0, 0.0);
|
Point2D | oneThirdPoint(@Nonnull Point2D pA, @Nonnull Point2D pB) calculate the point 1/3 of the way between two points return lerp(pA, pB, 1.0 / 3.0);
|
double[] | parabolaByFocusAndDirectrix(Point2D.Double focus, double directrix) Returns parabola with given point as its focus. return new double[] { -.5 / (directrix - focus.x), focus.y / (directrix - focus.x), .5 * (focus.x + directrix - focus.y * focus.y / (directrix - focus.x)) }; |
void | parameterizeCurve(Point[] coefficients, Point startPoint, Point endPoint, Point controlPoint1, Point controlPoint2) Given a curveto's endpoints and control points, compute the coefficients to trace out the curve as p(t) = c[0] + c[1]*t + c[2]*t^2 + c[3]*t^3 Point tangent2 = new Point(); tangent2.x = (int) (3.0 * (endPoint.x - controlPoint2.x)); tangent2.y = (int) (3.0 * (endPoint.y - controlPoint2.y)); coefficients[0] = startPoint; coefficients[1] = new Point((int) (3.0 * (controlPoint1.x - startPoint.x)), (int) (3.0 * (controlPoint1.y - startPoint.y))); coefficients[2] = new Point( (int) (3.0 * (endPoint.x - startPoint.x) - 2.0 * coefficients[1].x - tangent2.x), ... |