Java Program to Return -1 if Point is on Left and 1 if Point is on Right
public class Main
{
public static int check(float sx,float sy,float ex,float ey,float px,float py)
{
double sp = Math.sqrt(Math.pow(px-sx,2)+Math.pow(py-sy,2));
double ep = Math.sqrt(Math.pow(px-ex,2)+Math.pow(py-ey,2));
double se = Math.sqrt(Math.pow(ex-sx,2)+Math.pow(ey-sy,2));
if (sp+ep == se)
return 0;
else if (sp+ep != se && sp < ep)
return -1;
else
return 1;
}
public static void main(String[] args)
{
float sx = 0;
float sy = 0;
float ex = 0;
float ey = 5;
float px = 0;
float py = -9;
int result = check(sx,sy,ex,ey,px,py);
System.out.println(result);
}
}
Output: -1
