Java Utililty Methods Line Intersect

List of utility methods to do Line Intersect

Description

The list of methods to do Line Intersect are organized into topic(s).

Method

Pointintersect(int xa, int ya, int xb, int yb, int xc, int yc, int xd, int yd)
intersect
double denom = (double) ((xb - xa) * (yd - yc) - (yb - ya) * (xd - xc));
double rnum = (double) ((ya - yc) * (xd - xc) - (xa - xc) * (yd - yc));
if (denom == 0.0D) {
    return rnum != 0.0D ? null
            : ((xa >= xb || xb >= xc && xb >= xd) && (xa <= xb || xb <= xc && xb <= xd) ? new Point(xa, ya)
                    : new Point(xb, yb));
} else {
    double r = rnum / denom;
...
Pointintersect(Point a, Point b, Point c, Point d)
intersect
float[] rv = intersect(new float[] { a.x, a.y, b.x, b.y, c.x, c.y, d.x, d.y });
if (rv == null)
    return null;
return new Point((int) rv[0], (int) rv[1]);
Areaintersect(Shape shape1, Shape shape2)
Intersect 2 shapes and return result in an Area type shape.
final Area result = new Area(shape1);
result.intersect(new Area(shape2));
return result;
ShapeintersectClip(final Graphics2D g2d, final Shape clip)
Setting clip Shape by taking old clip Shape into account
return intersectClip(g2d, clip, true);
Point2Dintersection(Line2D a, Line2D b)
Computes the intersection between two lines.
double x1 = a.getX1(), y1 = a.getY1(), x2 = a.getX2(), y2 = a.getY2(), x3 = b.getX1(), y3 = b.getY1(),
        x4 = b.getX2(), y4 = b.getY2();
double d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
if (d == 0) {
    return null;
double xi = ((x3 - x4) * (x1 * y2 - y1 * x2) - (x1 - x2) * (x3 * y4 - y3 * x4)) / d;
double yi = ((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d;
...
Point2Dintersection(Line2D lineA, Line2D lineB)
Computes the intersection between two lines.
Point2D lineAPt1 = lineA.getP1();
Point2D lineAPt2 = lineA.getP2();
Point2D lineBPt1 = lineB.getP1();
Point2D lineBPt2 = lineB.getP2();
double x1 = lineAPt1.getX();
double y1 = lineAPt1.getY();
double x2 = lineAPt2.getX();
double y2 = lineAPt2.getY();
...
Point2D.Doubleintersection(Point2D p1, Point2D p2, Point2D p3, Point2D p4)
Return the intersection point between infinite line A defined by points p1 & p2 and infinite line B defined by points p3 & p4.
double x1 = p1.getX();
double y1 = p1.getY();
double x2 = p2.getX();
double y2 = p2.getY();
double x3 = p3.getX();
double y3 = p3.getY();
double x4 = p4.getX();
double y4 = p4.getY();
...
Point2DintersectionPoint(final Line2D l1, final Line2D l2)
Calculates the intersection point where the two infinitely enlarged lines meet.
final double x1 = l1.getX1();
final double y1 = l1.getY1();
final double x2 = l1.getX2();
final double y2 = l1.getY2();
final double x3 = l2.getX1();
final double y3 = l2.getY1();
final double x4 = l2.getX2();
final double y4 = l2.getY2();
...
PointintersectionZJU(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
intersection ZJU
long d = ((long) (y4 - y3)) * (x2 - x1) - ((long) (x4 - x3)) * (y2 - y1);
if (d == 0)
    return new Point(-1, -1); 
double a = (((long) (x4 - x3)) * (y1 - y3) - ((long) (y4 - y3)) * (x1 - x3)) * 1.0 / d;
int x = x1 + (int) (a * (x2 - x1));
int y = y1 + (int) (a * (y2 - y1));
if (x >= Math.min(x1, x2) && x <= Math.max(x1, x2) && x <= Math.max(x3, x4) && x >= Math.min(x3, x4)
        && y >= Math.min(y1, y2) && y <= Math.max(y1, y2) && y <= Math.max(y3, y4) && y >= Math.min(y3, y4)) 
...
PointintersectionZJU(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
intersection ZJU
long d = ((long) (y4 - y3)) * (x2 - x1) - ((long) (x4 - x3)) * (y2 - y1);
if (d == 0)
    return new Point(-1, -1); 
double a = (((long) (x4 - x3)) * (y1 - y3) - ((long) (y4 - y3)) * (x1 - x3)) * 1.0 / d;
int x = x1 + (int) (a * (x2 - x1));
int y = y1 + (int) (a * (y2 - y1));
if (x >= Math.min(x1, x2) && x <= Math.max(x1, x2) && x <= Math.max(x3, x4) && x >= Math.min(x3, x4)
        && y >= Math.min(y1, y2) && y <= Math.max(y1, y2) && y <= Math.max(y3, y4) && y >= Math.min(y3, y4)) 
...