Java Program to Find Line Passing Through 2 Points
class Main
{
// Driver method
public static void main(String args[])
{
IntsPoint x1 = new IntsPoint(3, 2);
IntsPoint x2 = new IntsPoint(2, 6);
lines_pts(x1,x2);
}
static class IntsPoint
{
int a,b;
public IntsPoint(int a, int b)
{
this.a = a;
this.b = b;
}
}
//find the line passing through 2 points by using equation
static void lines_pts(IntsPoint x1, IntsPoint x2)
{
int x = x2.b - x1.b;
int y = x1.a - x2.a;
int z = x * (x1.a) + y * (x1.b);
if (y < 0)
System.out.println("The line passing through points x1 and x2 is: " + x + "x - " + y + "y = " + z);
else
System.out.println("The line passing through points x1 and x2 is: " + x + "x + " + y + "y = " + z);
}
}
Output:
The line passing through points x1 and x2 is: 4x + 1y = 14
