Here you can find the source of findIntersection(Point2D.Double p1, Point2D.Double p2, Point2D.Double p3, Point2D.Double p4)
static Point2D.Double findIntersection(Point2D.Double p1, Point2D.Double p2, Point2D.Double p3,
Point2D.Double p4)
//package com.java2s; /*//ww w . ja va 2s .co m * #%L * Cytoscape Ding View/Presentation Impl (ding-presentation-impl) * $Id:$ * $HeadURL:$ * %% * Copyright (C) 2006 - 2013 The Cytoscape Consortium * %% * This program 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 program 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 General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.awt.geom.Point2D; public class Main { static Point2D.Double findIntersection(Point2D.Double p1, Point2D.Double p2, Point2D.Double p3, Point2D.Double p4) { 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); } static double epsilon(double v) { if (Math.abs(v) < 1.0E-10) return 0.0; return v; } }