Here you can find the source of intersectLinesWithParams(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double[] params)
public static int intersectLinesWithParams(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double[] params)
//package com.java2s; //License from project: Apache License public class Main { public static final double EPSILON = Math.pow(10, -14); public static int intersectLinesWithParams(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double[] params) { double dx = x4 - x3; double dy = y4 - y3; double d = dx * (y2 - y1) - dy * (x2 - x1); // double comparison if (Math.abs(d) < EPSILON) { return 0; }/*from w w w.ja v a 2 s. c o m*/ params[0] = (-dx * (y1 - y3) + dy * (x1 - x3)) / d; if (dx != 0) { params[1] = (line(params[0], x1, x2) - x3) / dx; } else if (dy != 0) { params[1] = (line(params[0], y1, y2) - y3) / dy; } else { params[1] = 0f; } if (params[0] >= 0 && params[0] <= 1 && params[1] >= 0 && params[1] <= 1) { return 1; } return 0; } public static double line(double t, double x1, double x2) { return x1 * (1f - t) + x2 * t; } }