Here you can find the source of findIntersect(Point2D p1, Point2D p2, Point2D p3, Point2D p4)
public static Point2D findIntersect(Point2D p1, Point2D p2, Point2D p3, Point2D p4)
//package com.java2s; /*/* ww w .j av a 2s . co m*/ * =========================================== * Java Pdf Extraction Decoding Access Library * =========================================== * * Project Info: http://www.idrsolutions.com * Help section for developers at http://www.idrsolutions.com/support/ * * (C) Copyright 1997-2016 IDRsolutions and Contributors. * * This file is part of JPedal/JPDF2HTML5 * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * --------------- * ShadingUtils.java * --------------- */ import java.awt.geom.Point2D; public class Main { public static Point2D findIntersect(Point2D p1, Point2D p2, Point2D p3, Point2D p4) { double xD1, yD1, xD2, yD2, xD3, yD3; //double dot, deg, len1, len2; double ua, div; // calculate differences 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(); //len1 = Math.sqrt(xD1 * xD1 + yD1 * yD1); //len2 = Math.sqrt(xD2 * xD2 + yD2 * yD2); //dot = (xD1 * xD2 + yD1 * yD2); //deg = dot / (len1 * len2); // find intersection Pt between two lines //Point pt = new Point(0, 0); div = yD2 * xD1 - xD2 * yD1; ua = (xD2 * yD3 - yD2 * xD3) / div; //ub = (xD1 * yD3 - yD1 * xD3) / div; return new Point2D.Double((p1.getX() + ua * xD1), (p1.getY() + ua * yD1)); } }