Point (Line2D aFirst, Line2D aSecond) { double firstDeltaX = aFirst.getX2() - aFirst.getX1(); double firstDeltaY = aFirst.getY2() - aFirst.getY1(); double kFirst = firstDeltaY / firstDeltaX; double bFirst = aFirst.getY1() - kFirst * aFirst.getX1(); double secondDeltaX = aSecond.getX2() - aSecond.getX1(); double secondDeltaY = aSecond.getY2() - aSecond.getY1(); double kSecond = secondDeltaY / secondDeltaX; double bSecond = aSecond.getY1() - kSecond * aSecond.getX1(); double xIntersection; double yIntersection; double deltaK = (kFirst - kSecond); if (linesAreAngledAndParallel(kFirst, kSecond)) { return null; } if (Double.isInfinite(deltaK) || (0 == deltaK)) { if (firstDeltaX == secondDeltaX && 0 == firstDeltaX) { return null; } if (firstDeltaY == secondDeltaY && 0 == firstDeltaY) { return null; } if ((0 == firstDeltaX) && (0 == secondDeltaY)) { xIntersection = aFirst.getX1(); yIntersection = aSecond.getY1(); } else if ((0 == secondDeltaX) && (0 == firstDeltaY)) { xIntersection = aSecond.getX1(); yIntersection = aFirst.getY1(); } else { if (0 == firstDeltaX) { xIntersection = aFirst.getX1(); yIntersection = kSecond * xIntersection + bSecond; } else { xIntersection = aSecond.getX1(); yIntersection = kFirst * xIntersection + bFirst; } } } else { xIntersection = (bSecond - bFirst) / deltaK; yIntersection = kFirst * xIntersection + bFirst; } return new Point((int) xIntersection, (int) yIntersection); }