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

Point2D.DoublefindIntersection(Point2D.Double p1, Point2D.Double p2, Point2D.Double p3, Point2D.Double p4)
find Intersection
double denominator = (p4.getY() - p3.getY()) * (p2.getX() - p1.getX())
        - (p4.getX() - p3.getX()) * (p2.getY() - p1.getY());
double ua = ((p4.getX() - p3.getX()) * (p1.getY() - p3.getY())
        - (p4.getY() - p3.getY()) * (p1.getX() - p3.getX())) / denominator;
double x = epsilon(p1.getX() + ua * (p2.getX() - p1.getX()));
double y = epsilon(p1.getY() + ua * (p2.getY() - p1.getY()));
return new Point2D.Double(x, y);
intfindLineSegmentIntersection(Line2D one, Line2D two, Point2D intersection)
Compute the intersection between two line segments, or two lines of infinite length.
final double x0 = one.getX1();
final double y0 = one.getY1();
final double x1 = one.getX2();
final double y1 = one.getY2();
final double x2 = two.getX1();
final double y2 = two.getY1();
final double x3 = two.getX2();
final double y3 = two.getY2();
...
Point2DfindMiddlePoint(Point2D p1, Point2D p2)
Return the middle point between p1 and p2.
double x = (p1.getX() + p2.getX()) / 2;
double y = (p1.getY() + p2.getY()) / 2;
return (new Point2D.Double(x, y));
Ellipse2DfitCircle(final Point2D P1, final Point2D P2, final Point2D P3)
fit Circle
final Point2D center = circleCentre(P1.getX(), P1.getY(), P2.getX(), P2.getY(), P3.getX(), P3.getY());
final double radius = center.distance(P2);
return new Ellipse2D.Double(center.getX() - radius, center.getY() - radius, 2 * radius, 2 * radius);
voidforceMouseMove(Point pos)
Forces a mouse movement by 1 pixel to the right and back that will generate mouse movement events.
try {
    Robot robot = new Robot();
    robot.setAutoDelay(0);
    robot.mouseMove(pos.x + 1, pos.y);
    robot.mouseMove(pos.x, pos.y);
} catch (AWTException e) {
Line2D.DoublegenerateLine(Point2D.Double point, double length, double angle)
generate Line
double endX = length * Math.cos(angle * (Math.PI / 180)) + point.x;
double endY = length * Math.sin(angle * (Math.PI / 180)) + point.y;
return new Line2D.Double(point, new Point2D.Double(endX, endY));
StringgenerateLookAtTag(ArrayList geoCoords, ArrayList modsAM)
generate Look At Tag
Boolean doLookAt = true;
Rectangle2D controlPointBounds = null;
Point2D tempPt = null;
StringBuilder LookAtTag = new StringBuilder("<LookAt>");
if (doLookAt) {
    for (int j = 0; j < geoCoords.size(); j++) {
        tempPt = geoCoords.get(j);
        if (controlPointBounds != null) {
...
PointgeneratePoint(Shape region)
generate Point
Rectangle r = region.getBounds();
double x, y;
do {
    x = r.getX() + r.getWidth() * Math.random();
    y = r.getY() + r.getHeight() * Math.random();
} while (!region.contains(x, y));
return new Point((int) x, (int) y);
ListgenerateRobotPositions(Point start, Point end, int stepSize)
generate Robot Positions
List<Point> positions = new ArrayList<Point>();
int numXIterations = Math.abs(start.x - end.x) / stepSize;
int lastStepSize = Math.abs(start.x - end.x) % stepSize;
int startX = start.x;
int startY = start.y;
for (int i = 0; i < numXIterations; i++) {
    startX = (start.x > end.x) ? startX - stepSize : startX + stepSize;
    Point temp = new Point(startX, startY);
...
Point[]generateSpline(final Point[] controls)
Generates a spline that moves no more then one pixel at a time TIP: For most movements, this spline is not good, use applyDynamism
final double degree = controls.length - 1;
final java.util.Vector<Point> spline = new java.util.Vector<Point>();
boolean lastFlag = false;
for (double theta = 0; theta <= 1; theta += 0.01) {
    double x = 0;
    double y = 0;
    for (double index = 0; index <= degree; index++) {
        final double probPoly = nCk((int) degree, (int) index) * Math.pow(theta, index)
...