Over a million developers have joined DZone.

Find X, Y Intersection Of 2 Lines

DZone's Guide to

Find X, Y Intersection Of 2 Lines

Free Resource
// Find X,Y intersection of 2 lines

public class findLineIntersection {

	public static void main(String args[]){
		//Ay = Bx + C
		//Dy = Ex + F
		double A,B,C,D,E,F;
		A=1; B=2; C=3; D=4; E=5; F=6;
		double X = findX(A,B,C,D,E,F);
		double Y = findY(A,B,C,X);
	public static double findX(double A, double B, double C, double D, double E, double F){
		double neg =-1;
		double Q,R,S;
		if (A<0 ^ D<0){
			//If A or D is negative add the values
			neg = 1;
		//Eliminate Y using multiple
		double multiple = neg*(A/D);
		D = D*multiple;
		E = E*multiple;
		F = F*multiple;
		//Q will be 0
		Q = A+D;
		R = B+E;
		S = C+F;
		return (-S)/R;
	public static double findY(double A, double B, double C, double X){
		return ((B*X) + C)/A;

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}