List of utility methods to do Geometry Algorithm
int | dot(Point a, Point b, Point c) Help function: This function calculates the dot product of vector ab and bc. return (b.x - a.x) * (c.x - b.x) + (b.y - a.y) * (c.y - b.y);
|
double | dotNorm(final Point2D a, final Point2D b) Calculates the normalized dot product of two vectors. return dot(a, b) / (vecLength(a) * vecLength(b));
|
void | drag(Robot robot, Point startPoint, Point endPoint, int button) Drags from one point to another with the specified mouse button pressed. if (!(button == InputEvent.BUTTON1_MASK || button == InputEvent.BUTTON2_MASK || button == InputEvent.BUTTON3_MASK)) { throw new IllegalArgumentException("invalid mouse button"); robot.mouseMove(startPoint.x, startPoint.y); robot.mousePress(button); try { mouseMove(robot, startPoint, endPoint); ... |
int | dx(Point a, Point b) dx return Math.abs(a.x - b.x);
|
HashSet | edge(Collection Calculate the edge of the specified linked area. HashSet<Point> edge = new HashSet<Point>(); int x = 0; int y = 0; for (Point p : points) { if (p.x > x) x = p.x; if (p.y > y) y = p.y; ... |
void | extendLine(Point2D p0, Point2D p1, double toLength) extend Line final double oldLength = p0.distance(p1); final double lengthFraction = oldLength != 0.0 ? toLength / oldLength : 0.0; p1.setLocation(p0.getX() + (p1.getX() - p0.getX()) * lengthFraction, p0.getY() + (p1.getY() - p0.getY()) * lengthFraction); |
double | findArea(Point2D p1, Point2D p2, Point2D p3) Given three points each represents the vertex of a triangle, return the area of this triangle. if (!preprocess(p1, p2, p3)) { return 0.0; } else { double p4x; double p4y; double m13 = findSlope(p1.getX(), p1.getY(), p3.getX(), p3.getY()); double m24 = 0; if (Double.isNaN(m13)) { ... |
Dimension | findDimension(Point2D[] pts) Returns the dimensions of the smallest rectangle that could contain the supplied points. double minx = Double.POSITIVE_INFINITY; double maxx = Double.NEGATIVE_INFINITY; double miny = Double.POSITIVE_INFINITY; double maxy = Double.NEGATIVE_INFINITY; for (Point2D pt : pts) { minx = Math.min(minx, pt.getX()); maxx = Math.max(maxx, pt.getX()); miny = Math.min(miny, pt.getY()); ... |
Point2D | findDistancedPoint(double t, Point2D sp, Point2D c1, Point2D c2, Point2D ep) method used to find any point in given distance in cubic bezier curve double d = 1 - t; double dCube = d * d * d; double dSqr = d * d; double tCube = t * t * t; double tSqr = t * t; double xCoord = (dCube * sp.getX()) + (3 * t * dSqr * c1.getX()) + (3 * tSqr * d * c2.getX()) + (tCube * ep.getX()); double yCoord = (dCube * sp.getY()) + (3 * t * dSqr * c1.getY()) + (3 * tSqr * d * c2.getY()) ... |
Point2D | findIntersect(Point2D p1, Point2D p2, Point2D p3, Point2D p4) find Intersect double xD1, yD1, xD2, yD2, xD3, yD3; double ua, div; xD1 = p2.getX() - p1.getX(); xD2 = p4.getX() - p3.getX(); yD1 = p2.getY() - p1.getY(); yD2 = p4.getY() - p3.getY(); xD3 = p1.getX() - p3.getX(); yD3 = p1.getY() - p3.getY(); ... |